Question:

The keys 5, 28, 19, 15, 26, 33, 12, 17, 10 are inserted into a hash table using the hash function $h(k) = k \mod 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

To solve this quickly, just count the frequency of each remainder. The highest frequency value is your answer.
Updated On: Mar 12, 2026
Hide Solution
collegedunia
Verified By Collegedunia

Solution and Explanation

Step 1: Understanding the Concept:
Chaining is a collision resolution technique where each cell of the hash table points to a linked list of records that have the same hash value. The length of a chain is the number of elements in that specific bucket.
Step 2: Key Formula or Approach:
Calculate the remainder for each key using $k \mod 9$.
Step 3: Detailed Explanation:
Let's compute the hash values for all keys:
- $5 \mod 9 = 5$
- $28 \mod 9 = 1$
- $19 \mod 9 = 1$
- $15 \mod 9 = 6$
- $26 \mod 9 = 8$
- $33 \mod 9 = 6$
- $12 \mod 9 = 3$
- $17 \mod 9 = 8$
- $10 \mod 9 = 1$
Grouping keys by their hash values:
- Index 1: $\{28, 19, 10\}$ $\rightarrow$ Length = 3
- Index 3: $\{12\}$ $\rightarrow$ Length = 1
- Index 5: $\{5\}$ $\rightarrow$ Length = 1
- Index 6: $\{15, 33\}$ $\rightarrow$ Length = 2
- Index 8: $\{26, 17\}$ $\rightarrow$ Length = 2
The maximum length observed is 3 at index 1.
Step 4: Final Answer:
The length of the longest chain is 3.
Was this answer helpful?
0
0