Contents    Page-10    Prev    Next    Page+10    Index   

Tree Rotation

The basic idea upon which self-balancing trees are based is tree rotation. Rotations change the height of subtrees but do not affect the ordering of elements required for binary search trees.

The tree on the left is converted to the tree on the right with a right rotation, or vice versa with a left rotation. Both trees maintain the required ordering, but the heights of the subtrees have changed. In this diagram, B and D are single nodes, while A, C, and E could be subtrees.

There are several other rotation cases, but this is the basic idea.