The keys are inserted into a hash table using the hash function . The collisions are resolved by chaining. After all the keys are inserted, the length of the longest chain is __________. <i>(answer in integer)</i>
3.00
Step-by-Step Solution
Insight: Separate chaining appends colliding keys to a linked list at the hashed index; the longest chain is simply the maximum bucket size.
Exam route: Compute for all 9 keys, tally the frequencies of each remainder, and pick the maximum frequency.
Learning route:
The hash function is .
Compute the bucket for each key:
Tallying the remainders:
- Index 0: 0 keys
- Index 1: 28, 19, 10 (3 keys)
- Index 2: 0 keys
- Index 3: 12 (1 key)
- Index 4: 0 keys
- Index 5: 5 (1 key)
- Index 6: 15, 33 (2 keys)
- Index 7: 0 keys
- Index 8: 26, 17 (2 keys)
The maximum number of keys in any bucket is 3 (at index 1).
Thus, the length of the longest chain is 3.
Tempting wrong path: A student might count the total number of collisions instead of the maximum chain length. There are 4 collisions (28 collides with 19, 10 collides with them, 33 collides with 15, 17 collides with 26), leading to an answer of 4. This breaks down because "longest chain" refers to the maximum bucket size, not the sum of collisions.
Generalization: In separate chaining, the chain length at any index is exactly the frequency of that hash value.
Verification: Re-checking , , . All correctly map to 1. No other bucket has 3 or more keys.