Chapter 10 · Simulation

Splay Tree Simulator

← Chapter 10

Example splay tree loaded. Choose an operation.

Nodes0
Levels0
Root—
Rotations0

Access path

—

Splay steps

  1. No splay steps yet.

Splay Tree Simulator

A splay tree is a self-adjusting binary search tree. Every insertion or access moves the node involved to the root through a series of rotations (it is splayed), so recently used keys are quick to reach again.

How to use it

  • Type an integer and press Insert, Search + splay or Delete. Splay minimum and Splay maximum bring the smallest or largest key to the root.
  • The access path and every zig, zig-zig and zig-zag step are listed on the right. Validate checks the binary-search-tree order.
  • Example, Random and Reset replace the tree; Stop interrupts a running animation.

Splay tree ideas

  • Successful access: the node found moves to the root, which pays off when the same or nearby keys are accessed again and again.
  • Unsuccessful search: if the key is absent, the last node visited moves to the root, the usual convention in practice.
  • No balance information: unlike AVL and red-black trees, a splay tree stores no heights, balance factors or colors.
  • Amortized guarantee: a single operation can take linear time, but the amortized cost over a sequence of operations is logarithmic.

Rotation patterns

PatternCaseRotations
ZigThe parent 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