GateAI
Searching, Sorting and Hashing

GATE CSE 2022 · Q16

MCQ1 markEasy

Time

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?

Select one answerSingle correct

Pick an option to check

Solution

Step-by-step verified solution

Official answer: B) (n)/(m)

Searching, Sorting and Hashing

Let noddn_{\text{odd}} be the number of odd keys and nevenn_{\text{even}} be the number of even keys, such that:

nodd+neven=nn_{\text{odd}} + n_{\text{even}} = n

Under the Simple Uniform Hashing Assumption (SUHA):

  • Any key hashed using h1h_1 is equally likely to hash to any of the mm slots with probability 1m\frac{1}{m}.

  • Any key hashed using h2h_2 is equally likely to hash to any of the mm slots with probability 1m\frac{1}{m}.

For a specific slot jj (1≤j≤m1 \le j \le m), let the indicator random variable Ii=1I_i = 1 if key ii hashes to slot jj, and 00 otherwise. Then E[Ii]=1mE[I_i] = \frac{1}{m} for every key ii, whether it is odd or even.

The total number of keys in slot jj is Xj=∑i=1nIiX_j = \sum_{i=1}^n I_i.

By the linearity of expectation:

E[Xj]=∑i=1nE[Ii]=∑i∈oddE[Ii]+∑i∈evenE[Ii]=nodd⋅1m+neven⋅1m=nodd+nevenm=nmE[X_j] = \sum_{i=1}^n E[I_i] = \sum_{i \in \text{odd}} E[I_i] + \sum_{i \in \text{even}} E[I_i] = n_{\text{odd}} \cdot \frac{1}{m} + n_{\text{even}} \cdot \frac{1}{m} = \frac{n_{\text{odd}} + n_{\text{even}}}{m} = \frac{n}{m}

Hence, the expected number of keys in any slot is nm\frac{n}{m}.

Therefore, option B is correct.

Try the question first, then check your work.

Think the official key or this write-up is wrong?

Report error or challenge

Examiner trap

The misconception this question tests

This Searching, Sorting and Hashing previous year question is Q16 of the GATE CSE 2022 paper. Find more GATE CSE PYQs on Searching, Sorting and Hashing in Algorithms, or browse all GATE CSE PYQs.

Free diagnostic

Where do you stand for GATE?

Take the 20-minute diagnostic: the 3 topics that cost you the most marks, and a rank range. Or sit 5 related Searching, Sorting and Hashing PYQs now with no account.

One GATE CSE PYQ every morning

An official question by email at 7 AM IST, with a link to its verified solution. Unsubscribe in one click.

Searching, Sorting and Hashing in GATE CSE

Searching, Sorting and Hashing has 27 GATE CSE PYQs across 20 papers from 2012 to 2026. 9 of them are 1-mark MCQs like this one, and it is the only one in GATE CSE 2022.

How GATE tests Searching, Sorting and Hashing

More from GATE CSE 2022

Share this solution

A plain-text card for WhatsApp or Telegram study groups.

GateAI solution cardGATE CSE 2022 · Q16 · MCQ

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

Topic-wise GATE CS PYQs with verified steps

Independent practice explanation verified by the GateAI team. GATE is conducted by the IITs; question text follows the official paper.