LOGBOOK

HELP

Quiz Entry - updated: 2026.12.01

In the directional naming of splay steps, what do zig and zag stand for, and which rotations does a zag-zig step perform?

Zig is a right rotation, zag a left rotation, and the name lists the rotations in the order they are done. A zag-zig step (x is the right child of a left child) is a left rotation around y followed by a right rotation around z.

Some texts only distinguish zig, zig-zig and zig-zag. Others also encode the direction, which gives six cases:

x is … Step Rotations, in order
left child of the root zig right rotation around the root
right child of the root zag left rotation around the root
left child of a left child zig-zig right around z, right around y
right child of a right child zag-zag left around z, left around y
right child of a left child zag-zig left around y, right around z
left child of a right child zig-zag right around y, left around z

How to derive it instead of memorising: a node that is a left child moves up by a right rotation (zig), and a right child by a left rotation (zag). For the opposite-sides cases, x moves up twice, first over y (so the first word matches x's own side) and then over z. For the same-side cases, the rotation around z comes first, but both rotations go in the same direction anyway.

Shortcut: read the name from the bottom up, first the side x is on, then the side y is on: zig for a left child, zag for a right child. A German mnemonic: zig and links (left) both have an i.

Gotcha: with the short naming, "zig-zag" means any opposite-sides step. With the directional naming, the same step is either zig-zag or zag-zig, depending on which way it bends.

From Quiz: ADS / AVL Trees and Splay Trees | Updated: Dec 01, 2026