Quiz Entry - updated: 2026.12.01
Which node is splayed after find, insert and remove in a splay tree?
find: the node with the key, or, if the key is missing, the last node visited (the parent of the external node where the search ended). insert: the node holding the new (or replaced) entry. remove: the parent of the node that was actually deleted.
| Operation | Node that is splayed |
|---|---|
find(k), key found |
the node holding k |
find(k), key not found |
the parent of the external node where the search stopped |
insert(k, v) |
the node where the entry was inserted or replaced |
remove(k) |
the parent of the internal node that was removed |
The common idea: splay the deepest node the operation touched. That is what pays for the walk down. Every operation's cost is dominated by the length of its path, and splaying the end of that path folds the whole path into a shallower shape.
Two cases are easy to get wrong:
- An unsuccessful search still splays. It walked a long path just like a successful one, so the last node on it is moved up. For example, in a tree with root 7, left child 4 and 4's children 2 and 6, a search for 5 visits 7, 4 and 6 and falls off 6's empty left side, so 6 is splayed to the root.
- After a remove, the deleted node is gone, so its parent is splayed. If the key's node had two children, the node actually removed is the inorder neighbour's old node, deeper in the tree, and its parent is splayed, not the parent of the original key.