SDSystem DesignConcepts to case studies
System DesignDSA
x
0/311
Part 1: Foundations
Part 2: APIs and Communication
Part 3: Caching
Part 4: Data and Storage
Part 5: Architecture
Part 6: Distributed Systems
Part 7: Advanced Data Topics
  • Bloom Filters
  • Cuckoo Filter
  • Skip Lists
  • Count-Min Sketch
  • HyperLogLog
  • Merkle Trees
  • MinHash
Part 8: Operations and Security
Part 9: Estimation and Interview Method
Part 10: Case Studies
System Design/Advanced Data Topics/Probabilistic and Other Structures

Skip Lists

A sorted list with express lanes, so search is fast without a tree (used in Redis).

⏱ 12 min readIntermediateInterview FavouriteHas visualizer
SummaryConceptReal-Life ExampleWhy?Where?How It WorksStepsKey TermsPros & ConsMistakesReal WorldRead NextInterview Q&ACheat-Sheet

01Quick Summary

A skip list is a sorted linked list with extra express lanes on top. The express lanes let a search jump over many items at once, so it is fast without using a tree.

  • A plain sorted linked list is simple, but finding a key means walking one item at a time.
  • A skip list adds a few higher lanes that link only some of the items. A search starts on the top lane and drops down when it would go too far.
  • Lane heights are chosen by a coin flip, so no hard re-balancing is needed. Search, insert and delete take about O(log n) time on average.

02Concept: What is it?

Start with a sorted linked list: 4 → 9 → 13 → 20 → 26 → ... To find 57 you must walk through every item before it. For a million items that is up to a million steps.

Now add a second lane above it that links every other item. Then a third lane that links every other item of that lane, and so on. You search from the top: go right while the next key is still smaller than your target, otherwise drop down one lane and keep going. Each drop cuts the remaining work roughly in half, just like binary search.

Building the lanes in a perfect pattern would make inserts painful (every insert would shift the pattern). So a skip list does something clever and lazy: when you insert a key, it flips a coin. Heads, the key also joins the next lane up, and the coin is flipped again. Half of the keys reach lane 2, a quarter reach lane 3, an eighth reach lane 4, and so on. The lanes come out roughly balanced, with no complex rotation code.

A sorted list and the same list with express lanes
Lane 34 ........... 38 ...........
Lane 24 ..... 20 ..... 38 ..... 57
Lane 14 9 13 20 26 31 38 44 51 57
The bottom lane holds every key. Higher lanes hold fewer keys, so they are the express lanes.
🧠Randomness gives balance
Nobody plans which key gets a tall tower. The coin flips make tall towers rare and short ones common, which is exactly the shape that makes searching fast. On average, the structure behaves like a balanced tree.

03Real-Life Example

🍵The Subway with Local and Express Trains
A subway line has 40 stations. The local train stops at all of them. An express train stops only at a few big stations. To go to station 37 you take the express to the big station nearest to it (say station 35), then change to a local train for the last two stops. You never need to ride the local train past every single stop, and you never go past your station. If an even faster super-express runs between a handful of huge stations, you start there. You always begin on the fastest train and change to a slower one when the next stop would be too far.
Subway
Skip list
Local train that stops everywhere
The bottom lane with every key
Express and super-express trains
Higher lanes with fewer keys
Start on the fastest train
Start on the top lane at the head
Change to a slower train before you pass your stop
Drop down a lane when the next key is too big
Big stations where many lines meet
Keys with tall towers (many lanes)
Deciding which stations get express stops
The coin flips when inserting
Your station
The key you are searching for
Searching for 57 with the skip list
🏁Headtop lane
→↓jump far
⏭️Key 38next is too big, drop
→↓walk
⏩Key 51next is 57
→↓step
✅Key 57found

04Why Do We Need It?

⚡Fast search
About O(log n) steps on average for search, insert and delete, like a balanced tree.
🧩Simple to build
No rotations, no re-balancing rules. Just linked lists and a coin flip. It is easy to get right.
📏Sorted order for free
The bottom lane is already a sorted list, so range queries (all keys from A to B) are just a walk to the right.
🧵Friendly to many threads
An insert changes only a few nearby links, so lock-free and fine-grained locking versions are practical.
🧠Good for in-memory data
Pointer-based, so it suits RAM. It is not designed for disk blocks like a B-Tree is.
🔀No worst-case input
Because levels are random, a bad order of inserts cannot build a lopsided structure (unlike a plain unbalanced tree).
You want a sorted collection with fast search and range scans, in memory, and you want it simple and easy to make concurrent. A skip list gives you that.

05Where Do We Use It?

