Lably
Skip to content

Splay tree

Self-adjusting binary search tree

  • 29 min read
  • 8 chapters

Related on Lably

Through Big O notation and Probability distribution

All normal operations on a binary search tree are combined with one basic operation, called splaying. Splaying the tree for a certain element rearranges the tree so that the element is placed at the root of the tree. One way to do this with the basic search operation is to first perform a standard binary tree search for the element in question, and then use tree rotations in a specific fashion to bring the element to the top. Alternatively, a top-down algorithm can combine the search and the tree reorganization into a single phase.

Advantages

Good performance for a splay tree depends on the fact that it is self-optimizing, in that frequently accessed nodes will move nearer to the root where they can be accessed more quickly. The worst-case height—though unlikely—is O(n), with the average being O(log n). Having frequently-used nodes near the root is an advantage for many practical applications (also see locality of reference), and is particularly useful for implementing caches and garbage collection algorithms.

Advantages include:

  • Comparable performance: Average-case performance is as efficient as other trees.
  • Small memory footprint: Splay trees do not need to store any bookkeeping data.

Sign in to keep reading

7 more chapters are free with a Lably account.

More in Computing and communication