You are on page 1of 7

BST Data Structure

Definitions, terminologies, notations, operations


• A data structure to represent sets whose elements are ordered by some
linear order.
• Binary Search Tree (BST)
• A binary tree in which the nodes are labelled with the elements of the
set.
• Each node satisfies the binary search tree property:
• All the elements stored in the left subtree of any node k are all lesser
than the elements stored at k, and
• All the elements stored in the right subtree of any node k are all
greater than the elements stored at k.

• The element stored in the left child of any node k is lesser than the
element stored at k, and
• The element stored in the right child of any node k is greater than
the element stored at k.
• Operations: Member, Insert, Delete, DeleteMin All in O(h) time
Which of the following are BSTs?
• BT(T1) = 2305
274E 11 -1 -1 12 -1 1688 7 2A2 -1 5 -1
2305 2A2 274E 1688

• BT(T2) = 2305
2305
11 12 7 ▓

11
• BT(T3) = 11 ● T4 11 ●T5
7
7 7

5 8
5 9
5 12

6 9 8 10
Represent {11, 6, 8, 19, 4, 10, 5, 17,
43, 49, 31} as a BST. Is it unique?
Represent {11, 6, 8, 19, 4, 10, 5, 17,
43, 49, 31} as a BST. Is it unique?
11

6
19

4 8 17 43

5 10 31 49
Traverse the BST
Preorder =
Postorder = 11
Inorder =

6
19

4 8 17 43

5 10 31 49
Delete(<31, 4, 11>, T)

11

6
19

4 8 17 43

5 10 31 49

You might also like