Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
7
8
2
1
2
1
2)
3)
4)
6
8
4
3
8
9
6
9
9
8
4
5
Pretend the tree is flexible, grab hold of k 2, letting gravity take hold.
k3 > k2 (by BST property), so k3 becomes k2s right subtree.
X and Z can remain attached to the same point,
and Y becomes k3s subtree to maintain BST property.
k
k
X
Need to rotate.
Need to rotate.
1
4
1
6
1
6
1
6
1
6
1
4
1
6
1
4
1
1
Rotation type:
1
3
1
2
1
1
1
6
1
4
1
2
1
1
1
4
1
6
1
2
1
1
1
4
1
0
1
6
1
3
1
5
1
2
1
1
1
0
1
4
1
6
1
1
1
0
1
2
1
4
1
6
Double Rotation
Place k2 as the new root.
This forces k1 to be k2s left child and k3 to be its right
child.
Then the 4 subtrees A,B,C,D fall according to BST rules.
k
A
B
Single Left
Rotation at
K1
k
3
t
gh
Ri at
le on
ng ti
Si ta
Ro
K3
k
2