We use analytics cookies.We use cookies to analyze site traffic and improve your experience.
Loading...
This idea carries a full system design question on its own. Each walks through the full answer.
System Design Masterclass · Database Types Storage
Free preview: the first 2 parts of this 6-part lesson.
Already bought the course? Sign in to read the whole lesson.
this lesson is part of
System Design Masterclass
Unlock this lesson and the 751 other paid lessons
$25 once, by PayPal
See the System Design courseread the rest of this lesson in
System Design Masterclass
Unlock this lesson and the 751 other paid lessons
$25 once, by PayPal
See the System Design coursein Database Types Storage
This lesson is part of the full System Design Masterclass. Unlock it along with 769 other lessons for a one-time payment.
One-time payment by card or PayPal
Get Lifetime AccessOne-time payment: UPI, card or netbanking
Get Lifetime Access18 Foundation lessons are free, no payment needed. Try them now
It is easy and good
“It is really nice and good Please join the course”
Linked lists are simple and beautiful. Insert a node? O(1). Delete a node? O(1). Traverse? O(n). Search? Also O(n). And that's the problem, searching a linked list means walking every single node from the beginning until you find what you're looking for.
Balanced binary trees (AVL trees, red-black trees) solve the search problem. O(log n) lookups. But they're complex to implement. Rotations, rebalancing, color-flipping, the code is notoriously error-prone and hard to debug.
In 1990, William Pugh published a paper with a deceptively simple idea: what if you gave a linked list express lanes? Instead of walking every node, what if some nodes had pointers that let you skip ahead, like an express subway line that stops at every 4th station?
That's a skip list. It gives you O(log n) search, insertion, and deletion, the same as a balanced BST, but with an implementation so simple you can code it from memory in an interview.
uses skip lists as the backbone of its sorted sets (ZSET). When you run ZRANGEBYSCORE in Redis, you're walking a skip list. LevelDB and MemSQL use them too. They're one of those data structures that look like a toy but power serious production systems.
A skip list is a multi-level sorted linked list where each level acts as an "express lane" for the level below.
Searching for a value:
Inserting a value:
This randomized promotion is the genius of skip lists. You don't need complex rebalancing algorithms, probability handles the balance for you. On average, the structure stays balanced, giving O(log n) operations.
| Operation | Average Case | Worst Case |
|---|---|---|
| Search | O(log n) | O(n) |
| Insert | O(log n) | O(n) |
| Delete | O(log n) | O(n) |
| Space | O(n) | O(n log n) |
The worst case is theoretically possible (every coin flip is heads, creating a tall tower), but astronomically unlikely with a fair random number generator.