Simple implementation of deletion from open-address hash table
Deletion from open-address hash table is not so easy as deletion from chained hash table, because in open-address table we can't simply mark a slot containing deleted key as empty. Search for keys may
Deletion from open-address hash table is not so easy as deletion from chained hash table, because in open-address table we can’t simply mark a slot containing deleted key as empty. Search for keys may become incorrect. The classical method to implement deletion is to mark slots in hash table by three values: “free”, “busy”, “deleted”. That method is easy to implement, but there are some disadvantages. In this article we consider alternative method of deletion keys, where we avoid using the mark “deleted”. The article contains the implementation of the method in Java.
💡 Research Summary
The paper addresses a well‑known difficulty in open‑address hash tables: deleting an entry without corrupting subsequent searches. In chained hash tables a deletion is trivial, but in open addressing a naïve “make the slot empty” approach breaks the probe sequence, causing keys that were inserted after the deleted one to become unreachable. The classic solution introduces a third slot state, “deleted”, which allows the probe to continue while marking the slot as unavailable for new insertions. Although functional, this three‑state scheme has several drawbacks: it requires an extra flag per slot, it complicates the logic for when to trigger a rehash, and the accumulation of deleted markers can degrade performance over time.
The author proposes an alternative method that completely eliminates the “deleted” marker. The key insight is that after removing an element, the now‑empty slot can be filled by moving a later element forward, provided that the moved element’s original hash position lies before the empty slot in the circular ordering of the table. By repeatedly shifting such elements toward the empty slot, the algorithm restores a valid probe sequence while leaving the slot truly empty for future insertions.
Algorithmic steps:
- Locate the slot containing the key to be removed using the standard probe routine (
findSlot). - Set that slot to
null(empty) and start a “shift‑delete” process from this position. - Iterate forward through the table (wrapping around at the end). For each occupied slot
i, compute the original hash indexh = hash(key_i). Determine the circular distance fromhtoi(dist_i) and fromhto the current empty slot (dist_empty). Ifdist_i > dist_empty, the element atishould have been placed earlier; therefore move it into the empty slot, markias the new empty slot, and continue. - Stop when a full cycle is completed without any move, or when the empty slot reaches the end of the table.
The method works with any probing strategy (linear, quadratic, double hashing) because the only requirement is a deterministic, wrap‑around probe sequence. The worst‑case time complexity of a single deletion is O(m) where m is the table size, but in practice the number of shifted elements is small, yielding near‑constant average cost. Memory usage is reduced because no extra boolean flag is stored per entry; each slot holds only the key/value (or null). Moreover, because the slot truly becomes empty, subsequent insertions can use it immediately, avoiding the “deleted‑slot backlog” problem of the three‑state approach.
The paper supplies a complete Java implementation. The delete(K key) method first finds the index, sets `table
📜 Original Paper Content
🚀 Synchronizing high-quality layout from 1TB storage...