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

400 ms

Example Splay Tree loaded. Choose an operation.

Nodes0
Height0
Root—
Rotations0

Access path

—

Splay events

  1. 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

PatternSituationRotations
ZigParent is the rootOne left or right rotation
Zig-ZigLeft-left or right-rightTwo rotations in the same direction
Zig-ZagLeft-right or right-leftTwo rotations in opposite directions