




























































































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!





























































































Insertion Order Matters
●
Suppose we create a BST of numbers in
this order:
4, 2, 1, 3, 6, 5, 7
4
2 6
Tree Terminology
●
The height of a tree is the number of
nodes in the longest path from the root
to a leaf.
4
2 6
Tree Terminology
●
The height of a tree is the number of
nodes in the longest path from the root
to a leaf.
1 2 3 4 5 6
Tree Rotations
●
One common way of keeping tree heights
low is to reshape the BST when it gets
too high.
●
One way to accomplish this is a tree
rotation , which locally rearranges
nodes.
Tree Rotations
B
A
B
<A
A
<B
B
A
B
<A
A
<B
Rotate Right
Rotate Left
1
2
3
4
5
1
2
3
4
5