A sorted list with express lanes, so search is fast without a tree (used in Redis).
A skip list is a sorted linked list with extra express lanes on top. The express lanes let a search jump over many items at once, so it is fast without using a tree.
Start with a sorted linked list: 4 → 9 → 13 → 20 → 26 → ... To find 57 you must walk through every item before it. For a million items that is up to a million steps.
Now add a second lane above it that links every other item. Then a third lane that links every other item of that lane, and so on. You search from the top: go right while the next key is still smaller than your target, otherwise drop down one lane and keep going. Each drop cuts the remaining work roughly in half, just like binary search.
Building the lanes in a perfect pattern would make inserts painful (every insert would shift the pattern). So a skip list does something clever and lazy: when you insert a key, it flips a coin. Heads, the key also joins the next lane up, and the coin is flipped again. Half of the keys reach lane 2, a quarter reach lane 3, an eighth reach lane 4, and so on. The lanes come out roughly balanced, with no complex rotation code.
| Item | Typical value | Why |
|---|---|---|
| Chance a key reaches lane 2 | 1/2 | One head on the first flip |
| Chance a key reaches lane 3 | 1/4 | Two heads in a row |
| Average pointers per key | About 2 | 1 + 1/2 + 1/4 + ... adds up to 2 |
| Number of useful lanes | About log2(n) | The lanes run out when only a key or two is left on top |
| Search, insert, delete | O(log n) on average | Each drop halves the remaining work |
| Worst case | O(n) | Extremely unlikely with random levels, but possible in theory |
| Structure | Search | Range scan | Notes |
|---|---|---|---|
| Sorted array | O(log n) with binary search | Very fast | Insert and delete are slow (items must shift) |
| Sorted linked list | O(n) | Fast | Simple, but search is slow |
| Skip list | O(log n) average | Fast (walk the bottom lane) | Simple, easy to make concurrent, uses extra pointers |
| Balanced tree (red-black, AVL) | O(log n) worst case | Fine, needs in-order walk | Strict guarantee, but rotations make it harder to build and to lock |
| B-Tree | O(log n) with few disk reads | Fast | Made for disk pages, not for pointer-based RAM structures |
Only 12 keys are shown, so the saving looks small. With a million keys a skip list needs about 20 to 40 lookups, while a plain list may need a million. The lane heights here are fixed on purpose (a real skip list flips a coin for each new key).
| Term | Meaning in easy words |
|---|---|
| Skip list | A sorted linked list with extra lanes that let searches skip many items |
| Lane / level | One linked list in the stack. Lane 1 holds every key, higher lanes hold fewer |
| Tower | The stack of nodes that represent one key on several lanes |
| Head | A special starting node that has a pointer on every lane |
| Forward pointer | A link that says which key comes next on this lane |
| Promotion | Putting a key on the next lane up after a coin flip comes up heads |
| Probabilistic | Built on chance. The structure is balanced on average, not by strict rules |
| Range query | Ask for all keys between two values, such as all scores from 100 to 200 |
| Rank | The position of a key in the sorted order (the 5th smallest, for example) |
| Sorted set (ZSET) | A Redis type that keeps unique members ordered by a score, built on a skip list |
| Lock-free | A way to write concurrent code with atomic steps instead of locks, which skip lists suit well |
| Choice | We gain | We lose |
|---|---|---|
| Promotion chance 1/2 | Shorter searches | More pointers per key |
| Promotion chance 1/4 | Fewer pointers, less memory | Slightly longer searches |
| Skip list instead of a balanced tree | Simple code and easy concurrency | No strict worst-case promise |
| Skip list instead of a hash table | Sorted order, ranges and rank | Slower single lookups than O(1) |
| More lanes allowed | Handles bigger data | A little more memory for the head |
| Skip list instead of a B-Tree | Simple in-memory structure | Many more cache misses and no disk-friendly layout |