Which one of the following hash functions on integers will distribute keys most uniformly over buckets numbered to for ranging from to ?
View worked solution
Answer: B
Since the hash functions compute values modulo , the hash value depends only on the last digit of (i.e., ). For ranging from to , the last digits appear almost equally often. Thus, the most uniform distribution is achieved by the function that maps these digits to the buckets as uniquely as possible.
Let's evaluate the outputs for each option for :
- Option A:
The outputs are . Only buckets are used, leaving others empty. - Option B:
The outputs for are:
, , , , , , , , , .
This produces a perfect permutation of . Every bucket receives an equal number of keys, resulting in a perfectly uniform distribution. - Option C: . Same as Option A.
- Option D: .
The outputs are restricted to , which is highly non-uniform.
Therefore, Option B distributes the keys most uniformly.
Free practice · Your answers on this page are not saved.
