A skip list stores a sorted set of keys in a hierarchy of sorted linked lists. Every key is in the bottom list, level 1, and each key is independently given a height with , so that it appears in levels . A search starts at the top level of a header node, moves right while the next key on the current level is smaller than the target, and drops one level when it is not. A treap is a binary search tree on the keys that is also a max-heap on independent random priorities attached to them: every node’s priority exceeds its children’s. Its shape is the shape of the binary search tree obtained by inserting the keys in decreasing order of priority, which is a random binary search tree whatever order the keys actually arrive in.

Both structures replace the rebalancing rules of AVL or red-black trees with a random choice made once per key. A skip list’s level holds about keys, so each level is a sample of the one below and a search crosses about keys per level over levels. A treap’s priorities decide which key is the root of every subtree, and a key becomes an ancestor of another exactly when its priority is the largest in the range between them. The expected search cost of either structure is for every input sequence, with the expectation taken over the structure’s own random choices; no input order, sorted or adversarial (as long as the adversary does not see the random choices), produces a deep structure more often than any other.

Pugh (1990) introduced skip lists as a simpler alternative to balanced trees. Seidel and Aragon (1996) introduced treaps (as randomized search trees) and analyzed their expected depth, rotations and the cost of split and join. Skip lists are the in-memory index of LevelDB’s memtable and of Redis’s sorted sets. LevelDB’s readers traverse the list without locks while one writer inserts, which a skip list allows because an insertion only links a new node into each of its levels from the bottom up.

The data

The keys are the 64-bit hashes of the benchmark’s (project, page) keys used by the earlier notes of the series, the 60,974,808 distinct values in order of first appearance; the experiments use the first , or of them. Because the keys are hashes, their order of first appearance is a random permutation of their sorted order. A second run inserts the same keys in sorted order, which makes an unbalanced binary search tree degenerate into a list and leaves the expected shape of a skip list or treap unchanged.

Skip lists

A key’s height is where counts successes of a coin with probability before the first failure, so the expected height is and a skip list holds forward pointers in expectation, for and for . The number of levels is the largest height, about ; implementations cap it at a constant such as 12 in LevelDB, with , which bounds the levels but not the search cost for sets larger than the cap’s design size.

The cost of a search follows from looking at its path backwards (Pugh 1990). Seen from the target, the path climbs one level each time it reaches a key taller than the current level, which happens with probability at each step, and otherwise moves left. The expected cost of climbing to level is at most , and of crossing the levels above it at most , so Pugh bounds the expected number of comparisons by

which is for and .

The exact expectation can be written down for any counting convention. Counting every key comparison, one for each move to the right, one that ends each level whose next pointer exists, and a final equality test, the search for the -th smallest of keys makes

comparisons. A key is moved to on level exactly when its height is and no key between it and the target is taller, which gives the first term; level ends with a comparison exactly when some key at or after the target is taller than , which gives the second.

Expected comparisonsMeasured mean (range over seeds)Largest for one keyLevels
1/239.6439.60 (38.34 to 41.17)70 to 7519 to 25
1/438.6438.61 (36.55 to 42.55)92 to 10710 to 12
1/246.2945.87 (45.11 to 46.60)85 to 8922 to 25

Each row is 10 skip lists with different seeds and the row is 3; the mean is over all keys of each list. The measured means agree with the expectation to within the spread between seeds, which comes mostly from the few keys at the top levels. The two values of give nearly the same mean, since the leading term is for both, but uses a third fewer pointers and has a wider distribution: its worst key took 92 to 107 comparisons against 70 to 75. Pugh recommended unless the variability of running times is a primary concern, in which case . Redis’s sorted sets use with at most 32 levels, and a 2017 pull request proposed , which minimizes at comparisons (2.718 against 2.885) for 1.58 pointers per key.

Treaps

In a random binary search tree on keys , key is an ancestor of key exactly when has the largest priority among the keys between and inclusive, which has probability . Summing over , the depth of the -th key with the root at depth 1 has expectation

where , and the mean depth over all keys is . A successful search compares the target with every key on its path, so its cost is the depth. The expected number of rotations per insertion or deletion is less than 2 (Seidel and Aragon 1996), independent of .

Expected mean depthMeasured mean (range)Height
25.7925.77 (25.22 to 26.37)48 to 54
30.3930.33 (29.37 to 31.35)57 to 65

The row is 10 treaps and the row is 3. A treap’s search makes about two thirds as many comparisons as a skip list’s with , since a skip list compares the target with keys per level including the one that ends the level, and the treap’s is against the skip list’s .

Running time

Each figure is nanoseconds per operation, the median of 3 repetitions on one core. A lookup is a successful search for a key drawn at random from the set; building is inserting every key into an empty structure, or for the sorted array, copying and sorting the keys. The treap, std::map and sorted array ran once alongside each value of , so their cells give both runs. The first table is lookup time and the second is build time per key.

