2.4. Double Rotations

A single rotation doesn't always do the job. In setting up our rotation example, we assumed that subtree z was higher than y. What would happen if y were the higher of the two?

In this case, the rotation does not produce a balanced tree.

A single rotation produces a balanced tree only if the interior subtree of H is no higher than the other subtree of H.

But, we can note that a left rotation shifts height from the right of the root to the left. Similarly, a right rotation shifts height from left to right.

So in this case, we are faced with a problem in that y is too high compared to z. The solution is to do a single right rotation of H to shift height to the right, making z higher, then do the single left rotation of U.

This combination is called a double left rotation. (There is, of course, a mirror image double right rotation as well.)

==============================================

So the process of rebalancing a node consists mainly of determining whether we need a single or double rotation, then applying the appropriate rotation routines.


In the Forum:

(no threads at this time)