LOGBOOK

HELP

Quiz Entry - updated: 2026.11.26

What does a single rotation do, and when is it the right repair?

When z, y and x lie in a straight line (y and x both left children, or both right children), one rotation around z lifts y into z's place: z becomes y's child, and y's inner subtree moves over to z.

Single rotation: the left-left case before and after a right rotation around z

* Only three references change. The orange subtree T2 is the one that changes parent. *

In the left-left case (z's left child is y, y's left child is x), a right rotation around z:

  1. y takes z's place under z's old parent;
  2. z becomes y's right child;
  3. y's old right subtree (T2) becomes z's left subtree.

Step 3 is the one people forget, and it is forced by the ordering (without it, y would end up with three children): every key in T2 is larger than y and smaller than z, so after the rotation its only legal place is between them, as z's left subtree. The inorder sequence T0, x, T1, y, T2, z, T3 is the same before and after, which is why a rotation never breaks the search-tree property.

T2 is a position, not necessarily a node: it can hold one node, forty nodes, or nothing at all. An empty T2 still moves, which simply means z's new left child is empty.

The right-right case is the mirror image: a left rotation around z.

Why it fixes the balance: the deep part of the tree (x's subtree) moves up one level and z, which sat over the shallow side, moves down one level. The subtree is now one level lower, back to the height it had before the update.

Go deeper:

  • doc Tree rotation โ€” the left and right rotation, with the subtree that changes parent highlighted.

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