← All Tools

Splay Tree Visualizer

A splay tree is a binary search tree with one twist: every accessed node is splayed to the root by a sequence of rotations. There's no colour, height, or rank stored on the nodes — the amortized O(log n) comes entirely from the access pattern. Insert some keys, then find or delete one and watch the zig / zig-zig / zig-zag chain unwind.

Tree stats

size0
height0
root key
last access depth
total rotations0

Operation trace

How splaying works

Every operation — insert, find, delete — ends with a splay of the target node x. Working up from x, the algorithm applies one of three cases per pass:

Because every access moves the touched node to the root, splay trees exhibit strong working-set locality: recently or frequently accessed items are near the root and cost O(1) to reach. Sleator and Tarjan proved they're within a constant factor of any BST for any access sequence — the famous dynamic optimality conjecture. Real users include the Linux kernel's lib/klist.c, GNU libavl, and some database B-tree page caches.