Data Structures & AlgorithmsHardGATE CS · Product-company placement

Symbols occur with frequencies 18, 23, 24, 28, 34, 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. 435 and 486
  2. B. 417 and 486
  3. C. 417 and 972
  4. D. 399 and 486

Correct answer: B. 417 and 486

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

More Trees, Graphs, Recursion and Dynamic Programming questions

Exams that ask this topic