Data Structures & AlgorithmsHardHCLTech · Wipro pattern

Keys 26, 63, 80, 39, 14, 99, 18, 93, 44 are inserted via linear probing (h(k) = k mod 11, probe by +1 on collision) into an initially empty table of size 11 (indices 0 to 10). What is the final table, left to right (_ = empty)?

  1. A. 99/44, _, _, 80/14, 26, 93, 39, 18, 63, _, _
  2. B. 99, 44, _, 80, 26, 18, 39, 14, 63, 93, _
  3. C. 99, 44, _, 80, 26, 14, 39, 18, 63, 93, _
  4. D. _, 93, 63, 18, 39, 14, 26, 80, _, 44, 99

Correct answer: C. 99, 44, _, 80, 26, 14, 39, 18, 63, 93, _

Each key goes to h(k) = k mod 11, and on a collision the next slot (wrapping around) is tried until an empty one is found. Simulating all insertions in order gives [99, 44, _, 80, 26, 14, 39, 18, 63, 93, _]. Using quadratic probing (+1², +2², ...) instead would give a different table, [99, 44, _, 80, 26, 18, 39, 14, 63, 93, _], since the probe sequence differs after the first collision.

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

Exams that ask this topic