Data Structures & AlgorithmsVery hardProduct-company placement

Keys 55, 50, 19, 76, 39, 98, 34, 63, 58, 69 are inserted via separate chaining (h(k) = k mod 8, new keys appended to the end of the chain) into a table of size 8 (buckets 0 to 7). What are the final bucket contents, and what is the longest chain length?

  1. A. 39, 63, 50, 19, 76, 98, 34, 55 — longest chain 1
  2. B. ∅, ∅, 58→34→98→50, 19, 76, 69, ∅, 63→39→55 — longest chain 4
  3. C. ∅, ∅, 50→98→34→58, 19, 76, 69, ∅, 55→39→63 — longest chain 3
  4. D. ∅, ∅, 50→98→34→58, 19, 76, 69, ∅, 55→39→63 — longest chain 4

Correct answer: D. ∅, ∅, 50→98→34→58, 19, 76, 69, ∅, 55→39→63 — longest chain 4

Each key is appended to the chain at index k mod 8 in insertion order, giving buckets [∅, ∅, 50→98→34→58, 19, 76, 69, ∅, 55→39→63], whose longest chain has 4 key(s). This differs from open addressing (linear probing), which would spread keys like [39, 63, 50, 19, 76, 98, 34, 55] into single-slot buckets instead of chains.

More Trees, Graphs, Recursion and Dynamic Programming questions

Exams that ask this topic