Pigeonhole — infinite possible keys, finite m slots, so two keys must share a slot.
In separate chaining, what does each bucket store?
A linked list (or small structure) of all keys that hashed to that bucket.
Expected unsuccessful-search probes in open addressing?
1−α1.
Why must open addressing use tombstones on deletion?
An emptied slot would stop later searches early, severing the probe chain; a tombstone says "keep probing" but "free to reuse".
What is primary clustering?
Long contiguous runs of filled slots forming under linear probing, lengthening future probes.
Linear vs quadratic vs double-hashing probe function f(i)?
i vs i2 vs i⋅h2(k).
Why choose prime p=31 in a polynomial string hash?
Prime > alphabet size spreads bits; and 31x=(x≪5)−x is cheap.
When do you rehash and what happens?
When α exceeds a threshold; allocate a bigger array (≈double) and reinsert all keys.
Average search cost in chaining?
O(1+α).
Why does a simple character sum make a bad string hash?
Anagrams like "ab"/"ba" collide; order is ignored.
Open addressing's main hardware advantage over chaining?
Cache friendliness — data is contiguous, no pointer chasing.
Recall Feynman: explain it to a 12-year-old
Imagine a row of numbered lockers. Instead of searching every locker for your bag, you have a magic rule that says "your bag goes in locker number 7" just by looking at your name. Super fast! But sometimes two kids' names point to the same locker — that's a collision. Two fixes: (1) Chaining — put a little bag-rack inside locker 7 and hang both bags there. (2) Open addressing — if locker 7 is taken, just walk to the next free locker (8, 9, ...) and remember to walk the same way when you come back. If lockers get too crowded, you rent a bigger hallway and move everyone — that's rehashing.
Socho hash table ek bada array hai jisme har key ka address hum calculate karte hain, dhoondte nahi. Yeh kaam karti hai hash function — key (jaise string "banana") ko ek number me badalti hai, phir % m karke valid index nikal lete hai. Isliye average me search, insert, delete sab O(1) ho jaata hai. Lekin problem yeh hai ki do alag keys kabhi-kabhi same slot par aa jaati hain — isko collision kehte hai, aur pigeonhole principle ke wajah se yeh hona hi hona hai.
Collision handle karne ke do tareeke hai. Chaining me har bucket ke andar ek chhoti linked list hoti hai — jitni keys same slot par aayi, sab us list me ad hoti jaati hai. Open addressing me sab keys array ke andar hi rehti hai; agar slot bhara hai to agle khaali slot tak probe (chalte) karte hai — linear probing me +1,+2,+3 aage badhte ho. Yaad rakho: search ke time bhi wahi probe sequence follow karna padta hai jo insert ke time follow kiya tha.
Ek important trap: open addressing me delete karte waqt slot ko seedha khaali mat karo, warna baad ki searches beech me ruk jaayengi. Iske liye tombstone (DELETED marker) lagao. Aur load factorα=n/m ko control me rakhna zaroori hai — open addressing me unsuccessful search ka expected cost 1−α1 hota hai, yaani 90% bhara hua table me ~10 probes lagte hai. Isliye α jab limit cross kare to rehash karo: bada array banao aur sab keys dobara daalo. Yehi cheez interviews aur real systems (HashMap, dict, unordered_map) ka core hai.