Question
A message is made up entirely of characters from the set . The table of probabilities for each of the characters is shown below:
| Character | Probability |
|---|---|
| P | 0.22 |
| Q | 0.34 |
| R | 0.17 |
| S | 0.19 |
| T | 0.08 |
| Total | 1.00 |
If a message of 100 characters over is encoded using Huffman coding, then the expected length of the encoded message in bits is
Official answer and solution
- Official answer
- 225
- From
- Official GATE 2017 answer key
Solution
Construct the Huffman tree by repeatedly merging the two least probable nodes, determine codeword lengths, and calculate expected message length.
Given character probabilities:
Apply the greedy Huffman tree algorithm:
- Combine the two lowest probabilities and :
Node with probability .
Remaining probabilities: . - Combine the two lowest probabilities and :
Node with probability .
Remaining probabilities: . - Combine the two lowest probabilities and :
Node with probability .
Remaining probabilities: . - Combine and to form the root with probability .
Determine the length of each character's codeword (its depth in the tree):
- : depth 2 (in ) bits
- : depth 2 (in ) bits
- : depth 2 (in ) bits
- : depth 3 (in inside ) bits
- : depth 3 (in inside ) bits
Compute the expected length per character ():
For a message of 100 characters:
225
Forgetting to multiply the per-character expected length (2.25 bits) by the message length of 100 characters.
The answer is the one in the official GATE answer key. The solution is this site's own explanation.
Source
- Paper
- GATE 2017 Computer Science and Information Technology (CS) Session 2
- Question
- 50 of 65, printed as CS Q.50
- Section
- Computer Science and Information Technology
Report an error in this question
GATE questions are the work of the organising institutes. This site is independent and is not affiliated with them.