Core problem jo solve karni hai: agar kisi key ka home slot occupied hai, toh agla slot kaun sa try karein? Ek probe sequence un slots ki ordered list hai jo hum examine karte hain.
Primary clustering kyun hoti hai? Koi bhi key jiska home length L ke cluster ke andar kahin bhi hota hai, woh end par land karti hai, use extend karti hai. Toh size L ka cluster nayi keys ka ∝L fraction capture karta hai → bade clusters aur bade hote jaate hain. Rich-get-richer.
Expected probes ka derivation (uniform hashing assumption).
Maano ki har probe ek independent uniformly random slot par land karta hai. Probability ki slot occupied hai ≈α.
Unsuccessful search ke liye, hum tab tak probe karte rehte hain jab tak khali slot nahi milti. Probes ki sankhya X satisfy karti hai P(X>i)=αi (pehle i probes sab occupied slots pe gaye). Toh
E[X]=∑i=0∞P(X>i)=∑i=0∞αi=1−α1.
Recall Feynman: 12-saal ke bachche ko explain karo
Ek row of lockers imagine karo aur tum apna bag locker #3 mein rakhna chahte ho. Agar #3 full hai toh tumhe ek rule chahiye ki agla locker kaun sa try karein. Linear: bilkul agla locker try karo (3,4,5...) — lekin jaldi hi full lockers ka ek lamba traffic-jam ban jaata hai. Quadratic: 1, phir 4, phir 9 lockers aage jump karo — tum jam ko cross kar lete ho. Double: har bachche ko ek personal "skip-by" number milta hai ek doosre jaadu ke formula se, isliye do bachche almost kabhi ek hi path par nahi chalte. Aur agar tum bag remove karo, toh tumhe ek chota "koi yahan tha" sticky note (tombstone) chodna hoga, warna agla dhundhne wala bachcha sochega ki trail jaldi khatam ho gayi.
Ek collision strategy jahan har key table ke andar hi store hoti hai; collision par tum ek sequence of slots probe karte ho jab tak khali slot nahi milta (koi external lists nahi).
General probe-sequence template?
h(k,i)=(h1(k)+f(i))modm jisme f(0)=0.
Linear probing offset aur main flaw?
f(i)=i; primary clustering suffer karta hai (lambi contiguous runs jo merge aur grow hoti hain).
Quadratic probing offset aur main flaw?
f(i)=i2 (ya c1i+c2i2); secondary clustering suffer karta hai (same home ⇒ same path) aur free slot nahi reach kar sakta jab tak α≤0.5 aur m prime na ho.
Double hashing formula?
h(k,i)=(h1(k)+ih2(k))modm.
Double hashing ke saare slots probe karne ki condition?
h2(k), m ke saath coprime hona chahiye (e.g. m prime, ya m=2p ke saath h2 odd).
Unsuccessful search ke liye expected probes?
1/(1−α).
1/(1−α) derive karo.
P(X>i)=αi, isliye E[X]=∑i≥0αi=1/(1−α).
Successful search ke liye expected probes?
α1ln1−α1.
Deleted slot ko EMPTY kyun mark nahi kar sakte?
Yeh probe chains tod deta hai — uske baad wali keys dhundhi nahi ja sakti. Iske bajaaye DELETED tombstone use karo.
Primary vs secondary clustering?
Primary: cluster ke andar kahin bhi hash karne wali koi bhi key use extend karti hai (linear). Secondary: sirf same home wali keys ek path share karti hain (quadratic).
Double hashing clustering ke liye best kyun hai?
Do keys ko poore path par collide karne ke liye donoh1 aur h2 par agree karna padta hai → near-uniform hashing, minimal clustering.
Open addressing maximum kitna load factor allow karta hai?
α<1 strictly (slots se zyada nahi ho sakta); practically α≈0.7 ke aaspaas resize karo.