Splay Tree Simulator
A Splay Tree is a self-adjusting Binary Search Tree. Every successful insertion or access moves the relevant node to the root using rotations, so recently accessed values become quicker to reach.
Amortized searchO(log n)
Amortized insertO(log n)
Amortized deleteO(log n)
Single-operation worst caseO(n)
Tree operations
Example Splay Tree loaded. Choose an operation.
Nodes0
Height0
Root—
Rotations0
Access path
—
Splay events
- No splay event yet.
Splay cases
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 grandparent
Splay Tree concepts
Successful access
A found node is moved to the root. This improves locality when the same or nearby keys are accessed repeatedly.
Unsuccessful search
This simulator splays the last visited node even when the target is absent, following a common practical convention.
No stored balance data
Unlike AVL or Red-Black Trees, Splay Trees store no height, balance-factor, or color metadata.
Amortized guarantee
An individual operation may be linear, but a sequence of operations has logarithmic amortized cost.
Rotation patterns
| 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 |