Computer Science · Simulator 058
A hash table turns a key into an array index so lookups are nearly instant. But two keys can land in the same slot. Insert keys one by one, compare collision-resolution strategies, and watch how probe counts climb as the table fills.
A hash function maps a key to a slot: h(k) = k mod m for integer keys, or a polynomial string hash. When two keys map to the same slot, that is a collision:
As α approaches 1, open addressing degrades sharply. Tables usually resize (double m and rehash) at α ≈ 0.7. The readout compares measured average probes with these formulas. A poor hash, for example m sharing factors with patterned keys, makes collisions much worse.
Keys are integers or short strings; deletion (which needs tombstones in open addressing) is not shown.
With linear probing, why is inserting into a slot right after a long cluster more likely than into an isolated empty slot?
Any key hashing anywhere into the cluster probes to its end, so a slot right after a cluster of length L is filled with probability about (L + 1)/m, against 1/m for an isolated slot. Clusters therefore grow faster the longer they are: the “rich get richer” effect behind primary clustering.