GATE / CS ARCHIVE

GATE CSE 2017 SET 2 / QUESTION 50

GATE CSE 2017 Set 2 Q50

Algorithms · Greedy Algorithms · Full GATE CSE 2017 Set 2 paper

GATE 2017 Set 2, Q50 2 marks · NAT
Report issue

Greedy Algorithms

Question 50, GATE 2017: A message uses symbols P,Q,R,S,T with probabilities 0.22,0.34,0.17,0.19,0.08 respectively. For a 100-character message encoded with binary Huffman coding, what is the expected encoded length in bits?
Tap to enlarge
Answer & solution

Official answer: 225.0

Our answer: 225

1. Huffman coding repeatedly merges the two smallest current weights. Merge T and R:0.08+0.17=0.25. Next merge S and P:0.19+0.22=0.41. The remaining weights are 0.25,0.34,0.41; merge 0.25+0.34=0.59, then 0.41+0.59=1.

2. The resulting depths are 2 for P,Q,S and 3 for R,T. One valid code assignment is S=00,P=01,T=100,R=101,Q=11; swapping branch labels changes codewords but not lengths.

3. Expected bits per symbol are 2(0.22+0.34+0.19)+3(0.17+0.08)=1.5+0.75=2.25. Equivalently sum the merge weights 0.25+0.41+0.59+1=2.25. For 100 symbols the expectation is 225 bits, excluding codebook/container overhead. It is an expectation, not a guarantee for every possible 100-symbol sequence.

Original paper, page 20 · Answer key