edited by
5,576 views
7 7 votes

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}$$

  1. $4$
  2. $5$
  3. $6$
  4. $3$

3 Answers

Best answer
7 7 votes
Ans is 5.Because in worst case we have to probe index 8,9,0,1 and 2 as they are contiguously filled.
selected by
0 0 votes

Contiguous sequences of filled buckets:

  • Sequence 0,1 (2 buckets)
  • Sequence 3,4,6,8,9(5 buckets). 
  • Empty buckets terminate searches:

    • The empty buckets 2,5 and 7 stop the search when encountered.
  • By the worst case, I mean that if buckets 3,4,6,8,9 are sequentially filled and you are searching for a key that is not present, you will have to check all these buckets one by one before encountering an empty bucket (or cycling back to the start if no empty bucket is encountered).

    This sequential traversal would result in 5 comparisons in the worst case.

  • Another way

  • If buckets 3,4,6,8,9 are sequentially full, the worst-case number of comparisons for an unsuccessful search is 5. This is because the search will continue through the entire sequence before stopping.

Answer:
Position:
Show:

Related questions

59 59 votes
4 answers 4 answers
24.9k
24.9k views
Arjun asked Feb 12, 2020
24,901 views
Consider a double hashing scheme in which the primary hash function is $h_1(k)= k \text{ mod } 23$, and the secondary hash function is $h_2(k)=1+(k \text{ mod } 19)$. Ass...
10 10 votes
2 answers 2 answers
1.6k
1.6k views
gatecse asked Feb 23
1,572 views
Consider a hash table $P[0,1, \ldots, 10]$ that is initially empty. The hash table is maintained using open addressing with linear probing. The hash function used is $h(x...
2 2 votes
1 1 answer
412
412 views
Shubham Sharma 2 asked Jun 16, 2025
412 views
Suppose $3$ elements are hashed independently and uniformly at random one by one to slots in a hash table of size $6$ (assume that in case of a collision, the element is ...
5 5 votes
1 1 answer
980
980 views
admin asked Dec 15, 2022
980 views
A hash table contains $10$ buckets and uses linear probing to resolve collisions. The key values are intergers and the hash function used is $\text{Key}\%10.$ If we inser...