GATE / CS ARCHIVE

SIMILAR QUESTIONS / DATA STRUCTURES

Compute double-hash probe positions

2 questions solved the same way, newest first. Back to Data Structures

How these are solved

Evaluate (h1(k)+i*h2(k)) mod m with zero-based i; for insertions increase i until a free position after earlier keys. One prescribed probe and sequential insertion are not repeats.

2 marks · NAT
Report issue

Tracing double-hash probing positions

Hashing

Question 65, GATE 2025: An initially empty hash table has m=11 slots. h1(k)=k mod 11, h2(k)=1+(k mod 7), and probe i uses [h1(k)+i·h2(k)] mod 11, starting at i=0. Insert 63,50,25,79,67,24 in that order. In which slot does 24 end up? The formula yields a zero-based index; the official range also accepts the corresponding one-based slot number.
Tap to enlarge
Answer & solution

Official answer: 10 to 11

Our answer: 10

Step through it (8 steps)

Approach: Insert the earlier keys first, because their occupied positions determine how many probes key 24 needs.
For the first five keys the primary hash locations are 63 mod 11=8, 50 mod 11=6, 25 mod 11=3, 79 mod 11=2 and 67 mod 11=1. All differ, so each key is placed on its first probe. Occupied indices are therefore {1,2,3,6,8}.
For 24, h1=24 mod 11=2 and h2=1+(24 mod 7)=1+3=4. Probe i=0 checks index 2, occupied by 79. Probe i=1 checks (2+4) mod 11=6, occupied by 50. Probe i=2 checks (2+8) mod 11=10, which is empty, so 24 is stored there.
The derived index is 10. This is the eleventh slot if slots are described with one-based ordinal numbers. Preserve the official accepted interval 10–11, but use 10 when interpreting the given modulo formula literally. The second hash is the step size, not a replacement initial index.

Original paper, page 64 · Answer key

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