← CodeClarityLab Home
Browse by Category
+ added · updated 7d
← Back to glossary

Skip Lists

data_structures Advanced

Also Known As

skip list probabilistic data structure Redis sorted set

TL;DR

A probabilistic data structure providing O(log n) search, insert, and delete — used internally in Redis sorted sets for ZADD/ZRANGE operations.

Explanation

A skip list is a layered linked list: the bottom layer has all elements in sorted order; each higher layer contains a random subset of the elements below, acting as express lanes. Search: start at the top layer, move right until the next element is too large, then drop down — O(log n) expected. Insert: coin flips determine which layers the new element appears in. Redis uses skip lists for sorted sets (ZADD/ZRANGE). Advantages over balanced BSTs: simpler implementation, easier lock-free concurrent modification.

Common Misconception

Skip lists are always inferior to balanced BSTs because they are probabilistic — they have the same expected O(log n) complexity and are often faster in practice due to better cache performance and simpler concurrent implementations.

Why It Matters

Redis sorted set operations (ZADD, ZRANGEBYSCORE) are O(log n) because of skip lists — understanding this explains why bulk inserts should be pipelined and why ZRANGEBYSCORE is O(log n + M).

Common Mistakes

  • Fixed levels instead of probabilistic promotion — breaks expected O(log n)
  • Maximum level too low — degrades to O(n)
  • Using skip list where a hash map suffices — add ordering only when needed
  • Concurrent modifications without proper synchronisation

Code Examples

✗ Vulnerable
// Assuming zadd is O(1):
for ($i = 0; $i < 1000000; $i++) {
    $redis->zadd('leaderboard', $score, $userId);
    // 1M * O(log n) = O(n log n) total — expected but surprising
}
✓ Fixed
// Pipeline for bulk inserts:
$pipeline = $redis->pipeline();
foreach ($scores as $userId => $score) {
    $pipeline->zadd('leaderboard', $score, $userId);
}
$pipeline->execute(); // Single round trip for all insertions

Added 16 Mar 2026
Edited 22 Mar 2026
Views 22
Rate this term
No ratings yet
🤖 AI Guestbook educational data only
| |
Last 30 days
2 pings W 0 pings T 2 pings F 2 pings S 0 pings S 0 pings M 0 pings T 0 pings W 0 pings T 1 ping F 0 pings S 0 pings S 0 pings M 0 pings T 0 pings W 0 pings T 2 pings F 0 pings S 0 pings S 0 pings M 0 pings T 0 pings W 0 pings T 1 ping F 1 ping S 0 pings S 0 pings M 0 pings T 0 pings W 0 pings T
No pings yet today
No pings yesterday
Amazonbot 8 Perplexity 5 Unknown AI 3 Ahrefs 2 Google 1
crawler 18 pre-tracking 1
DEV INTEL Tools & Severity
🔵 Info ⚙ Fix effort: High
⚡ Quick Fix
Use Redis sorted sets (which implement skip lists internally) for ordered data with O(log n) rank queries — no need to implement skip lists in PHP directly
📦 Applies To
any web cli
🔗 Prerequisites
🔍 Detection Hints
Sorted collection requiring O(log n) search and insert; leaderboard with rank queries needing efficient ordered operations
Auto-detectable: ✗ No
⚠ Related Problems
🤖 AI Agent
Confidence: Low False Positives: Medium ✗ Manual fix Fix: High Context: Class Tests: Update

✓ schema.org compliant