Intermediate Topic 32 of 52 Data Structures
Skip Lists
Layered linked lists enabling probabilistic logarithmic search.
How it works
A skip list stacks several sorted linked lists in layers, where higher layers skip over many elements. Each inserted node is promoted to higher levels with a coin flip, giving an expected O(log n) search, insert and delete without rotations. Search starts at the top level, moves right while the next key is smaller and drops down a level when it would overshoot.
Step-by-step walkthrough
- Higher levels are sparse express lanes over the bottom list.
- Search starts at the top level and moves right while the next key is not too big.
- It drops down a level when the next key would overshoot.
- It drops again and walks a few steps at the bottom.
- Random level choice gives expected O(log n) search with simple insertion.
Where it is used
Redis sorted sets, LevelDB and RocksDB memtables, and concurrent ordered maps in Java use skip lists. They are simpler to implement than balanced trees and easier to make lock-free.
Common pitfall
Performance is probabilistic, so the worst case can be poor with unlucky randomness. Memory overhead comes from multiple forward pointers per node. Poor random number generators bias levels, and deleting requires updating pointers on every level. Cap the maximum level sensibly.
Where it fits in the course
Skip Lists is topic 32 of 52 in Data Structures, rated Intermediate. It follows Path Compression. The next topic is Bloom Filters.
Practice and explore
- Open the interactive lesson, with a mini quiz.
- Take the Data Structures quiz.
How to study this topic
- Read the explanation above and restate the definition in your own words.
- Open the interactive lesson and answer its mini quiz.
- Read the common pitfall, then write a short example that avoids it.
- Check your understanding in the Data Structures quiz, and revisit the topic if you miss a question.
Frequently asked questions
What is Skip Lists?
Where do people use Skip Lists?
What is the most common mistake with Skip Lists?
What should I learn before this topic?
How can I practice it?
Is Skip Lists hard to learn?
How long does it take to learn Skip Lists?
Which topics are related to Skip Lists?
What should I study after Skip Lists?
Related topics
- Path Compression (Data Structures)
- Bloom Filters (Data Structures)
- Disjoint Set Union (Data Structures)
- Splay Trees (Data Structures)
- Arrays and Lists (Programming Fundamentals)