StreakPeaked· Practice

ExamsGATETechnical

Consider a hash table with 9 slots. The hash function is h(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, 10. The maximum, minimum, and average chain lengths in the hash table, respectively, are

  1. 3, 0, and 1
  2. 3, 3, and 3
  3. 4, 0, and 1
  4. 3, 0, and 2

Correct answer: 3, 0, and 1

Solution

The maximum chain length is 3 because the keys 5, 15, and 33 all hash to the same slot, creating the longest chain. The minimum chain length is 0 since some slots remain empty after all insertions. The average chain length is 1, calculated by dividing the total number of keys by the number of non-empty slots.

Related GATE Technical questions

⚔️ Practice GATE Technical free + battle 1v1 →