Skip to main content

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…

Consider a hash table with 9 slots. The hash function is h(k)=kmod  9h(k)= k \mod 9. The collisions are resolved by chaining. The following 9 keys are inserted in the order: 5,28,19,15,20,33,12,17,105, 28, 19, 15, 20, 33, 12, 17, 10. The maximum, minimum, and average chain lengths in the hash table, respectively, are

  1. A
    3,0,3, 0, and 1
    Correct answer
  2. B
    3,3,3, 3, and 3
  3. C
    4,0,4, 0, and 1
  4. D
    3,0,3, 0, and 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.