Data Structures & AlgorithmsHardProduct-company placement

Keys 30, 11, 59, 70, 43, 35 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. ∅, ∅, ∅, 35→43→59→11, ∅, ∅, 70→30, ∅ — longest chain 4
  2. B. 35, ∅, ∅, 11, 59, 43, 30, 70 — longest chain 1
  3. C. ∅, ∅, ∅, 11→59→43→35, ∅, ∅, 30→70, ∅ — longest chain 4
  4. D. ∅, ∅, ∅, 11→59→43→35, ∅, ∅, 30→70, ∅ — longest chain 3

Correct answer: C. ∅, ∅, ∅, 11→59→43→35, ∅, ∅, 30→70, ∅ — longest chain 4

Each key is appended to the chain at index k mod 8 in insertion order, giving buckets [∅, ∅, ∅, 11→59→43→35, ∅, ∅, 30→70, ∅], whose longest chain has 4 key(s). This differs from open addressing (linear probing), which would spread keys like [35, ∅, ∅, 11, 59, 43, 30, 70] into single-slot buckets instead of chains.

More Trees, Graphs, Recursion and Dynamic Programming questions

Exams that ask this topic