Data Structures & AlgorithmsHardHCLTech · Wipro pattern

Keys 13, 28, 91, 42, 33 are inserted via linear probing (h(k) = k mod 7, probe by +1 on collision) into an initially empty table of size 7 (indices 0 to 6). What is the final table, left to right (_ = empty)?

  1. A. 13, 33, _, _, 42, 91, 28
  2. B. 28, 91, _, _, 42, 33, 13
  3. C. 28/91/42, _, _, _, _, 33, 13
  4. D. 28, 91, 42, _, _, 33, 13

Correct answer: D. 28, 91, 42, _, _, 33, 13

Each key goes to h(k) = k mod 7, and on a collision the next slot (wrapping around) is tried until an empty one is found. Simulating all insertions in order gives [28, 91, 42, _, _, 33, 13]. Using quadratic probing (+1², +2², ...) instead would give a different table, [28, 91, _, _, 42, 33, 13], since the probe sequence differs after the first collision.

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

Exams that ask this topic