The document discusses AVL trees and provides examples of inserting nodes into an AVL tree. It shows how single and double rotations are used to rebalance the tree when inserts cause height imbalances. Single rotations involve rotating a node and its child, while double rotations rotate a node and its child and grandchild.
3. CS216 Fall 2001
AVL Tree No longer AVL, must rebalance
Insert a node
h h +1 h h +2
Two ways to expand subtree of height h+2:
h h
h h +1 h +1 h
h +2
h +2
Apply a Single Rotation Apply a Double Rotation
Note: the symmetrical case is handled
identically (i.e. mirror image)
9/27/01 Page 3 of 4
4. CS216 Fall 2001
Single Rotation:
B D
Single
rotation
D B
A
E
h h +1
C E A C
h h +1 h h
h +2
Double Rotation:
B
D
F
B F
A Double
rotation
D
h
G A C E G
h h h h -1 h
C E OR
h-1 h
h h -1 OR
h h
OR
h-1 h
OR
h h
h +1
h +2
9/27/01 Page 4 of 4