GATE CS 2017 · Set-2 · Asymptotic Analysis & Recurrences

NAT · 2 marks · Problem PROG-DIVC-0092

A message is made up entirely of characters from the set \(X=\{P,Q,R,S,T\}\). The table of probabilities for each of the characters is shown below:\[\begin{array}{|c|c|}\hline \text{Character} & \text{Probability}\\ \hline P & 0.22\\ Q & 0.34\\ R & 0.17\\ S & 0.19\\ T & 0.08\\ \hline \end{array}\]If a message of 100 characters over \(X\) is encoded using Huffman coding, then the expected length of the encoded message in bits is

Numerical answer (NAT).

Solve it on GATE DA practice →More Searching & Sorting Algorithms problems

Show the worked solution\[\boxed{\text{Huffman: repeatedly merge the two smallest probabilities}}\]\(T+R=0.08+0.17=0.25\); \(S+P=0.19+0.22=0.41\); \(0.25+Q=0.25+0.34=0.59\); \(0.41+0.59=1\).Code lengths: \(P,Q,S\): 2 bits; \(R,T\): 3 bits.\[\bar L=2(0.22+0.34+0.19)+3(0.17+0.08)=1.50+0.75=2.25\ \text{bits/character}.\]For 100 characters: \(100\times2.25=225\) bits.Answer: 225

GATE DA practice: past exam problems by chapter, with worked solutions · gatedaprep.com