Data Structures & AlgorithmsHardInfosys · Wipro pattern

A chained hash table has 5 buckets, h(k) = k mod 5, and every new key is inserted at the HEAD of its chain. Keys 12, 7, 22, 3, 17, 2 are inserted in that order. What does bucket 2 hold, from head to tail?

  1. A. 2 → 17 → 22 → 7 → 12
  2. B. 12 → 7 → 22 → 17 → 2
  3. C. 2 → 17 → 3 → 22 → 7 → 12
  4. D. 2 → 22 → 12 → 17 → 7

Correct answer: A. 2 → 17 → 22 → 7 → 12

12, 7, 22, 17 and 2 all leave remainder 2 (3 goes to bucket 3). Head insertion reverses arrival order: the last key inserted (2) is first. '12 → … → 2' is tail insertion; the option containing 3 miscomputes 3 mod 5.

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

Exams that ask this topic