Professional Documents
Culture Documents
David Kaplan
Properties D E F
max # of leaves:
max # of nodes: G H
average depth for N nodes:
Representation: Data I J
left right
pointer pointer
B C
B C
left right left right
child child child child D E F
D E F
left right left right left right
child child child child child child
Fast searching
runtime:
Fast deletion
runtime:
3 7 9 17
1 4 6
2 9 20
What does this guarantee
with a BST?
7 17 30
In order listing:
25791015172030
return t;
}
} else {
// duplicate
// handling is app-dependent
}
in reverse order
1 + 2 + 3 + … + n = O(n2)
5 15
Find maximum
2 9 20
7 17 30
5 15
2 9 20
7 17 30
7 17 30
Delete(5) 5 15
Find(9) 2 9 20
Find(16)
7 17 30
Insert(5)
Find(17)
5 15
2 9 20
7 17 30
5 15
2 9 20
7 30
2 9 30
Delete(5)
7
Realities
For large data sets, disk accesses dominate runtime
Some deep and some shallow BSTs exist for any data
What matters?
Problems occur when one branch is much longer than another
i.e. when tree is out of balance