Binary Search Tree
Binary Search Tree
Binary Search Tree
By-
Ms. Shabnam Makandar
Asst. Prof.
DYPIMCAM
DYPIMCAM, Akurdi, Pune 1
Binary Search Tree
• Values in left sub tree less thanparent
• Values in right sub tree greater than parent
• Fast searches in a Binary Search tree, maximum of log n
comparisons
31
21 40
10 22 35 42
25
Binary search Not a binary
trees search tree
25
20>17-Left
20<25-Right 16
20
40
Insertion in a Binary Tree
40, 60, 50, 33, 55, 11
40
60
40
60
50
40
33 60
50
40
33 60
50
55
40
33 60
11 50
55
5 15
There are three items to delete.
Case 1: No Child
Case 2: One Child 3 7 13 17
5 15
23
6 9 14
DYPIMCAM, Akurdi, Pune 19
CASE 2: ONE CHILD
Root
12
5 15
Find the Node to Delete
Link it’s parent to this only child.
Remain attached to the tree. 3 7 13 17
24
6 9 14
DYPIMCAM, Akurdi, Pune 20
CASE 3: TWO CHILD
Root
12
1.
Find minimum in right
3 7 13 17
Copy the value in targetted node
Delete duplicate from right subtree.
25
6 9 14
DYPIMCAM, Akurdi, Pune 21
CASE 3: TWO CHILD
Root
12
5 15
2.
Find maximum in left
Copy the value in targetted node 3 7 13 17