Answer: 225
To find the expected length of the encoded message, we first construct the optimal prefix-free binary tree using Huffman Coding.
Step 1: List the characters and their probabilities
Arrange the characters in ascending order of their probabilities:
- T:0.08
- R:0.17
- S:0.19
- P:0.22
- Q:0.34
Step 2: Construct the Huffman Tree
- Combine the two smallest probabilities: T(0.08) and R(0.17).
- New internal node (TR)=0.08+0.17=0.25.
- Remaining set: S(0.19),P(0.22),(TR)(0.25),Q(0.34).
- Combine the next two smallest: S(0.19) and P(0.22).
- New internal node (SP)=0.19+0.22=0.41.
- Remaining set: (TR)(0.25),Q(0.34),(SP)(0.41).
- Combine the next two smallest: (TR)(0.25) and Q(0.34).
- New internal node (TRQ)=0.25+0.34=0.59.
- Remaining set: (SP)(0.41),(TRQ)(0.59).
- Combine the final two nodes: (SP)(0.41) and (TRQ)(0.59).
- Root node =0.41+0.59=1.00.
Step 3: Determine the Code Lengths
By tracing the paths from the root to each leaf node, we find the length (number of bits) for each character:
- P (from root → SP → P): 2 bits
- Q (from root → TRQ → Q): 2 bits
- R (from root → TRQ → TR → R): 3 bits
- S (from root → SP → S): 2 bits
- T (from root → TRQ → TR → T): 3 bits
Step 4: Calculate the Expected Length
The expected length of a single character (L) is given by:
L=∑(Probability of character×Code length of character)
L=(0.22×2)+(0.34×2)+(0.17×3)+(0.19×2)+(0.08×3)
L=0.44+0.68+0.51+0.38+0.24=2.25 bits/character
For a message containing 100 characters, the expected length of the entire encoded message is:
Expected Length=100×2.25=225 bits