Bucket for keys
Warm-up · Trace the algorithm · about 5 min
A table has 7 buckets and uses key mod 7 as its bucket index. Hash the keys 15, 22, 40, 9, 29 in this order and answer each question before the step plays.
Example 1
Input:
{"size":7,"keys":[15,22,40,9,29]}
Output:
[1,1,5,2,1]
Constraints
- 7 buckets, bucket = key mod 7
- Answer with a bucket number from 0 to 6
Learn the idea first: Hash functions: from key to bucket index, a visual lesson.
More Hash functions: from key to bucket index problems
- Why mod table size Warm-up
- Predict an anagram's bucket Standard
- Bucket index of every key Standard
- Bucket histogram Standard
- Implement a polynomial string hash Challenge