Data Structures & AlgorithmsHardProduct-company placement

Symbols occur with frequencies 7, 19, 20, 25, 26, 39. 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. 350 and 408
  2. B. 343 and 816
  3. C. 343 and 408
  4. D. 336 and 408

Correct answer: C. 343 and 408

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

More Trees, Graphs, Recursion and Dynamic Programming questions

Exams that ask this topic