GATE / CS ARCHIVE

GATE CSE 2015 SET 2 / QUESTION 50

GATE CSE 2015 Set 2 Q50

Data Structures · Hashing · Full GATE CSE 2015 Set 2 paper

GATE 2015 Set 2, Q50 2 marks · MCQ
Report issue

Hashing

Question 50, GATE 2015: Which hash best distributes integers i=0…2020 over buckets 0…9? A i²mod 10; B i³mod 10; C11i²mod 10; D12 imod 10.
Tap to enlarge
Your answer
Answer & solution

Official answer: B

Cubing permutes decimal residues: 0, 1, 8, 7, 4, 5, 6, 3, 2, 9. Therefore each block of 10 consecutive keys places one in each bucket. Among 2021 keys bucket 0 gets 203 and every other bucket 202, optimally balanced. Squares use only six residues, 11i² is identical modulo 10, and 12i only reaches even buckets. Thus B.

Only the last decimal digit matters modulo 10. Cubes of residues 0 through 9 give 0, 1, 8, 7, 4, 5, 6, 3, 2, 9, which is a permutation. Each full ten-key block therefore hits every bucket once. The 2021 keys consist of 202 full blocks plus one extra key 0 mod 10, giving counts 203, 202, …, 202, as balanced as possible. Squaring collapses residues, 11i²has the same residues as i², and 12i≡2i can only reach even buckets.

Original paper, page 44 · Answer key