Question
Which one of the following hash functions on integers will distribute keys most uniformly over 10 buckets numbered 0 to 9 for ranging from 0 to 2020?
Official answer and solution
- Official answer
- B
- From
- Official GATE 2015 answer key
Solution
Evaluate the distribution of residues modulo 10 generated by each candidate hash function.
We evaluate each function for :
-
(A) :
Squares modulo 10 can only take values in . Only 6 out of 10 buckets are used; buckets 2, 3, 7, 8 receive 0 keys. -
(B) :
Computing cubes modulo 10:Every digit in is hit exactly once! Thus, is a permutation polynomial on , distributing keys with perfect uniformity across all 10 buckets.
-
(C) : identical to (A), only 6 buckets used.
-
(D) : produces only even values ; odd buckets receive 0 keys.
Therefore, achieves the most uniform distribution (option B).
B
Assuming distributes keys uniformly without checking that .
The answer is the one in the official GATE answer key. The solution is this site's own explanation.
Source
- Paper
- GATE 2015 Computer Science and Information Technology (CS) Session 2
- Question
- 43 of 65, printed as CS Q.33
- Section
- Computer Science and Information Technology
Report an error in this question
GATE questions are the work of the organising institutes. This site is independent and is not affiliated with them.