Skip to main content

GATE CSE 2015Data Structures › Hashing & Complexity AnalysisVerified

GATE CSE 2015 PYQ: Which one of the following hash functions on integers will distribute keys most uniformly over 10 10 10…

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?

  1. A
    h(i)=i2mod 10h(i) = i^2 \text{mod } 10
  2. B
    h(i)=i3mod 10h(i) = i^3 \text{mod } 10
    Correct answer
  3. C
    h(i)=(11∗i2)mod 10h(i) = (11 \ast i^2) \text{mod } 10
  4. D
    h(i)=(12∗i2)mod 10h(i) = (12 \ast i^2) \text{mod } 10

Answer

(B) h ( i ) = i 3 mod 10 h(i) = i^3 \text{mod } 10 h ( i ) = i 3 mod 10

Approach

Because all hash functions use modulo 10, only the last digit of i matters. Compare how the last digits 0–9 map to buckets under each function. A uniform hash should map the 10 possible last digits to as many distinct buckets as possible, ideally a permutation of 0–9.

Cubing modulo 10 is a permutation of the last digits 0–9, so it spreads keys across all 10 buckets as evenly as possible. The square-based options either miss four buckets or use only a small subset of buckets.

Reviewed by GateIQ Editorial Team: IIT & IISc Alumni.