Question:medium

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 16, 2026
Show Solution

Solution and Explanation

Step 1: Understanding the Concept: 
Chaining involves storing multiple keys that map to the same hash index in a linked list (chain). The length of the chain is the number of keys at that index. 
Step 2: Key Formula or Approach: 
Calculate the index for each key using \( index = key \mod 9 \). 
Step 3: Detailed Explanation: 
Let's compute the indices: 
- \( 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 \) 
Mapping keys to indices: 
- 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

Step 4: Final Answer: 
The longest chain is at Index 1 with a length of 3. 
 

Was this answer helpful?
0