GATE Computer ScienceHardGATE CSE

Twelve keys 15, 22, 5, 31, 10, 27, 12, 40, 3, 18, 20, 25 are inserted in this order into a hash table of 5 slots with separate chaining, h(k) = k mod 5, and each new key is inserted at the head of its chain. Counting one comparison per key examined, what is the average number of comparisons for a successful search over these 12 keys?

  1. A. 33/12
  2. B. 31/12
  3. C. 28/12
  4. D. 37/12

Correct answer: B. 31/12

Chains (head first): 0: 25,20,40,10,5,15; 1: 31; 2: 12,27,22; 3: 18,3; 4: . Total comparisons 31 over 12 keys, so the average is 31/12 ≈ 2.58.

More Programming and Data Structures (GATE) questions

Exams that ask this topic