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

View worked solution
Answer: B
In a hash table with linear probing, an unsuccessful search for a key starting at index continues probing consecutive slots until an empty slot is encountered.
The number of comparisons required for an unsuccessful search starting at index is equal to the number of consecutive occupied slots starting from , plus (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 (slots to containing , followed by an empty slot at index ).
The maximum number of comparisons occurs when a searched key hashes to index :
- Probe 1: Index 0 (occupied by )
- Probe 2: Index 1 (occupied by )
- Probe 3: Index 2 (occupied by )
- Probe 4: Index 3 (occupied by )
- 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.
