Data Structures · Visualization
Skip List: Introduction
Skip List
A skip list is a layered linked list where higher levels skip over many elements, giving expected O(log n) search, insert, and delete without the rebalancing logic of trees. Time: Search/Insert/Delete: O(log n) expected. Space: O(n) expected (extra pointers for higher levels).
Big-O: Search / insert / delete O(log n) expected thanks to the extra skip lanes.
Skip List: Introduction
Skip ListA skip list is a layered linked list where higher levels skip over many elements, giving expected O(log n) search, insert, and delete without the rebalancing logic of trees. Each node is randomly promoted to higher levels via coin flips, creating express lanes over the base sorted list.
How Skip List: Introduction Works
- Maintain multiple linked lists ('levels'), where level 0 contains all elements in sorted order.
- Each higher level contains a random subset of the elements below it (typically ~50% via coin flip).
- To search, start at the top-left, move right while the next value is ≤ target, then drop down a level when you'd overshoot.
- Repeat until level 0 is reached — you've either found the target or its correct insertion point.
Skip List: Introduction Worked Example
Input: Search for 17 in a skip list of {3,6,7,9,12,17,19,21,25}
- Level 2: 3 → 9 → 21 (17 < 21, drop down from 9)
- Level 1: 9 → 12 → 19 (17 < 19, drop down from 12)
- Level 0: 12 → 17 (found!)
Output: Found 17 in 3 comparisons instead of scanning 6 elements
Press ▶ Run to watch it step by step.
import random
class Node:
def __init__(self, key, height):
self.key = key
self.next = [None] * height
def random_height(max_h):
h = 1
while h < max_h and random.random() < 0.5:
h += 1
return h
head = Node(None, 6) # sentinel towers
# levels act like express lanes over the base list
# example: view 17 on [3, 6, 7, 9, 12, 17, 19, 21, 25]Skip List: Introduction Time & Space Complexity
When to Use Skip List: Introduction
- Redis sorted sets (ZSET) implementation
- LevelDB / RocksDB memtables
- Concurrent data structures (lock-free skip lists)
- Alternative to balanced trees when simplicity matters
Recommended resourcesAffiliate links · may earn us a commission
Recommended for learners
Ready for the next step?
See the same ideas in action — visualize the algorithms that operate on these structures, or take a guided course.