Consider a hash table with 9 slots. The hash function is . The collisions are resolved by chaining. The following 9 keys are inserted in the order: . The maximum, minimum, and average chain lengths in the hash table, respectively, are
GATE CSE 2014Data Structures › Hashing & Complexity AnalysisVerified
GATE CSE 2014 PYQ: Consider a hash table with 9 9 9 slots. The hash function is h ( k ) = k m o d 9 h(k)= k \mod 9 h ( k ) = k…
- Aand 1Correct answer
- Band 3
- Cand 1
- Dand 2
Answer
(A) 3 , 0 , 3, 0, 3 , 0 , and 1 1 1
Approach
Insert each key by computing $h(k)=k \bmod 9$, place it in the corresponding hash-table slot, then count the number of keys in each slot to obtain the chain lengths. Finally, take the maximum, minimum, and average of the 9 slot lengths.
The hash table after all insertions has chain lengths 0,3,1,1,0,1,2,0,1, giving maximum 3, minimum 0, and average 1. Hence the correct option is A.
Reviewed by GateIQ Editorial Team: IIT & IISc Alumni.