The GATE Grind

GATE 2015 CS (CS2) – Question 50

Algorithms · Searching, Sorting and Hashing · 2 marks · Multiple choice

Which integer hash function distributes keys i=0,…,2020 most uniformly over buckets 0,…,9?

  1. i² mod 10
  2. i³ mod 10
  3. 11i² mod 10
  4. 12i mod 10

Practise this question in The GATE Grind →

Show answer and explanation

Correct answer: (B) i³ mod 10

Explanation

Cubing permutes the decimal residue classes: cubes of zero through nine end in 0,1,8,7,4,5,6,3,2,9. Thus complete groups of ten keys contribute one per bucket. Squaring misses several residues; multiplying squares by eleven leaves them unchanged modulo ten; 12i uses only even residues. Hence B.

More Searching, Sorting and Hashing questions

All Searching, Sorting and Hashing questions →