Skip to content
Official PYQ · 1989

GATE CS 1989 Q1-vii — Searching, Sorting, Hashing

Explain with AI

A hash table with ten buckets with one slot per bucket is shown in the following figure. The symbols S1S1 to S7S7 initially entered using a hashing function with linear probing. The maximum number of comparisons needed in searching an item that is not present is

Choose one option
View worked solution

Answer: B

In a hash table with linear probing, an unsuccessful search for a key starting at index ii continues probing consecutive slots until an empty slot is encountered.

The number of comparisons required for an unsuccessful search starting at index ii is equal to the number of consecutive occupied slots starting from ii, plus 11 (for the final comparison with the empty slot that terminates the search).

In the given hash table, the longest contiguous block of occupied slots has a length of 44 (slots 00 to 33 containing S1,S2,S3,S4S_1, S_2, S_3, S_4, followed by an empty slot at index 44).

The maximum number of comparisons occurs when a searched key hashes to index 00:

  • Probe 1: Index 0 (occupied by S1S_1)
  • Probe 2: Index 1 (occupied by S2S_2)
  • Probe 3: Index 2 (occupied by S3S_3)
  • Probe 4: Index 3 (occupied by S4S_4)
  • Probe 5: Index 4 (empty slot — search terminates)

Thus, the maximum number of comparisons needed is 5.

Free practice · Your answers on this page are not saved.

Published
Report a correction
Keep exploringMore Searching, Sorting, Hashing questions