edited by
20,969 views
41 votes
41 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 ______.
edited by

4 Answers

Best answer
47 votes
47 votes

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

so ans is 225

12 votes
12 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

Answer:

Related questions

29 votes
29 votes
8 answers
4