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?
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…
- A
- BCorrect answer
- C
- D
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.