🟥Redis sorted sets
A sorted set (ZSET) keeps its members in order by score with a skip list, next to a hash table for quick lookup by member.
📝Memtables in LSM stores
Databases that use LSM trees often keep the in-memory write buffer as a skip list (LevelDB and RocksDB by default).
☕Java standard library
ConcurrentSkipListMap and ConcurrentSkipListSet are thread-safe sorted collections built on skip lists.
🔎Search indexes
Posting lists in search engines can use skip pointers to jump ahead when combining word lists.
🏆Leaderboards
Rank players by score, find a player rank, and list the top N. All of these need a sorted structure.
📊In-memory indexes
Any place that needs an ordered in-memory map with many readers and writers at once.

06Types / Parts / How It Works

How a skip list works inside

Each key is a tower of nodes
Search
1️⃣Start at the headtop lane
↓
2️⃣Next key smaller than target?move right
↓
3️⃣Next key too big?drop down a lane
↓
4️⃣Bottom lane reachedcheck the next key
Insert
1️⃣Search for the placeremember the last node on each lane
↓
🪙Flip coinstower height
↓
🔗Link the tower inon every lane it reaches
A tall tower has many forward pointers. Each pointer says: the next key on this lane is over here.

Expected sizes

ItemTypical valueWhy
Chance a key reaches lane 21/2One head on the first flip
Chance a key reaches lane 31/4Two heads in a row
Average pointers per keyAbout 21 + 1/2 + 1/4 + ... adds up to 2
Number of useful lanesAbout log2(n)The lanes run out when only a key or two is left on top
Search, insert, deleteO(log n) on averageEach drop halves the remaining work
Worst caseO(n)Extremely unlikely with random levels, but possible in theory

Skip list compared with other sorted structures

StructureSearchRange scanNotes
Sorted arrayO(log n) with binary searchVery fastInsert and delete are slow (items must shift)
Sorted linked listO(n)FastSimple, but search is slow
Skip listO(log n) averageFast (walk the bottom lane)Simple, easy to make concurrent, uses extra pointers
Balanced tree (red-black, AVL)O(log n) worst caseFine, needs in-order walkStrict guarantee, but rotations make it harder to build and to lock
B-TreeO(log n) with few disk readsFastMade for disk pages, not for pointer-based RAM structures
VisualizerSearch path through a skip listSlide the number to find, and slide the number of lanes from 4 down to 1. Watch the cyan path, and compare the lookups with a plain sorted list.
Cyan = the path of the search. Green = the key that was found. The top lane is the fastest, the bottom lane holds every key.
H
H
H
H
head
4
·
9
9
·
13
·
20
·
26
26
26
·
31
·
38
38
·
44
·
51
51
51
51
·
57
stop
66
66
·
72
·
Skip list lookups
5
4 lanes
Plain list lookups
10
walk one by one
Saved
5
fewer lookups
Found 57 after 5 lookups. A plain sorted linked list needs 10.

Only 12 keys are shown, so the saving looks small. With a million keys a skip list needs about 20 to 40 lookups, while a plain list may need a million. The lane heights here are fixed on purpose (a real skip list flips a coin for each new key).

07How to Use It / Steps / Implementation

Using a skip list in practice

  1. 1
    Pick the maximum number of lanes
    About log2 of the largest number of keys you expect (for example 32 lanes can cover billions of keys).
  2. 2
    Choose the promotion chance
    Most skip lists use 1/2. A smaller chance (like 1/4) uses fewer pointers per key but makes searches a bit longer.
  3. 3
    Search by moving right and down
    On each lane move right while the next key is smaller than your target. When it is not, drop down. Stop at the bottom lane.
  4. 4
    Insert with a coin flip
    Find the spot, remember the last node you left on each lane, flip coins to choose the tower height, then link the new tower in on those lanes.
  5. 5
    Delete by unlinking
    Find the key, then unlink its tower on every lane it appears on.
  6. 6
    Walk the bottom lane for ranges
    To list all keys from A to B, search for A, then follow the bottom lane until you pass B.
  7. 7
    Use a library when you can
    In most real work you use a ready-made sorted set (a Redis sorted set or a concurrent skip list map), not your own code.
💡Rank queries
A plain skip list finds a key fast, but asking "what is the position of this key?" needs extra data. Redis stores, on each pointer, how many bottom-lane items it skips. Adding those counts lets a search add them up and return the rank in O(log n).
⚠️A pointer-heavy structure
Every node has several pointers, and pointer-chasing is slow on CPU caches. For data that must live on disk, or for very cache-sensitive code, a B-Tree or a sorted array can be faster even though a skip list looks good on paper.

08Key Terms to Know

TermMeaning in easy words
Skip listA sorted linked list with extra lanes that let searches skip many items
Lane / levelOne linked list in the stack. Lane 1 holds every key, higher lanes hold fewer
TowerThe stack of nodes that represent one key on several lanes
HeadA special starting node that has a pointer on every lane
Forward pointerA link that says which key comes next on this lane
PromotionPutting a key on the next lane up after a coin flip comes up heads
ProbabilisticBuilt on chance. The structure is balanced on average, not by strict rules
Range queryAsk for all keys between two values, such as all scores from 100 to 200
RankThe position of a key in the sorted order (the 5th smallest, for example)
Sorted set (ZSET)A Redis type that keeps unique members ordered by a score, built on a skip list
Lock-freeA way to write concurrent code with atomic steps instead of locks, which skip lists suit well

