Probing strategies side by side: linear, quadratic, double hashing
My notes comparing open addressing strategies. h is the hash index, i is the attempt number.
Linear: (h + i) mod capacity. Simple, but suffers from primary clustering.
Quadratic: (h + i²) mod capacity. Avoids primary clustering but can fail to find an open spot even when one exists.
Double hashing: (h + i · h2(key)) mod capacity. Spreads probes out the most, costs a second hash.
On removal with open addressing, you can't just empty the slot, or later searches stop too early. Mark it "deleted" instead, and reuse those slots on insert.
Comments
The note about marking deleted slots is so important. Classic bug.