Successful access
A found node is moved to the root. This improves locality when the same or nearby keys are accessed repeatedly.
A Splay Tree is a self-adjusting Binary Search Tree. Every successful insertion or access moves the relevant node to the root using rotations. Frequently accessed values therefore become quick to reach.
Example Splay Tree loaded. Choose an operation.
Zig:
node has a parent but no grandparent
perform one rotation
Zig-Zig:
node and parent lean the same way
rotate grandparent, then parent
Zig-Zag:
node and parent lean opposite ways
rotate parent, then grandparentA found node is moved to the root. This improves locality when the same or nearby keys are accessed repeatedly.
This simulator splays the last visited node even when the target is absent, following a common practical Splay Tree convention.
Unlike AVL or Red-Black Trees, Splay Trees store no height, balance factor, or color metadata.
An individual operation may be linear, but a sequence of operations has logarithmic amortized cost.
| Pattern | Situation | Rotations |
|---|---|---|
| Zig | Parent is the root | One left or right rotation |
| Zig-Zig | Left-left or right-right | Two rotations in the same direction |
| Zig-Zag | Left-right or right-left | Two rotations in opposite directions |