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: In separate chaining, the longest chain length is simply the maximum frequency of any hash value (bucket size), not the total number of collisions.
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 single bucket is 3 (at index 1). Thus, the length of the longest chain is 3.