Data Structures & AlgorithmsHardGATE CS · TCS NQT

A set of symbols has frequencies [5, 9, 12, 13, 16, 45]. Huffman coding repeatedly merges the two smallest weights, and each merge costs the sum of the two weights. What is the total merge cost over all merges?

  1. A. 234
  2. B. 100
  3. C. 238
  4. D. 224

Correct answer: D. 224

Repeatedly merge the two smallest values with a min-heap; the total cost is the sum of all intermediate merged weights, which equals the weighted external path length. Merging in sorted order as one growing block gives a much larger cost.

More Arrays, Strings, Linked Lists, Stacks, Queues and Hashing questions

Exams that ask this topic