Skip list
A sorted linked list with randomly built express lanes, giving fast search and ordered iteration with simple code.
A skip list is a sorted linked list where some nodes also appear in higher “express” lists that skip over many nodes. Which nodes get promoted is decided by coin flips, so on average each level has half the nodes of the one below. A search runs along the top level, drops down when it would overshoot, and finds a key in logarithmic time. William Pugh introduced it in 1990 as a simpler alternative to balanced trees.
Its appeal is simple code and easy concurrent inserts, since no global rebalancing is needed. Redis sorted sets (leaderboards, time-ordered queues) combine a skip list with a hash table, and the in-memory table of RocksDB is a skip list by default before data is flushed to an LSM tree file.
On disk, B-trees win, because they read whole pages at once; skip lists are an in-memory structure.
Sources
- Communications of the ACM: Pugh, Skip Lists: A Probabilistic Alternative to Balanced Trees (1990) doi.org
- Redis docs: Sorted sets redis.io
- RocksDB wiki: MemTable github.com
Related terms
- B-tree: A sorted, wide and shallow tree that stores keys in disk-sized pages; the default index in most relational databases.
- LSM tree (log-structured merge tree): A storage design that buffers writes in memory and flushes them as sorted files merged in the background; fast writes, more work on reads.
- HNSW (hierarchical navigable small world): A layered graph index that finds approximately nearest vectors fast; the default index in most vector databases, trading a little recall for speed.
- Heap (priority queue): A tree kept just ordered enough that the smallest or most urgent item is always on top, with cheap inserts and removals.
