Skip to main content

GATE CSE 2007Algorithms › Greedy Method, Dynamic Programming & Algorithm Design TechniquesVerified

GATE CSE 2007 PYQ: Suppose the letters a , b , c , d , e , f a, \,b, \,c, \,d, \,e, \,f a , b , c , d , e , f have…

Suppose the letters a, b, c, d, e, fa, \,b, \,c, \,d, \,e, \,f have probabilities 12,14,18,116,132,132\frac{1}{2}, \frac{1}{4}, \frac{1}{8}, \frac{1}{16}, \frac{1}{32}, \frac{1}{32}, respectively. 

Which of the following is the Huffman code for the letter a, b, c, d, e, fa, \,b, \,c, \,d, \,e, \,f?

  1. A

    0, 10, 110, 1110, 11110, 11111

    Correct answer
  2. B

    11, 10, 011, 010, 001, 000

  3. C

    11, 10, 01, 001, 0001, 0000

  4. D

    110, 100, 010, 000, 001, 111

Answer

(A) 0 0 0 , 10 10 10 , 110 110 110 , 1110 1110 1110 , 11110 11110 11110 , 11111 11111 11111

Approach

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.