in Algorithms edited by
14,801 views
35 votes
35 votes
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 ______.
in Algorithms edited by
by
2437 3623 5535
14.8k views

6 Comments

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

–2
–2

set2018

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 .

2
2
Why this question is not in GO book? I downloaded the latest version but did not find it.
0
0
this is in network ..vol 3
0
0
0
0
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..
0
0

Subscribe to GO Classes for GATE CSE 2022

4 Answers

37 votes
37 votes
 
Best answer

$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$

edited by
by
113 299 480

5 Comments

 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.

1
1
@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?
0
0

@

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 )

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

so ans is 225

by
20 56 84

5 Comments

 

0
0
@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.
2
2
@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.
0
0
@Rupendra @akash

Rupendra's comment should be added in the best answer.

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

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

2 Comments

Detailed and clean <3
0
0
Thanks sir , the first method is very helpful
0
0
3 votes
3 votes
Answer-225
edited by
by
5 14 22

2 Comments

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

Related questions