KeysInsertion orderSkip list, Skip list, Treapstd::mapSorted array
random1,0061,435876, 1,0281,054, 1,038221, 226
sorted773886756, 7591,114, 1,133221, 232
random2,3213,6572,558, 2,5722,144, 2,024444, 428
sorted1,7102,4231,867, 1,8032,205, 2,035407, 419
KeysInsertion orderSkip list, Skip list, Treapstd::mapSorted array
random1,0071,350948, 922815, 871211, 216
sorted12811856, 55217, 22529, 30
random2,3683,1302,435, 2,3081,865, 1,816340, 300
sorted12612374, 72429, 36837, 36

The two treap runs at keys in random order executed identical code and differ by 17% in lookup time, which sets the scale of the noise on this machine; differences smaller than that are not meaningful here.

  • Against the sorted array. With keys inserted in random order, every pointer structure took 4.0 to 8.5 times as long per lookup as binary search on the sorted array, which makes about comparisons (20 or 23) in one contiguous block of memory.
  • Comparisons and time. A treap search made about two thirds of the comparisons of a skip-list search with and read fewer distinct nodes (25.8 against 32.4 to 33.7 at keys, counting a node once when a level ends at it and the next level starts by reading it again), yet its lookups were no faster. The skip list with made slightly fewer comparisons than with and read 14% more distinct nodes at keys (37.6 against 33.0 on average over 3 seeds) and 10% more at , but its lookups took 43% longer at keys and 58% longer at . I did not measure cache misses, so these runs do not separate the causes, but neither count of the search predicted its time.
  • Insertion order. Both the skip list and the treap allocate nodes in insertion order, so after sorted insertion the nodes adjacent in key order are adjacent in memory, and their lookups were 14 to 38% faster than after random insertion; std::map’s were not. Sorted insertion also made building fast, since each insertion’s search path runs along the most recently inserted nodes, which are likely still in cache.
  • Building in random order. Inserting a key cost about as much as looking one up in the skip list and treap, and at keys std::map built in 21 to 23% less time than the treap and the skip list with .

Pugh’s (1990) table of normalized search times gives the same value as , since is the same for both, with 1.33 pointers per node against 2. On this machine and at these sizes searched more slowly, so the choice of is worth measuring on the hardware that will run it.

The figure

Skip list (levels 1, 2, … across)

123head1 AMDAMD2 Alien: EarthAlien: Earth3 Fahrenheit 451Fahrenheit 4514 General MotorsGeneral Motors5 GoyGoy6 Green DayGreen Day7 High and Low (1963 film)High and Low (1963 film)8 Hillsborough disasterHillsborough disaster9 Limp BizkitLimp Bizkit10 LouvreLouvre11 MedusaMedusa12 Microsoft 365Microsoft 36513 The Crow GirlThe Crow Girl14 The Voice of Hind RajabThe Voice of Hind Rajab15 Tower of LondonTower of London16 VK (service)VK (service)

Treap (same keys, numbered as in the skip list)

1AMD, priority 0.1272Alien: Earth, priority 0.8593Fahrenheit 451, priority 0.0724General Motors, priority 0.5295Goy, priority 0.2906Green Day, priority 0.5037High and Low (1963 film), priority 0.5448Hillsborough disaster, priority 0.0789Limp Bizkit, priority 0.23210Louvre, priority 0.66611Medusa, priority 0.84912Microsoft 365, priority 0.34013The Crow Girl, priority 0.09914The Voice of Hind Rajab, priority 0.69715Tower of London, priority 0.31516VK (service), priority 0.892
moved tocompared, ends a levelfound

Finding AMD among the 16 drawn titles takes 4 comparisons in the skip list and 3 in the treap.

Over all 2,000 titles, the skip list with p = 1/2 has 15 levels and makes 24.45 comparisons per search on average (expected 21.72), at most 39. The treap has height 25 and mean depth 13.47 (expected 13.36).

Comparisons to find each of the 2,000 titles

skip listtreapexpected for each position
01020304015001,0001,5002,000position of the title in sorted order
The keys are 2,000 English Wikipedia article titles drawn at random from the 12,546 articles with titles of at most 32 characters that had 20 or more views in the hour ending 12:00 UTC on 4 March 2026, inserted in random order. The drawn structures hold the first 16 titles inserted. Levels and priorities come from a seeded generator in the browser; a skip-list comparison is counted for each move, for each comparison that ends a level, and for the final equality test, and a treap search makes one comparison per node on its path.

Consequences

Skip lists and treaps give expected search cost on every input order with no balance information stored in the nodes and no rebalancing rules: a skip-list insertion splices one node into lists, and a treap insertion is a binary-search-tree insertion followed by rotations that restore the heap order. The exact expectations above matched the measured mean costs on and keys to within the spread between seeds.

Neither structure looked up keys faster than std::map’s red-black tree after random insertion, beyond the noise, and the treap was slower at keys. Each step of a pointer-based search loads a node whose address depends on the previous load, and a sorted array with binary search was 4.0 to 8.5 times faster for lookups than all three pointer structures here. The case for skip lists rests on concurrency and simplicity of insertion, as in LevelDB’s memtable, and the case for treaps on split, join and order-statistic operations that follow directly from the heap order.