Skip to content

ISRO Scientist/Engineer CSE 2015Algorithms › Hashing

ISRO Scientist/Engineer CSE 2015 PYQ: A hash table with ten buckets with one slot per bucket is shown in the following figure. The symbols $S1$ to…

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

  1. A
    4
  2. B
    5
    Correct answer
  3. C
    6
  4. D
    3

Answer

(B) $5$

Approach

The table is circular, so bucket 9 and bucket 0 are adjacent. Reading the figure: buckets 0,1 = S7,S1; 3,4 = S4,S2; 6 = S5; 8,9 = S6,S3. The occupied runs are {8,9,0,1} (length 4), {3,4} (length 2), and {6} (length 1). For an unsuccessful search with linear probing, the maximum number of comparisons equals the longest contiguous occupied run plus one probe to hit an empty bucket: 4 + 1 = 5. Hence option B.

Reviewed by ISRO IQ Editorial Team.