Data Structures · Visualization
Skip List: Search
Skip List
Searching a skip list walks right along the top level as far as possible without overshooting the target, then drops down a level and repeats, using the higher levels as express lanes to skip large chunks of the list. Time: O(log n) expected, O(n) worst case. Space: O(1) auxiliary.
Big-O: Search / insert / delete O(log n) expected thanks to the extra skip lanes.
Skip List: Search
Skip ListSearching a skip list walks right along the top level as far as possible without overshooting the target, then drops down a level and repeats, using the higher levels as express lanes to skip large chunks of the list.
How Search Works
- Start at the highest level's leftmost (head) node.
- While the next node at this level exists and its value ≤ target, move right.
- If the next node would overshoot (value > target) or there's no next node, drop down one level.
- Repeat until level 0; check if the current next node equals the target.
Search Worked Example
Input: Search for 9 in the skip list from the Introduction example
- Level 2: 3 → 9 (9 ≤ 9, move right); next would be 21 > 9, drop down
- Level 1: already at 9, next is 12 > 9, drop down
- Level 0: at 9, matches target
Output: Found 9 in 2 moves across levels
Press ▶ Run to watch it step by step.
def search(head, max_h, key):
cur = head
for level in range(max_h - 1, -1, -1):
while (cur.next[level] and
cur.next[level].key < key):
cur = cur.next[level] # jump ahead on fast lane
cur = cur.next[0] # land on base level
return cur.key == key if cur else False
# example: search 9 on [3, 6, 7, 9, 12, 17, 19, 21, 25]Behind the Scenes Execution
Press ▶ Run in the visualizer — the call stack, registers and memory will replay here in sync with the code, line by line.
Search Time & Space Complexity
When to Use Search
- Range queries in sorted in-memory stores
- Fast membership tests in ordered sets
- Database index scans
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.