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\dfrac{1}{2}, \dfrac{1}{4}, \dfrac{1}{8}, \dfrac{1}{16}, \dfrac{1}{32}, \dfrac{1}{32}, respectively. 

What is the average length of the Huffman code for the letters a, b, c, d, e, fa, \,b, \,c, \,d, \,e, \,f?

  1. A
    3
  2. B
    2.1875
  3. C
    2.25
  4. D
    1.9375
    Correct answer

Answer

(D) 1.9375 1.9375 1.9375

Approach

Construct the Huffman tree by repeatedly merging the two smallest probabilities until one root remains. Then read each codeword length from the tree and compute the weighted average length using the given letter probabilities.

The Huffman procedure produces code lengths 1,2,3,4,5,5 for letters $a,b,c,d,e,f$ respectively. Therefore the average Huffman code length is 1.9375, which matches option D.

Reviewed by GateIQ Editorial Team: IIT & IISc Alumni.