Data Structures & AlgorithmsVery hardTCS NQT · Infosys pattern

Keys 56, 48, 53, 36, 81, 29, 64 are inserted via separate chaining (h(k) = k mod 7, new keys appended to the end of the chain) into a table of size 7 (buckets 0 to 6). What are the final bucket contents, and what is the longest chain length?

  1. A. 56, 64→29→36, ∅, ∅, 81→53, ∅, 48 — longest chain 3
  2. B. 56, 36→29→64, ∅, ∅, 53→81, ∅, 48 — longest chain 3
  3. C. 56, 36→29→64, ∅, ∅, 53→81, ∅, 48 — longest chain 2
  4. D. 56, 36, 29, 64, 53, 81, 48 — longest chain 1

Correct answer: B. 56, 36→29→64, ∅, ∅, 53→81, ∅, 48 — longest chain 3

Each key is appended to the chain at index k mod 7 in insertion order, giving buckets [56, 36→29→64, ∅, ∅, 53→81, ∅, 48], whose longest chain has 3 key(s). This differs from open addressing (linear probing), which would spread keys like [56, 36, 29, 64, 53, 81, 48] into single-slot buckets instead of chains.

More Trees, Graphs, Recursion and Dynamic Programming questions

Exams that ask this topic