Hash tables and collisions

Insert 2, 7 and 12 into five slots. All three keys start at slot 2. Compare how two layouts later find and remove a key.

The home slot h is the key modulo m. Use a residue from 0 to m − 1 even for negative keys.

A tombstone × keeps the search path intact after deletion. Continue past it. An empty slot ∅ ends the search.

With well-distributed keys and a modest load, operations take O(1) on average. A worst-case search scans a whole chain or table.