LOGBOOK

HELP

Quiz Entry - updated: 2026.11.26

What does a double rotation do, and why is one rotation not enough when z, y and x form a zig-zag?

When y and x bend in opposite directions (y a right child and x a left child, or the other way round), a first rotation around y straightens the bend, and a second rotation around z lifts x to the top. x ends up above both y and z.

Double rotation, right-left case: rotate around y, then around z

* The first rotation turns the bend into a straight line; the second is an ordinary single rotation. *

Take the right-left case: y is z's right child and x is y's left child. The heavy part is x's subtree, in the middle of the key range. A single left rotation around z would lift y, but x's subtree would only swap sides and the tree would stay just as deep.

So the repair goes in two steps:

  1. Right rotation around y: x moves up into y's place, y becomes x's right child. Now z, x, y form a straight right-right line.
  2. Left rotation around z: x moves up into z's place, z becomes x's left child.

At the end x is the root of the subtree, z on its left and y on its right, and x's two old subtrees are split between them (T1 to z, T2 to y). The left-right case is the mirror image: left rotation around y, then right rotation around z.

Tip: the middle key of the three always ends up on top. In a zig-zag the middle key is x, so x must rise two levels, and one rotation only lifts a node by one.

From Quiz: ADS / AVL Trees and Splay Trees | Updated: Nov 26, 2026