GATE / CS ARCHIVE

GATE CSE 2026 SET 2 / QUESTION 30

Longest chain after hashing

Data Structures · Hashing · Full GATE CSE 2026 Set 2 paper

GATE 2026 Set 2, Q30 1 mark · NAT
Report issue

Hashing

Question 30, GATE 2026: Insert keys 5,28,19,15,26,33,12,17,10 into a table with h(k)=k mod 9, resolving collisions by chaining. Find the longest chain length.
Tap to enlarge
Answer & solution

Official answer: 3

Step through it (11 steps)

Givens and goal

Insert keys 5,28,19,15,26,33,12,17,10 into a table with h(k)=k mod 9, resolving collisions by chaining. Find the longest chain length.

Approach

Group all keys by their remainder rather than by insertion adjacency.

Step-by-step solution

1. The nine remainders in order are 5,1,1,6,8,6,3,8,1. For example 28=3×9+1, 33=3×9+6, and 17=1×9+8.
2. Bucket 1 receives 28,19,10; bucket 3 receives 12; bucket 5 receives 5; bucket 6 receives 15,33; bucket 8 receives 26,17. Buckets 0,2,4,7 remain empty.
3. The nonempty chain lengths are therefore 3,1,1,2,2, summing to 9 as a consistency check with the number of inserted keys.
4. The maximum is 3. Whether chaining inserts at the head or tail changes order inside a bucket but not its length. Do not apply linear probing: the problem explicitly stores collisions in chains.

Original paper, page 22 · Answer key