IAE Academy

GATE 2024 DA Q.21: solution and answer

GATE 2024 · DAQ.21 · 1 mark · MCQ

Consider performing uniform hashing on an open address hash table with load factor , where elements are stored in the table with slots. The expected number of probes in an unsuccessful search is at most .

Inserting an element in this hash table requires at most ______ probes, on average.

  1. (A)

  2. (B)

  3. (C)

  4. (D)

See the question in the paper

Answer and solution

ANSWER

Inserting an element needs at most probes on average, which is option (B).

Official answer: BSource: Official answer key, GATE 2024 DA (IISc Bengaluru)

  1. In open addressing, to insert a key you follow its probe sequence, examining one slot after another, until you reach an empty slot, and then place the key there.

  2. This is exactly the work of an unsuccessful search: that search also follows the probe sequence over occupied slots and stops at the first empty one. So the number of probes for an insertion has the same distribution as for an unsuccessful search; the only extra work is the single write into the empty slot, which is not a probe.

  3. The question states that the expected number of probes in an unsuccessful search is at most . Hence inserting an element needs at most probes on average.

  4. Check by derivation. Let be the number of probes. Under uniform hashing, the probability that the first probes all land on occupied slots is , because when . Therefore .

  5. Check the other options. (D) for every , but at least one probe is always needed, so it cannot be an average. (A) equals at and is below for , again less than the one probe an insertion always needs. (C) stays below , yet the true expected number of probes, , grows without limit as (for large ), so cannot be an upper bound.

  6. Hence the answer is option (B), .

KEY IDEA

In open addressing, an insertion probes exactly as an unsuccessful search does, until the first empty slot, so it has the same bound .

WATCH OUT FOR

Picking (option A) by mixing up the insertion cost with the successful-search cost, which is about . An insertion always needs at least one probe and its cost blows up as .

From the GATE 2024 DA paper. Every question of this paper · Download the full paper · All 18 Sorting & hashing questions, with notes

More Sorting & hashing questions