Sketch · 2026-11-11
Robin Hood hashing, against linear probing.
An open-addressing hash table keeps every key in one flat array. A key goes to the slot its hash names, and if that slot is taken it walks right until it finds a free one. How far it walked is its displacement. Both tables below receive the same keys in the same order. They differ in one rule about who has to keep walking.
Point at a slot to see where its key wanted to live.
| linear | robin hood | theory | |
|---|---|---|---|
| mean probes, hit | |||
| mean probes, miss | |||
| longest walk | |||
| variance | |||
| total displacement |
Keys by displacement
What to look at
Drag the load past 0.8 and compare the bottom row of the table. Total displacement is the same number in both columns, every time, for every set of keys. That is not luck. Both tables end up with the same slots occupied, because a run of full slots grows the same way no matter which key inside it moves. Robin Hood only decides who pays. So the mean cost of finding a key that is present cannot change.
The spread changes a lot. Under linear probing the key that arrives last at a busy cluster walks its whole length, while keys that came early sit at home. Robin Hood compares displacements at each occupied slot. If the walking key is further from home than the resident, they swap and the resident walks on instead. Taking from the rich and giving to the poor is where the name comes from. The longest walk drops, and the variance falls even further.
The bigger win is on misses. Because keys in a cluster end up sorted by home slot, a lookup can stop as soon as it meets a resident that is closer to home than the search has walked. The key it wants would have evicted that resident, so it is not further on. Linear probing has to walk until it reaches an empty slot. At load 0.95 that gap is the second row, and it is wide.
The theory column is Knuth's approximation for linear probing, (1 + 1/(1 − α)) / 2 for hits and (1 + 1/(1 − α)²) / 2 for misses. It assumes an infinite table and averages over all key sets, so on 256 slots it wanders. Press New keys a few times at high load to see by how much. Deletion is left out: Robin Hood tables usually shift the following keys back one slot instead of leaving tombstones, and that deserves its own page.
Sources
- Celis, P., Larson, P.-A., Munro, J. I. (1985). Robin Hood Hashing. 26th Annual Symposium on Foundations of Computer Science, pages 281-288.
- Knuth, D. E. (1998). The Art of Computer Programming, Volume 3: Sorting and Searching, second edition. Section 6.4, Hashing.
- Peterson, W. W. (1957). Addressing for Random-Access Storage. IBM Journal of Research and Development, 1(2), pages 130-146.