The GATE Grind

GATE 2026 CS (CS2) – Question 30

Algorithms · Searching, Sorting and Hashing · 1 mark · Numerical answer

The keys 5, 28, 19, 15, 26, 33, 12, 17, and 10 are inserted into a hash table using the hash function $h(k)=k \bmod 9$. Collisions are resolved by chaining. After all the keys are inserted, the length of the longest chain is __________. (answer in integer)

Practise this question in The GATE Grind →

Show answer and explanation

Correct answer: 3

Explanation

Using $h(k)=k \bmod 9$, the keys map as follows: $5\to5$, $28\to1$, $19\to1$, $15\to6$, $26\to8$, $33\to6$, $12\to3$, $17\to8$, and $10\to1$. Bucket 1 therefore contains 28, 19, and 10, giving a longest chain of length 3. Hence the answer is 3.