Skip to content
Official PYQ · 2015

GATE CS 2015 Set 2 Q33 — Graphs

Explain with AI

Which one of the following hash functions  on integers will distribute keys most uniformly over 1010 buckets numbered 00 to 99 for ii ranging from 00 to 20202020?

Choose one option
View worked solution

Answer: B

Since the hash functions compute values modulo 1010, the hash value h(i)h(i) depends only on the last digit of ii (i.e., i(mod10)i \pmod{10}). For ii ranging from 00 to 20202020, the last digits d∈{0,1,2,…,9}d \in \{0, 1, 2, \dots, 9\} appear almost equally often. Thus, the most uniform distribution is achieved by the function that maps these 1010 digits to the 1010 buckets as uniquely as possible.

Let's evaluate the outputs for each option for d∈{0,1,…,9}d \in \{0, 1, \dots, 9\}:

  • Option A: h(i)=i2(mod10)h(i) = i^2 \pmod{10}
    The outputs are {0,1,4,9,6,5,6,9,4,1}\{0, 1, 4, 9, 6, 5, 6, 9, 4, 1\}. Only buckets {0,1,4,5,6,9}\{0, 1, 4, 5, 6, 9\} are used, leaving others empty.
  • Option B: h(i)=i3(mod10)h(i) = i^3 \pmod{10}
    The outputs for d=0,1,2,3,4,5,6,7,8,9d = 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 are:
    03≡00^3 \equiv 0, 13≡11^3 \equiv 1, 23≡82^3 \equiv 8, 33≡73^3 \equiv 7, 43≡44^3 \equiv 4, 53≡55^3 \equiv 5, 63≡66^3 \equiv 6, 73≡37^3 \equiv 3, 83≡28^3 \equiv 2, 93≡9(mod10)9^3 \equiv 9 \pmod{10}.
    This produces a perfect permutation of {0,1,2,3,4,5,6,7,8,9}\{0, 1, 2, 3, 4, 5, 6, 7, 8, 9\}. Every bucket receives an equal number of keys, resulting in a perfectly uniform distribution.
  • Option C: h(i)=(11∗i2)(mod10)≡i2(mod10)h(i) = (11 \ast i^2) \pmod{10} \equiv i^2 \pmod{10}. Same as Option A.
  • Option D: h(i)=(12∗i2)(mod10)≡2i2(mod10)h(i) = (12 \ast i^2) \pmod{10} \equiv 2i^2 \pmod{10}.
    The outputs are restricted to {0,2,8}\{0, 2, 8\}, which is highly non-uniform.

Therefore, Option B distributes the keys most uniformly.

Free practice · Your answers on this page are not saved.

Published
Report a correction
Keep exploringMore Graphs questions