Learn the vocabulary of a tree that rotates each accessed node up to the root to speed up its next access.
0 / 5 completed
1 / 5
At standup, a dev mentions a binary search tree that, after every single access, rotates the accessed node all the way up to the root, so recently or frequently accessed elements end up near the top and cheap to reach again. What is this structure called?
A splay tree is exactly this: after every single access, whether a lookup, insert, or delete, it rotates the accessed node all the way up to become the new root, so elements that were just accessed, or are accessed frequently, stay near the top of the tree and remain cheap to reach again. A hash collision is an unrelated hash-table concept about two keys sharing a bucket. This move-to-root-on-access behavior is exactly why a splay tree performs especially well on workloads with locality, where the same elements tend to be accessed repeatedly in bursts.
2 / 5
During a design review, the team picks a splay tree specifically because the workload repeatedly re-accesses a small, changing subset of elements in bursts. Which capability does this provide?
A splay tree here provides amortized fast access to recently or frequently touched elements, since every access rotates that element up to the root, meaning if the same element, or one near it, is accessed again soon afterward, that next access is nearly immediate. A structure with no locality benefit would cost the same to access any element regardless of how recently it was touched, missing out on exactly the pattern a bursty, repeat-access workload exhibits. This move-to-root behavior is exactly why a splay tree can outperform a plain, statically-balanced tree on workloads with strong locality.
3 / 5
In a code review, a dev notices a cache-like feature repeatedly re-accesses a small, shifting subset of elements in bursts, but stores them in a statically-balanced tree that never adapts to which elements are actually hot. What does this represent?
This is a missed splay-tree opportunity, since a statically-balanced tree costs the same to reach any element regardless of how recently it was accessed, while a splay tree would rotate each accessed element up to the root, keeping the currently hot, frequently re-accessed subset cheap to reach again. A cache eviction policy is an unrelated concept about discarded cache entries. This never-adapts-to-hot-elements pattern is exactly the kind of missed locality benefit a reviewer flags once the workload is known to access a shifting subset in bursts.
4 / 5
An incident report shows a lookup-heavy feature performed worse than expected on a workload that repeatedly re-accessed a small, shifting subset of elements in bursts, because it used a statically-balanced tree that never adapted to which elements were currently hot. What practice would prevent this?
Switching to a splay tree rotates each accessed element up to the root, keeping the currently hot, frequently re-accessed subset cheap to reach on the next nearby access, which is exactly the fix for the underperformance described in this incident. Continuing to use the statically-balanced tree regardless of the workload's strong locality is exactly what left that adaptive speedup on the table. This splay-tree approach is the standard fix for lookup-heavy workloads with strong locality, where the same shifting subset of elements is repeatedly re-accessed in bursts.
5 / 5
During a PR review, a teammate asks why the team accepts a splay tree's occasional expensive single access, when a node far from the root gets rotated all the way up, instead of using a red-black tree with a guaranteed worst-case bound on every single access. What is the reasoning?
A splay tree only guarantees a good cost when amortized, averaged, across a whole sequence of accesses, meaning any single access, especially one to an element that hasn't been touched in a while, can be considerably more expensive than a red-black tree's guaranteed bound on every individual access. The tradeoff is exactly why a splay tree is attractive for a workload with strong locality that benefits from its adaptive, move-to-root behavior on average, while a red-black tree remains preferred wherever a hard guarantee is needed on every single individual access, not just the average.