Data Structures & AlgorithmsHardCognizant · Capgemini pattern

Keys 15, 11, 27, 8, 12, 22, 29, 1 are inserted into a hash table of size 7 with h(k) = k mod 7 and separate chaining. What is the length of the longest chain?

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

Correct answer: A. 5

15, 8, 22, 29 and 1 all leave remainder 1 when divided by 7, so slot 1 holds a chain of 5; 11 → 4, 27 → 6, 12 → 5 are alone. Missing 1 mod 7 = 1 gives the tempting 4.

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

Exams that ask this topic