Insert a sequence
Warm-up · Trace the algorithm · about 5 min
A table has 5 buckets and uses key mod 5 as its hash. New keys join the end of their chain. Insert 12, 7, 3, 22, 9 in this order and answer each question before the step plays.
Example 1
Input:
{"size":5,"keys":[12,7,3,22,9]}
Output:
[[],[],[12,7,22],[3],[9]]
Constraints
- 5 buckets, hash = key mod 5
- A key joins the end of its chain
Learn the idea first: Hash tables with separate chaining, a visual lesson.
More Hash tables with separate chaining problems
- Average chain length Warm-up
- Implement get and put Standard
- Count collisions Standard
- Longest chain Standard
- Implement remove and iteration Challenge