Professional Documents
Culture Documents
0 0 1
0
AVL Implementation issues:
-2 2 -2 2
-1 1 1 -1
or
or 0 0 0
0
CASE 1 CASE 2
Imbalance caused by inserting node Imbalance caused by inserting node
in left subtree of left child or right in right subtree of left child or left
subtree of right child (i.e., insertion subtree of right child (i.e., insertion
occurs on the outside) occurs on the inside)
Fixing Imbalances (contd)
Fixing an imbalance is done by rotating the tree
There are two types of rotation:
single rotation
for CASE 1 imbalances
double rotation
for CASE 2 imbalances
consists of two single rotations
The rotations must always preserve the BST property
Fixing Imbalances: Case 1
node with imbalance
6
D
4
4
C right rotate
2 node 4 about 6 2 6
A B A B C D