GATE Computer ScienceVery hardGATE CS (PYQ pattern)

Ten symbols with frequencies 2, 3, 4, 5, 6, 8, 10, 15, 20, 27 (total 100) are encoded with an optimal ternary (3-ary) Huffman code, whose codewords use digits 0, 1, 2. What is the total length of the encoded message in ternary digits?

  1. A. 228
  2. B. 295
  3. C. 186
  4. D. 192

Correct answer: D. 192

A full ternary tree needs (n − 1) divisible by 2, so one dummy symbol of frequency 0 is added (11 leaves). Merging three smallest each time: (0,2,3)=5, (4,5,5)=14, (6,8,10)=24, (14,15,20)=49, (24,27,49)=100. Total = 5 + 14 + 24 + 49 + 100 = 192. Merging without the dummy gives 228; 295 is the binary Huffman length.

More Algorithms questions

Exams that ask this topic