Question

Consider a double hashing scheme in which the primary hash function is h1(k)=k mod 23h_1(k) = k \bmod 23, and the secondary hash function is h2(k)=1+(k mod 19)h_2(k) = 1 + (k \bmod 19). Assume that the table size is 23. Then the address returned by probe 1 in the probe sequence (assume that the probe sequence begins at probe 0) for key value k=90k = 90 is _______.

Official answer and solution
Official answer
13
From
Official GATE 2020 answer key

Solution

Evaluate the primary and secondary hash functions and determine the bucket address for probe 1.

In double hashing, the hash probe sequence for a key kk at probe index ii is given by:

hash(k,i)=(h1(k)+i⋅h2(k)) mod m\text{hash}(k, i) = (h_1(k) + i \cdot h_2(k)) \bmod m

where m=23m = 23, and the sequence starts at probe i=0i = 0.

Evaluate the primary and secondary hash values for k=90k = 90:

  • h1(90)=90 mod 23=90−3×23=90−69=21h_1(90) = 90 \bmod 23 = 90 - 3 \times 23 = 90 - 69 = 21
  • h2(90)=1+(90 mod 19)=1+(90−4×19)=1+(90−76)=1+14=15h_2(90) = 1 + (90 \bmod 19) = 1 + (90 - 4 \times 19) = 1 + (90 - 76) = 1 + 14 = 15

Evaluate the address returned by probe 1 (i=1i = 1):

hash(90,1)=(21+1×15) mod 23=36 mod 23=13\text{hash}(90, 1) = (21 + 1 \times 15) \bmod 23 = 36 \bmod 23 = 13

Therefore, the address returned by probe 1 is 13.

Final answer

13

The answer is the one in the official GATE answer key. The solution is this site's own explanation.

Source

Paper
GATE 2020 Computer Science and Information Technology (CS)
Question
33 of 65, printed as CS Q.23
Section
Computer Science and Information Technology

Report an error in this question

GATE questions are the work of the organising institutes. This site is independent and is not affiliated with them.