Data Structures & AlgorithmsHardGATE CS · Product-company placement

Symbols occur with frequencies 3, 4, 13, 27, 35. How many bits does an optimal (Huffman) prefix code need for the whole message, and how many would a fixed-length code need?

  1. A. 159 and 246
  2. B. 156 and 410
  3. C. 153 and 246
  4. D. 156 and 246

Correct answer: D. 156 and 246

Total Huffman bits = sum of all merge costs (repeatedly merge the two smallest) = 156. A fixed-length code needs ⌈log₂5⌉ = 3 bits per symbol: 246.

More Trees, Graphs, Recursion and Dynamic Programming questions

Exams that ask this topic