Data Structures & AlgorithmsVery hardGATE CS · ICPC regional · Product Company SDE

Keys 18, 24, 4, 33, 84, 49, 74, 69, 8, 79 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. 24→8, 33→49, 18→74, ∅, 4→84, 69, ∅, 79 — longest chain 1
  2. B. 8→24, 49→33, 74→18, ∅, 84→4, 69, ∅, 79 — longest chain 2
  3. C. 24, 33, 18, 49, 4, 84, 74, 69 — longest chain 1
  4. D. 24→8, 33→49, 18→74, ∅, 4→84, 69, ∅, 79 — longest chain 2

Correct answer: D. 24→8, 33→49, 18→74, ∅, 4→84, 69, ∅, 79 — longest chain 2

Each key is appended to the chain at index k mod 8 in insertion order, giving buckets [24→8, 33→49, 18→74, ∅, 4→84, 69, ∅, 79], whose longest chain has 2 key(s). This differs from open addressing (linear probing), which would spread keys like [24, 33, 18, 49, 4, 84, 74, 69] into single-slot buckets instead of chains.

More Trees, Graphs, Recursion and Dynamic Programming questions

Exams that ask this topic