ISRO Scientist/Engineer CSE 2018Algorithms › Hashing
ISRO Scientist/Engineer CSE 2018 PYQ: A hash table with 10 buckets with one slot pet per bucket is depicted here. The symbols, $S1$ to $S7$ are…
A hash table with 10 buckets with one slot pet per bucket is depicted here. The symbols, $S1$ to $S7$ are initially entered using a hashing function with linear probing. The maximum number of comparisons needed in searching an item that is not present is
$$\begin{array}{|c|c|} \hline 0 & S7 \\ \hline 1 & S1 \\ \hline 2 & \\ \hline 3 & S4 \\ \hline 4 & S2 \\ \hline 5 & \\ \hline 6 & S5 \\\hline 7 & \\ \hline 8 & S6 \\\hline 9 & S3 \\ \hline \end{array}$$
- A4
- B5Correct answer
- C6
- D3
Answer
(B) $5$
Approach
For an unsuccessful search, we must count the maximum number of probes needed to determine an item is absent. With linear probing, the worst case occurs when the probe sequence passes through the longest contiguous run of occupied slots, since the search must continue until it hits an empty slot. We identify the longest such run in the given table and count its length plus the final empty-slot check.
Reviewed by ISRO IQ Editorial Team.