Professional Documents
Culture Documents
AVL Tree Balance Requirements
AVL Tree Balance Requirements
AVL Tree Balance Requirements
The complexity of an AVL Tree comes from the balance requirements it enforces on each
node. A node is only allowed to possess one of three possible states (or balance factors):
If the balance of a node becomes -2 (it was left high and a level was lost from the left sub-
tree) or +2 (it was right high and a level was lost from the right sub-tree) it will require re-
balancing. This is achieved by performing a rotation about this node (see the section below
on rotations).
NB. There will only ever be at most one rotation required after an insert operation.
Now, as with the insertion algorithm, we traverse back up the path to the root node, checking
the balance of all nodes along the path. If we encounter an unbalanced node we perform an
appropriate rotation to balance the node (see the section below on rotations).
NB. Unlike the insertion algorithm, more than one rotation may be required after a
delete operation, so in some cases we will have to continue back up the tree after a
rotation.
LL Rotation
RR Rotation
LR Rotation
RL Rotation