GATE / CS ARCHIVE

GATE CSE 2020 / QUESTION 23

GATE CSE 2020 Q23

Data Structures · Hashing · Full GATE CSE 2020 paper

GATE 2020, Q23 1 mark · NAT
Report issue

Hashing

Question 23, GATE 2020: Double hashing uses h1(k)=k mod 23, h2(k)=1+(k mod 19), and table size 23. Probe numbering starts at 0. What address is returned at probe 1 for key 90?
Tap to enlarge
Answer & solution

Official answer: 13

Worked explanation

Double hashing uses h(k,i)=(h1(k)+i·h2(k)) mod m. Since 90=3×23+21, h1=21. Since 90=4×19+14, h2=1+14=15. The requested i=1 is the second probe, because i=0 gives the initial position. Add the step once and wrap around: (21+15) mod 23=13. Further probes would be 5,20,…, but their occupancy is irrelevant because only the address of a specified probe is requested.

Derivation and answer

h1(90)=90 mod23=21 and h2(90)=1+(90 mod19)=15. Probe1 is(21+1·15)mod23=36mod23=13. Probe0 would have been 21.

Original paper, page 8 · Answer key