LOGBOOK

HELP

Quiz Entry - updated: 2026.11.26

In a splay tree with root 7, left child 5 (children 2 and 6), where 2 has children 1 and 3 and 3 has a right child 4: what does remove(5) do?

5 has two children, so its inorder predecessor 4 takes its place and 4's old node is deleted. That node's parent, 3, is splayed: a zig-zag step (left rotation around 2, right rotation around 4) and then a zig (right rotation around 7) make 3 the root.

Splay tree remove(5): replace by the predecessor, then splay the removed node's parent

* The splayed node is 3, the parent of the node that physically disappeared, not anything near the key 5. *

  1. Remove as in a binary search tree. 5 has two children, so it is replaced by its inorder predecessor, the largest key in its left subtree: 4. 4 moves into 5's node, and 4's old node (a leaf, right child of 3) is deleted.
  2. Choose the node to splay. u = 3, the parent of the node that was actually removed.
  3. Zig-zag (zag-zig): u = 3 is the right child of 2, and 2 is the left child of 4. A left rotation around 2, then a right rotation around 4. Now 3 is the left child of 7, with 2 (holding 1) on its left and 4 (holding 6) on its right.
  4. Zig: a right rotation around the root 7. 3 is the root, with 2 (and 1) on the left and 7 on the right; 7 keeps 4 (and 6) as its left subtree.

The final inorder sequence 1, 2, 3, 4, 6, 7 is the original keys without 5.

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