Data Structures & AlgorithmsHardTCS NQT · Infosys pattern

Keys 92, 78, 40, 55, 53, 90, 42 are inserted via separate chaining (h(k) = k mod 5, new keys appended to the end of the chain) into a table of size 5 (buckets 0 to 4). What are the final bucket contents, and what is the longest chain length?

  1. A. 40, 55, 92, 78, 53 — longest chain 1
  2. B. 40→55→90, ∅, 92→42, 78→53, ∅ — longest chain 2
  3. C. 40→55→90, ∅, 92→42, 78→53, ∅ — longest chain 3
  4. D. 90→55→40, ∅, 42→92, 53→78, ∅ — longest chain 3

Correct answer: C. 40→55→90, ∅, 92→42, 78→53, ∅ — longest chain 3

Each key is appended to the chain at index k mod 5 in insertion order, giving buckets [40→55→90, ∅, 92→42, 78→53, ∅], whose longest chain has 3 key(s). This differs from open addressing (linear probing), which would spread keys like [40, 55, 92, 78, 53] into single-slot buckets instead of chains.

More Trees, Graphs, Recursion and Dynamic Programming questions

Exams that ask this topic