Data Structures & AlgorithmsHardProduct-company MCQ pattern

Keys 43, 46, 99, 82, 78, 23, 40, 44, 60, 34 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→60, 46, 82, 43→78→23, 99→44→34 — longest chain 2
  2. B. 60→40, 46, 82, 23→78→43, 34→44→99 — longest chain 3
  3. C. 78, 46, 82, 43, 99 — longest chain 1
  4. D. 40→60, 46, 82, 43→78→23, 99→44→34 — longest chain 3

Correct answer: D. 40→60, 46, 82, 43→78→23, 99→44→34 — longest chain 3

Each key is appended to the chain at index k mod 5 in insertion order, giving buckets [40→60, 46, 82, 43→78→23, 99→44→34], whose longest chain has 3 key(s). This differs from open addressing (linear probing), which would spread keys like [78, 46, 82, 43, 99] into single-slot buckets instead of chains.

More Trees, Graphs, Recursion and Dynamic Programming questions

Exams that ask this topic