LOGBOOK

HELP

Quiz Entry - updated: 2026.11.26

In a splay tree, (8,N) is the right child of (7,T), which is the left child of (10,A), which is the left child of the root (20,Z). How is (8,N) splayed to the root?

First a zig-zag step (x is a right child, its parent a left child): a left rotation around (7,T), then a right rotation around (10,A). Now (8,N) is the root's left child, so a final zig, a right rotation around (20,Z), makes it the root.

Splaying (8,N): a zig-zag step and then a zig

* Three rotations in two steps; the subtrees on the far left and right are carried along unchanged. *

The keys are (key, value) pairs; the tree is ordered by the number. (8,N) has children (7,P) and (10,U), (10,A) has a right child (14,J), and (20,Z) has a right subtree with the keys from 21 to 40.

Step 1: zig-zag (in directional naming, zag-zig). x = (8,N), y = (7,T), z = (10,A). x is a right child, y a left child: opposite sides.

  • Left rotation around y: (8,N) moves up, (7,T) becomes its left child and takes (7,P) as its new right child.
  • Right rotation around z: (8,N) moves up again, (10,A) becomes its right child and takes (10,U) as its new left child.

Now (8,N) has (7,T) and (10,A) as children and is the left child of (20,Z).

Step 2: zig. x is a child of the root: a right rotation around (20,Z). (8,N) is the root, (20,Z) its right child, and (10,A)'s subtree moves over to become (20,Z)'s left subtree.

Check: read the result in inorder and the keys are still sorted. Rotations never break the search-tree order.

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