Skip List Explained: How Random Levels Make Search Fast

Skip list explained in plain terms means understanding how a simple linked list can search as fast as a balanced tree. The central question is how to find an item in a sorted list without scanning it from the start, and the answer is express lanes: extra links that skip ahead, added at random, so that a search can jump over most of the list.

A skip list is a probabilistic data structure that stores sorted items in a linked list with several layers of links, where each layer skips over more items than the one below. Searching starts at the top layer and drops down as it closes in on the target, which makes the average search logarithmic.

The idea is simple: randomness does the balancing that a tree does with rotations. This article explains what a skip list is, how it works, and where it is used.

Key takeaways

  • A skip list is a sorted linked list with extra layers of links.
  • Each layer skips over more items, so a search can jump ahead.
  • The layers are chosen at random, which keeps the structure balanced on average.
  • Searching, inserting, and deleting all take logarithmic time on average.
  • It is simpler to build than a balanced tree, and easier to make concurrent.

What a skip list is

The bottom layer of a skip list is an ordinary sorted linked list, holding every item in order. Above it sit further layers, each holding a subset of the items, and each item appears in a layer only if a coin toss said so. The top layer holds very few items, spaced far apart, and a search starts there.

The randomness is the key. When an item is inserted, the structure tosses a coin to decide how many layers it joins: it always joins the bottom layer, joins the second with probability one half, the third with probability one quarter, and so on. The result is a structure that is balanced on average, without any rebalancing step.

Skip lists were invented by William Pugh in 1990, as a simpler alternative to balanced trees. Pugh showed that a skip list matches a balanced tree’s performance while being far easier to implement, and that its simplicity makes it easier to adapt for concurrent access. Our guide to LSM trees explains a storage design that uses skip lists in memory, and our guide to Redis explains the database that made them famous.

How a skip list works

Searching begins at the top layer, at the first item. The search moves forward along the current layer while the next item is smaller than the target, and drops down a layer when it would overshoot. It repeats this until it reaches the bottom layer, where it either finds the target or proves it is absent.

Inserting an item starts with a search that records, at each layer, the last item smaller than the new one. The item is then linked into the bottom layer, and a coin is tossed to decide how many higher layers it joins, linking it into each of them after the recorded predecessors.

Deleting an item follows the same search, then unlinks the item from every layer it appears in. There is no rebalancing and no restructuring: the remaining links still form a valid skip list, because the layers were random to begin with.

The height of a skip list grows slowly with the number of items. With a coin toss of one half, the expected number of layers is the logarithm of the number of items, so a list of a million items is about twenty layers high, and a search touches only a few items on each layer.

The worst case is possible but unlikely. If the coin tosses went badly, a skip list could degenerate into a plain linked list, but the chance of that falls sharply as the list grows, and in practice the average case is what a system sees. This is the trade a skip list makes: no worst-case guarantee, in exchange for a much simpler design.

A dark office with a glowing green tower of express lanes, a search path jumping down through the layers toward a single lit item
A dark office with a glowing green tower of express lanes, a search path jumping down through the layers toward a single lit item, shows how a skip list works: start high, drop down, and arrive in a few steps.

Comparing a skip list with other sorted structures

A skip list is one of several ways to keep sorted data searchable, and each was built with a different emphasis. A balanced tree guarantees logarithmic search but needs rotations, a hash table is faster for exact lookups but cannot order keys, and a plain list is simple but slow, and each approach trades guarantees for simplicity in a different way.

The table below sets out the main contrasts between the leading approaches.

Aspect Skip list Balanced tree Hash table
Search time Logarithmic, on average Logarithmic, guaranteed Constant, on average
Ordered traversal Yes, bottom layer is sorted Yes No
Range queries Yes, walk the bottom layer Yes No
Rebalancing None, randomness does it Rotations on insert and delete Resizing as it grows
Best for Concurrent sorted sets Guaranteed performance Exact-match lookups

The practical result is that a skip list is the right choice for a concurrent sorted set, a balanced tree suits work where the worst case must be bounded, and a hash table fits lookups where order does not matter.

Where skip lists are used

Redis uses a skip list for its sorted sets. Every member of a sorted set is stored in a skip list, which is how Redis can return the top scores, the members in a range, and the rank of a member, all quickly.

LSM-tree storage engines use skip lists for their in-memory tables. LevelDB, RocksDB, and similar engines keep recent writes in a skip list, which is fast to update and can be scanned in order when it is time to flush to disk.

Concurrent data structures use skip lists because they are easy to make lock-free. The links can be updated with atomic operations, so many threads can search and insert at once without a single lock guarding the whole structure.

Databases use skip lists in their indexes when simplicity matters more than guarantees. Some embedded databases choose a skip list over a B-tree because the code is shorter, easier to verify, and fast enough in practice.

Operating systems use skip lists for process scheduling and timers. The kernel keeps timers in a structure that must support fast insertion and finding the next timer to fire, and a skip list provides both with little code.

Strengths and limits

The greatest strength of a skip list is its simplicity. The whole structure is a few dozen lines of code, there is no rebalancing logic to get wrong, and the performance matches a balanced tree in the cases that matter.

It is also a strength that skip lists are naturally concurrent. The links can be changed with atomic operations, so a lock-free skip list is far easier to build than a lock-free balanced tree, which is why they appear in so many concurrent systems.

The limits are real, though. The performance is average-case, not guaranteed, and a skip list uses more memory than a tree, because each item carries several forward pointers. For work where the worst case must be bounded, a balanced tree is still the safer choice.

Skip list checklist

  • Use a skip list when you need a sorted set with fast search and insertion.
  • Choose the coin-toss probability to fit the data; one half is the usual default.
  • Cap the maximum height so a rare run of luck cannot build a tall tower.
  • Walk the bottom layer for range queries and ordered scans.
  • Prefer a skip list over a tree when several threads must update the set.
  • Measure before assuming it beats a tree; the constant factors differ.
  • Remember the guarantee is average-case, not worst-case.
  • Use it for in-memory tables that flush to disk in order.
  • Test with adversarial insertion orders; randomness should still hold up.

Frequently asked questions

What is a skip list in simple terms?

It is a sorted linked list with extra layers of links that skip ahead, so a search can jump over most of the list instead of scanning it.

Why is it called a skip list?

Because the upper layers let a search skip over large stretches of the list, like express lanes on a road.

How does randomness keep a skip list balanced?

Each item joins higher layers by coin toss, so the layers thin out evenly on average, without any rebalancing step.

What is the difference between a skip list and a balanced tree?

A tree guarantees logarithmic search through rotations, while a skip list achieves it on average through randomness, with far simpler code.

Why does Redis use a skip list?

For its sorted sets, where it needs ordered traversal, range queries, and fast insertion, all of which a skip list provides.

When should I not use a skip list?

When the worst case must be guaranteed, when memory is very tight, or when only exact-match lookups are needed and order does not matter.

The bottom line

Skip list explained in one line is this: add random express lanes to a sorted list, and searching becomes fast.

It is the structure that trades a guarantee for simplicity, and the reason a few dozen lines of code can match a balanced tree.

This article is general information about how skip lists work, not advice about choosing a data structure for a particular system.

Latest articles

Scroll to Top