Data Structures & AlgorithmsHardInfosys · Accenture pattern

A hash table of size 10 uses linear probing. Slots 2, 3, 4, 7 and 8 are occupied and all others are empty (no deletions have happened). An UNSUCCESSFUL search is made for a key whose hash is 2. How many slots are examined?

  1. A. 3
  2. B. 4
  3. C. 1
  4. D. 6

Correct answer: B. 4

The search walks 2, 3, 4 (all occupied, none match) and stops at the first empty slot, 5: 4 slots examined. The empty slot must be checked too – that is how the search knows the key is absent – so '3' undercounts.

More Arrays, Strings, Linked Lists, Stacks, Queues and Hashing questions

Exams that ask this topic