The core problem to solve: given a key whose home slot is occupied, which slot do we try next? A probe sequence is the ordered list of slots we examine.
Why does primary clustering happen? Any key whose home falls anywhere inside a cluster of length L lands at the end, extending it. So a cluster of size L captures a fraction ∝L of new keys → big clusters get bigger. Rich-get-richer.
Derivation of expected probes (uniform hashing assumption).
Assume each probe lands on an independent uniformly random slot. Probability a slot is occupied ≈α.
For an unsuccessful search, we keep probing until we hit an empty slot. The number of probes X satisfies P(X>i)=αi (first i probes all hit occupied slots). So
E[X]=∑i=0∞P(X>i)=∑i=0∞αi=1−α1.
Imagine a row of lockers and you want to drop your bag in locker #3. If #3 is full you need a rule for which locker to try next. Linear: try the very next locker (3,4,5...) — but soon a long traffic-jam of full lockers forms. Quadratic: jump 1, then 4, then 9 lockers ahead — you skip past the jam. Double: every kid gets a personal "skip-by" number from a second magic formula, so two kids almost never walk the same path. And if you remove a bag, you must leave a little "someone was here" sticky note (tombstone), or the next kid searching will think the trail ended too early.
A collision strategy where every key is stored inside the table itself; on collision you probe a sequence of slots until finding an empty one (no external lists).
General probe-sequence template?
h(k,i)=(h1(k)+f(i))modm with f(0)=0.
Linear probing offset and main flaw?
f(i)=i; suffers primary clustering (long contiguous runs that merge and grow).
Quadratic probing offset and main flaw?
f(i)=i2 (or c1i+c2i2); suffers secondary clustering (same home ⇒ same path) and may not reach a free slot unless α≤0.5 and m prime.
Double hashing formula?
h(k,i)=(h1(k)+ih2(k))modm.
Condition for double hashing to probe all slots?
h2(k) must be coprime to m (e.g. m prime, or m=2p with h2 odd).
Expected probes for an unsuccessful search?
1/(1−α).
Derive 1/(1−α).
P(X>i)=αi, so E[X]=∑i≥0αi=1/(1−α).
Expected probes for a successful search?
α1ln1−α1.
Why can't we just mark a deleted slot EMPTY?
It breaks probe chains — later keys past it become unfindable. Use a DELETED tombstone instead.
Primary vs secondary clustering?
Primary: any key hashing into a cluster extends it (linear). Secondary: only keys with the same home share a path (quadratic).
Why is double hashing the best for clustering?
Two keys must agree on bothh1 and h2 to collide on a whole path → near-uniform hashing, minimal clustering.
Max load factor open addressing allows?
α<1 strictly (can't exceed slots); practically resize around α≈0.7.
Dekho, hashing me jab do keys ek hi slot maangti hain to collision ho jaata hai. Chaining me hum us slot pe ek linked list laga dete hain, par open addressing bolta hai — "yeh seat full hai? koi baat nahi, agli khaali seat dhoondo, wahi array ke andar." Matlab saara data ek hi contiguous array me rehta hai, koi extra pointer nahi — isliye CPU cache ko bahut pasand aata hai aur fast chalta hai.
Ab "agli seat kaun si?" — yeh decide karne ke teen tareeke hain. Linear probing me seedha agle slot pe jao (+1, +1...), simple hai par primary clustering ho jaata hai — full slots ka lamba jam ban jaata hai aur woh badhta hi rehta hai. Quadratic probing me jump bada karte jao (+1, +4, +9...), isse jam se aage nikal jaate ho, par jin keys ka home same hai woh phir bhi same path follow karti hain (secondary clustering), aur table aadhe se zyada bhar gaya to khaali slot milne ki guarantee nahi (isliye m prime aur α≤0.5 rakho). Double hashing sabse best — ek doosra hash h2(k) step-size deta hai, to har key ka apna unique raasta hota hai, clustering almost khatam.
Performance ka funda: load factor α=n/m. Unsuccessful search me average probes =1−α1. Yaad rakho — α=0.9 pe 10 probes lagte hain, α=0.5 pe sirf 2! Isliye table bharne se pehle hi resize/rehash kar do. Aur ek important trap: delete karte time slot ko seedha EMPTY mat karo, warna probe chain toot jaata hai aur aage wali keys "kho" jaati hain — uski jagah tombstone (DELETED marker) lagao. Bas yeh teen formulas aur deletion ka funda pakka kar lo, exam aur interview dono me chalega.