Chapter 12 · Simulation

Open Addressing Simulator

← Chapter 12

Formula

h(k, i) = (h(k) + i) mod 13
occupied✗ DEFUNCT (deleted)probed (number = probe order)home slot h(k)

Probe sequence

  1. No operations yet.

History

  1. No operations yet.

Open Addressing Simulator

With open addressing, every key lives directly in the table array. If the home slot h(k) = k mod N is taken, the key follows the probe sequence j = (h(k) + f(i)) mod N for i = 0, 1, 2, … until it finds a usable slot.

Controls

  • Type an integer key and choose Insert, Search or Delete. Probed slots are numbered in probe order, and the home slot is outlined.
  • Pick the probing method and the table size N. Changing either one rebuilds the table and reloads the sample keys (18, 41, 22, 44, 59, 32, 31, 73).
  • The probe sequence panel lists every probe of the last operation; the counters show the number of keys n, the load factor λ = n / N, the number of ✗ markers and the probes used.

Probing methods

Methodf(i)Note
LineariSimple, but builds long runs (primary clustering).
Quadratici²Breaks up runs but may miss some slots; with a prime N, λ ≤ 0.5 guarantees an empty slot is found.
Double hashingi · h₂(k)h₂(k) = R − (k mod R), R = 7 (R = 5 when N = 7); the step is never 0.

Deleting with DEFUNCT markers

Emptying a slot would cut every probe sequence that passes through it, so a deletion leaves a ✗ DEFUNCT marker behind. Search skips markers and stops only at a truly empty slot; insertion, once it knows the key is not in the table, may reuse the first marker it met.

Load factor

The expected number of probes climbs steeply as λ approaches 1. Open-addressing tables are usually kept at λ ≤ 0.5 and rehashed into a larger table once they pass it; the λ box is highlighted above 0.5.