Average chain length
Warm-up · Trace the algorithm · about 5 min
A table has 4 buckets and uses key mod 4. Insert 5, 9, 2, 6, 11, 14, then read the load factor and the chains.
Example 1
Input:
{"size":4,"keys":[5,9,2,6,11,14]}
Output:
1.5
Constraints
- 4 buckets, hash = key mod 4
- Average chain length = keys ÷ buckets, counting empty buckets
Learn the idea first: Hash tables with separate chaining, a visual lesson.
More Hash tables with separate chaining problems
- Insert a sequence Warm-up
- Implement get and put Standard
- Count collisions Standard
- Longest chain Standard
- Implement remove and iteration Challenge