Suppose the letters have probabilities , respectively.
Which of the following is the Huffman code for the letter ?
GATE CSE 2007Algorithms › Greedy Method, Dynamic Programming & Algorithm Design TechniquesVerified
0, 10, 110, 1110, 11110, 11111
11, 10, 011, 010, 001, 000
11, 10, 01, 001, 0001, 0000
110, 100, 010, 000, 001, 111
(A) 0 0 0 , 10 10 10 , 110 110 110 , 1110 1110 1110 , 11110 11110 11110 , 11111 11111 11111
Treat the probabilities as proportional frequencies by multiplying by 32: a=16, b=8, c=4, d=2, e=1, f=1. Build the Huffman tree by repeatedly merging the two smallest weights, which gives optimal code lengths a=1, b=2, c=3, d=4, e=5, f=5. Then identify which option has these lengths and is prefix-free.
The Huffman construction yields code lengths 1,2,3,4,5,5 in order of decreasing probability. Option A is the only listed code with these optimal lengths and is prefix-free, so it is the Huffman code.
Reviewed by GateIQ Editorial Team: IIT & IISc Alumni.