On this page
A sorted linked list is easy to build but slow to search: you walk from the front, one node at a time. A skip list adds express lanes on top and picks which nodes join each lane by flipping a coin. Below, we trace a search through a 10-key skip list, show where the O(log n) comes from, and insert a key.
What is a skip list?
A skip list is a sorted linked list with extra levels of forward pointers, balanced by randomness rather than by strict rules, as William Pugh described in Skip lists: a probabilistic alternative to balanced trees (Communications of the ACM, 1990).
Level 1 holds every key in order. Each node gets a random height: flip a fair coin and add a level while it lands heads. About half the nodes reach level 2, a quarter reach level 3, and so on. A head node spans every level, and every lane ends at nil.
Here is the list in the picture above, with each key's height:
3 (1), 7 (2), 12 (1), 19 (3), 21 (1)
25 (2), 31 (1), 38 (4), 44 (1), 50 (2)
That makes 10 nodes on level 1, five on level 2 (7, 19, 25, 38, 50), two on level 3 (19, 38) and one on level 4 (38). Close to halving each time, which is what the coin promises on average.
How do you search a skip list?
The rule: move right while the next key is no bigger than your target; when it is too big (or nil), drop a level. Stop when you find the key or fall off level 1.
Search for 44:
Start at head on level 4. Next is 38, and 38 is at most 44, so move to 38.
On level 4, next after 38 is nil. Drop to level 3.
On level 3, next is nil again. Drop to level 2.
On level 2, next is 50, which is bigger than 44. Drop to level 1.
On level 1, next is 44. Found.
That is three key comparisons (38, 50, 44). A plain linked list would have compared 3, 7, 12, 19, 21, 25, 31, 38 and then 44: nine comparisons.
Why is skip list search O(log n)?
Count the levels first. With a fair coin, a node reaches level k with probability 1/2 to the power k minus 1, so about n/2^(k-1) nodes live on level k. That count drops to about one when k is near log₂ n, so the list has about log₂ n levels. Pugh's 1990 paper builds the analysis on exactly this probabilistic balancing.
Now count moves per level by tracing the path backwards. At each node, did you arrive from above or from the left? A node continues upward with probability 1/2, so on average you take about one step left before you climb: about two moves per level, roughly 2 log₂ n in total.
For a million keys, log₂ n is just under 20, so a search costs around 40 moves, against half a million on average for a plain list. A node's expected height is 2, so the list holds about 2n pointers. Both counts rest on linearity of expectation with indicator variables.
How does insertion with random heights work?
Insert 28. First run the search for 28 and remember the last node you stood on at each level:
Level 4: head (38 is too big).
Level 3: 19 (next, 38, is too big).
Level 2: 25 (next, 38, is too big).
Level 1: 25 (next, 31, is too big).
Flip for the height: heads, then tails, so 28 gets height 2. Splice it in after 25 on levels 1 and 2; levels 3 and 4 are untouched. Deletion is the mirror image: find the predecessors, then unhook the node on each of its levels.
Why use a skip list instead of a balanced tree?
A red-black or AVL tree stays balanced by rotating nodes, with fiddly case analysis. A skip list never rotates; the coin balances it. Pugh's abstract says insertion and deletion in skip lists are "much simpler and significantly faster than equivalent algorithms for balanced trees" (CACM, 1990).
The idea is in everyday software. Java's ConcurrentSkipListMap is documented as a concurrent variant of skip lists with expected average log(n) time for get, put and remove. Redis builds its sorted sets from a skip list plus a hash table, so each insert is an O(log N) operation.
Compare it with hash tables and their load factor and the binary heap priority queue: each makes a different operation fast. If the expectation step is where you get stuck, the Fermi Concept Library has a lesson for each concept in mathematics and computing, and Fermi's AI tutor can work through a trace like this with you, checking your understanding as it goes.



