




























































































Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!





























































































By constraining the relative positions of the nodes in
the tree!
All data items are kept in sorted order!
Between every node and the nodes in its left subtree.
Between every node and the nodes in its right subtree.
BST Order Property!
h
2
h
- 1
log N log (N+1) h N
Lower Bound: h = (log N)
Upper Bound: h = O (N)
N
N
log N
N
If BST == NULL (empty tree) then
Create a new node; let BST point to this new node;copy newitem into new node’s
data portion; set the pointers in the new node to NULL.
else if newitem.Key < BST->Key then
Insert (BST->LchildPtr, newitem)
else
Insert (BST->RchildPtr, newitem)
O(N)
O(log N)
J
B
L
R
Z
Q
Three cases:
(leaf node)
J
B
L
R
Z
Q
J
B
L
R
Z
J
B
L
R
Z
Q
J
B
L
R
Z
J
B
L
R
Z
Q
J
B L
R
Z
J
B R
Z L
By copying IOP (In-Order Predecessor)
By copying IOS (In-Order Successor)
Case 3 => Case 1 or Case 2