09Pros, Cons and Trade-offs

✅ Pros
  • O(log n) average search, insert and delete
  • Much simpler than a balanced tree
  • Sorted order and fast range scans
  • Concurrent versions are easy to build
  • No expensive re-balancing steps
⚠️ Cons
  • The O(log n) time is only on average, not a hard guarantee
  • Extra memory for the pointers (about 2 per key on average)
  • Poor cache behaviour, because nodes are scattered in memory
  • Not made for disk storage
  • Results depend on a random number generator

Trade-offs

ChoiceWe gainWe lose
Promotion chance 1/2Shorter searchesMore pointers per key
Promotion chance 1/4Fewer pointers, less memorySlightly longer searches
Skip list instead of a balanced treeSimple code and easy concurrencyNo strict worst-case promise
Skip list instead of a hash tableSorted order, ranges and rankSlower single lookups than O(1)
More lanes allowedHandles bigger dataA little more memory for the head
Skip list instead of a B-TreeSimple in-memory structureMany more cache misses and no disk-friendly layout

10Common Problems and Mistakes

Common mistakes

  1. Saying it is always O(log n). It is O(log n) on average. The worst case is O(n), though very unlikely.
  2. Using a poor random source. If the coin flips are biased or repeat in a pattern, the lanes become unbalanced and searches slow down.
  3. Forgetting the bottom lane holds everything. Deleting a key from only some lanes leaves broken links.
  4. Choosing too few lanes. With a small maximum height and a lot of keys, the top lane gets long and searches slow toward O(n).
  5. Using it for disk data. Pointers jump around, which means many disk reads. Use a B-Tree there.
  6. Ignoring concurrency in a shared list. Two threads inserting next to each other must link nodes safely, or links can be lost.
  7. Expecting a fixed shape. Two skip lists with the same keys can look different. Do not write tests that depend on the exact tower heights.

Things to watch

🪙Random quality
Use a fast, decent random generator. Do not call a slow secure one on every insert.
🧠Memory use
Each key may carry several pointers. For billions of small keys this adds up.
🚶Cache misses
Following pointers across memory is slower than scanning an array. Measure on your own data.
🔒Lock choices
Coarse locking hurts throughput. Lock-free or per-node locking keeps many threads busy.

11Real-World Examples

🟥Redis leaderboards
Sorted sets power game rankings and top-N lists using a skip list plus a hash table.
🗃️LSM databases
LevelDB and RocksDB use a skip list for the in-memory memtable before data is flushed to sorted files.
☕Java concurrent maps
ConcurrentSkipListMap is the standard choice for a thread-safe sorted map.
🔎Search engines
Skip pointers in posting lists speed up finding documents that contain several words at once.
⏱️Time-ordered buffers
Event or order books keyed by price or time need fast insert and sorted reads.
📚Teaching
Often shown as the easy alternative to red-black trees in data structure courses.
📝Note
Exact defaults and implementation choices differ by product and version. Check the documentation of the system you use before relying on a detail.
Mini case: a game leaderboard
🎮Player scores 880
→↓insert
📶Skip listsorted by score
→↓walk from the top
🏆Top 10list
Write Sorted structure Read
A skip list keeps scores in order, so the top 10 is a short walk, and a new score is an O(log n) insert.
Typical lookups for 1 million keys (rough idea)skip list: tens of steps
Plain linked list for the same keysup to a million steps

12Related Topics to Read Next

LSM Trees→

Their in-memory write buffer is often a skip list.

B-Trees and B+ Trees→

The disk-friendly sorted structure that skip lists are often compared with.

Key-Value Databases→

Redis sorted sets are a classic skip list use.

Indexing→

A skip list is one way to keep an ordered index in memory.

Bloom Filters→

Another probabilistic structure, used to skip work in a different way.

Full-Text Search Engines→

Skip pointers speed up joining word lists.

13Interview Questions with Short Answers

14Quick Revision Cheat-Sheet

  • ✔What: a sorted linked list with express lanes, built with coin flips.
  • ✔Search: start at the top lane, go right while the next key is smaller, else drop down.
  • ✔Cost: O(log n) average for search, insert and delete. Worst case O(n), very rare.
  • ✔Height: flip a coin per lane. Half reach lane 2, a quarter reach lane 3.
  • ✔Space: O(n), about 2 pointers per key with promotion chance 1/2.
  • ✔Bonus: the bottom lane is sorted, so range scans are easy.
  • ✔Used in: Redis sorted sets, LevelDB and RocksDB memtables, Java ConcurrentSkipListMap.
  • ✔One line: “A linked list with express lanes, so you rarely walk the whole list.”
← Previous
Cuckoo Filter
Next →
Count-Min Sketch