Binary Search Trees
Announcements
Today:
A dictionary stores keys so we can find, insert, and remove them.
Where would you look for 25?
Where would you put 37?
A Binary Search Tree (BST) is a binary tree, T, such that:
____________, OR
T = {r, TL, TR} and
x ∈ TL → ______________
x ∈ TR → ______________
and
Pick A or B at random. On paper, insert those keys in that order into an empty BST.
A
4, 2, 6, 1, 3, 5, 7
B
1, 2, 3, 4, 5, 6, 7
Then find someone who picked the other list, and compare.
insert code. What’s different?find(7) on?T.remove(37);
T.remove(51);
Running time of Dictionary functions?
Which traversal sorts the keys?
What’s left?
CPSC 221