14,801 views
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 \textbf{Character} & \textbf{Probability } \\\hline \text{P} & \text{0.22} \\ \text{Q} & \text{0.34} \\ \text{R} & \text{0.17} \\ \text{S} & \text{0.19} \\ \text{T} & \text{0.08} \\ \hline\text{Total} & \text{1.00} \\\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 ______.

@Bikram sir whts wrong with this m just multiplying 100 .

Your Tree is Not correct ..

After 25 become root node ..there nodes are at that point --> 25, 19, 22, 34 and 100 .

Rearrange them in increasing order, it become 19, 22, 25, 34 , 100 .

so 19 and 22 make another sub tree . 25 and 34 make another sub tree ....

hope you get where you did mistake, you forget to rearrange them once again.. after each subtree make we need to rearrange each avaailable nodes .

this is in network ..vol 3

note the difference :)

ROOT node should be of 100 because sum of all character i.e P,Q,R,S,T is 100 and it totally wrong that you r getting 200..

### Subscribe to GO Classes for GATE CSE 2022

$X = \{ P, Q, R, S, T\}$

$∴ \text{Expected length of an encoded character}$
$\qquad \qquad= (0.22 \times 2) + (0.34 \times 2) + (0.17 \times 3) + (0.19 \times 2) + (0.08 \times 3) \hspace{0.1cm} \text{ bits }$
$\qquad \qquad= 0.44 + 0.68 + 0.51+ 0.38 + 0.24 \hspace{0.1cm} \text{ bits}$
$\qquad \qquad= 2.25 \hspace{0.1cm} \text{ bits }$

$\therefore \text{Expected length of a encoded message of$100$characters in bits} = 100 \times 2.25 = 225$

by
113 299 480

the expected length here does not mean the avg no of bits required to encode 1 character, it is total bits required to encode 100 characters.

@amitqy I think you're right, but generally expected means average. and when a question is NAT, it's difficult to guess that what do they mean?

it's very silly i think, how avg length of 100 character would be 2.25, if the characters are distinct. For one character you need at least 1 character to encode, isn't it. Some character vary by their prefix so it always be > 100. And if they ask avg length required by per character then this is a different context ,

hence it would be (weighted external path length / total frequency of each character )

Thank you sir
Your point important most of us make this mistake

so ans is 225

by
20 56 84

@loyal

I understood your tree solution .

Please help me in understanding what is difference between average length and average lengthy per character and how do we get to know in question we have to find which one avg lenght or avg length per character.
@mayank I also have the same doubt if the expected length is asked then answer should be 225/100 = 2.25, expected means average value.
@Rupendra @akash

As it is the mistake done by 90% people including me.

To create the Huffman tree, always increase the nodes in ascending order, and merge the first two nodes.

## Step 1)

Given: $\begin{bmatrix} P & Q &R &S &T \\ 0.22 &0.34 &0.17 &0.19 &0.08 \end{bmatrix}$ → $\begin{bmatrix} T & R &S &P &Q \\ 0.08 &0.17 &0.19 &0.22 &0.34 \end{bmatrix}$ → $\begin{bmatrix} TR &S &P &Q \\ 0.25 &0.19 &0.22 &0.34 \end{bmatrix}$

## Step 2)

$\begin{bmatrix} TR &S &P &Q \\ 0.25 &0.19 &0.22 &0.34 \end{bmatrix}$ → $\begin{bmatrix} S &P&TR &Q \\ 0.19 &0.22 &0.25 &0.34 \end{bmatrix}$ → $\begin{bmatrix} SP&TR &Q \\ 0.41 &0.25 &0.34 \end{bmatrix}$

## Step 3)

$\begin{bmatrix} SP&TR &Q \\ 0.41 &0.25 &0.34 \end{bmatrix}$ → $\begin{bmatrix} TR&Q &SP \\ 0.25 &0.34 &0.41 \end{bmatrix}$ → $\begin{bmatrix} TRQ &SP \\ 0.59 &0.41 \end{bmatrix}$

## Step 4)

Finally merge these two.

Hence, the Huffman Tree would look like this:-

$(0.22*2)+(0.34*2)+(0.19*2)+(0.17*3)+(0.08*3)=2.25$

Length  2.25 per character. Given, there are 100 characters in the message, so,

$2.25*100=225$

225

by
4 8 39

Detailed and clean <3
Thanks sir , the first method is very helpful
by
5 14 22

Yes!
225 is right ans as they have asked for expected length for endcoded msg and msg conatins 100 char.