Data Structures & AlgorithmsHardTCS NQT · Infosys

Problem: Huffman coding is applied to symbol frequencies 5, 9, 12, 13, 16, 45, always merging the two smallest weights. What is the total cost, meaning the sum of all merged weights?

  1. A. 214
  2. B. 229
  3. C. 224
  4. D. 245

Correct answer: C. 224

Merges are 5+9=14, 12+13=25, 14+16=30, 25+30=55, 45+55=100 with total 14+25+30+55+100 = 224. Merging the wrong pair first changes the sum, which is the trap.

More Coding Interview Problems questions

Exams that ask this topic