Question:medium

The keys 5, 28, 19, 15, 26, 33, 12, 17, 10 are inserted into a hash table using the
hash function β„Ž(π‘˜) = π‘˜ π‘šπ‘œπ‘‘ 9. The collisions are resolved by chaining. After all
the keys are inserted, the length of the longest chain is __________. (answer in
integer)

Show Hint

Compute $k \bmod 9$ for every key and group them by bucket; keys 28, 19 and 10 all map to bucket 1, giving the longest chain with a length of 3.
Updated On: Aug 3, 2026
Show Solution

Correct Answer: 3

Solution and Explanation

Instead of listing hash values one by one, it helps to notice a pattern: since the table size is 9, keys that differ by a multiple of 9 always land in the same bucket.

Step 1: The keys 28, 19 and 10 are each exactly 9 apart from one another (\(28-19=9\), \(19-10=9\)), so all three automatically map to the same bucket, namely \(10 \bmod 9 = 1\).

Step 2: Check the remaining keys: \(5 \bmod 9 = 5\) (alone); \(15 \bmod 9 = 6\) and \(33 \bmod 9 = 6\) (\(33-15=18\), a multiple of 9, so they collide) giving bucket 6 with 2 keys; \(26 \bmod 9 = 8\) and \(17 \bmod 9 = 8\) (\(26-17=9\), so they collide) giving bucket 8 with 2 keys; and \(12 \bmod 9 = 3\), alone in its bucket.

Step 3: Tally the chain sizes: one bucket with 3 keys (bucket 1: 28, 19, 10), two buckets with 2 keys each (bucket 6: 15, 33 and bucket 8: 26, 17), and two buckets with a single key each (bucket 3: 12 and bucket 5: 5). No bucket exceeds 3 keys.

Conclusion: The longest chain, formed at bucket index 1, contains 3 keys, so the answer is 3.

Was this answer helpful?
0


Questions Asked in GATE CS exam