Question

Which one of the following hash functions on integers will distribute keys most uniformly over 10 buckets numbered 0 to 9 for ii ranging from 0 to 2020?

Choose one option
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 i∈{0,1,…,9}i \in \{0, 1, \dots, 9\}:

  • (A) h(i)=i2 mod 10h(i) = i^2 \bmod 10:
    Squares modulo 10 can only take values in {0,1,4,5,6,9}\{0, 1, 4, 5, 6, 9\}. Only 6 out of 10 buckets are used; buckets 2, 3, 7, 8 receive 0 keys.

  • (B) h(i)=i3 mod 10h(i) = i^3 \bmod 10:
    Computing cubes modulo 10:

    03≡0,  13≡1,  23≡8,  33≡7,  43≡4,0^3 \equiv 0,\; 1^3 \equiv 1,\; 2^3 \equiv 8,\; 3^3 \equiv 7,\; 4^3 \equiv 4,
    53≡5,  63≡6,  73≡3,  83≡2,  93≡9.5^3 \equiv 5,\; 6^3 \equiv 6,\; 7^3 \equiv 3,\; 8^3 \equiv 2,\; 9^3 \equiv 9.

    Every digit in {0,1,2,…,9}\{0, 1, 2, \dots, 9\} is hit exactly once! Thus, i3 mod 10i^3 \bmod 10 is a permutation polynomial on Z10\mathbb{Z}_{10}, distributing keys with perfect uniformity across all 10 buckets.

  • (C) h(i)=(11×i2) mod 10≡i2 mod 10h(i) = (11 \times i^2) \bmod 10 \equiv i^2 \bmod 10: identical to (A), only 6 buckets used.

  • (D) h(i)=(12×i) mod 10≡2i mod 10h(i) = (12 \times i) \bmod 10 \equiv 2i \bmod 10: produces only even values {0,2,4,6,8}\{0, 2, 4, 6, 8\}; odd buckets receive 0 keys.

Therefore, h(i)=i3 mod 10h(i) = i^3 \bmod 10 achieves the most uniform distribution (option B).

Final answer

B

Common trap

Assuming 12×i mod 1012 \times i \bmod 10 distributes keys uniformly without checking that gcd⁡(12,10)=2>1\gcd(12, 10) = 2 > 1.

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.