LOGBOOK

HELP

Quiz Entry - updated: 2026.11.27

In the same splay tree, (40,X) is the right child of (37,P), which is the right child of (35,R), the root's right child. Which steps splay (40,X) to the root?

A zig-zig step (in directional naming, zag-zag), because x and y are both right children: a left rotation around (35,R), then around (37,P). (40,X) is then the root's right child, and a zig (a zag: left rotation around the root) finishes the job.

Step 1: zig-zig. x = (40,X), y = (37,P), z = (35,R), all leaning right.

  1. Left rotation around z: (37,P) rises into (35,R)'s place; (35,R) becomes its left child, keeping (21,O) and taking (36,L) as its right child.
  2. Left rotation around y: (40,X) rises; (37,P) becomes its left child.

The path that was right-right-right is now a left-leaning line under (40,X): (40,X), then (37,P), then (35,R).

Step 2: zig. (40,X) is the right child of the root (20,Z), so one left rotation around the root. (40,X) becomes the root with (20,Z) as its left child, and (20,Z) keeps its whole left subtree and takes (37,P) as its right child.

Notice the order in step 1: the grandparent is rotated first, then the parent. Doing it the other way round would also bring (40,X) to the root. On a path this short both orders end up about as deep; the grandparent-first order pays off on long paths, which it folds to about half their depth.

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