Question

Suppose we are given nn keys, mm hash table slots, and two simple uniform hash functions h1h_1 and h2h_2. Further suppose our hashing scheme uses h1h_1 for the odd keys and h2h_2 for the even keys. What is the expected number of keys in a slot?

Choose one option
Official answer and solution
Official answer
B
From
Official GATE 2022 answer key

Solution

Apply indicator random variables and linearity of expectation under simple uniform hashing.

Let S1S_1 be the set of odd keys and S2S_2 be the set of even keys, with ∣S1∣=n1|S_1| = n_1 and ∣S2∣=n2|S_2| = n_2 such that n1+n2=nn_1 + n_2 = n.

Under simple uniform hashing:

  • Each key k∈S1k \in S_1 is hashed by h1h_1 into any slot j∈{1,…,m}j \in \{1, \dots, m\} with probability 1m\frac{1}{m}.
  • Each key k∈S2k \in S_2 is hashed by h2h_2 into any slot j∈{1,…,m}j \in \{1, \dots, m\} with probability 1m\frac{1}{m}.

Let XjX_j be the number of keys hashed into slot jj. Defining indicator variables Ik,j=1I_{k,j} = 1 if key kk hashes to slot jj and 00 otherwise:

E[Xj]=∑k∈S1E[Ik,j]+∑k∈S2E[Ik,j]=n1(1m)+n2(1m)=n1+n2m=nmE[X_j] = \sum_{k \in S_1} E[I_{k,j}] + \sum_{k \in S_2} E[I_{k,j}] = n_1 \left(\frac{1}{m}\right) + n_2 \left(\frac{1}{m}\right) = \frac{n_1 + n_2}{m} = \frac{n}{m}

Thus, regardless of the distribution of odd and even keys, the expected number of keys in any given slot is nm\frac{n}{m}.

Final answer

Option (B)

Common trap

Dividing by 2m2m believing that two hash functions double the effective table size or halve the expected load.

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

Source

Paper
GATE 2022 Computer Science and Information Technology (CS)
Question
16 of 65
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.