Data Structures & AlgorithmsHardGATE CS

A hash table of size 7 uses h(k) = k mod 7 with linear probing. A delete leaves a tombstone, an insert goes into the first empty or tombstone slot on its probe path (without checking for duplicates), and a search skips tombstones and stops at a truly empty slot. After inserting 10, 17, 24, 3, 31, then deleting 17 and 24, then inserting 45 and 38, how many slots are examined by a successful search for 38?

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

Correct answer: C. 3

Final table (None = empty, D = tombstone): [31, None, None, 10, 45, 38, 3]. Searching for 38 starts at slot 38 mod 7 = 3 and examines slots until it finds 38, which takes 3 probes; the tombstones left by deletions are probed past but do not stop the search.

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

Exams that ask this topic