- 2075 Asoj · 10 marks
Huffman code for symbols A0 to A4
Short answer
Using Huffman coding with corrected probability 0.05 for A4, the average code length is 2.0500 bits/symbol and efficiency is 97.99%.
The source of information symbols {A0, A1, A2, A3 and A4} have corresponding probabilities {0.4, 0.3, 0.15, 0.1 and 0.5}. Encode the source symbols using the most efficient coding scheme and calculate the corresponding efficiency.
Note on the data: the printed probabilities {0.4, 0.3, 0.15, 0.1, 0.5} add up to 1.45, which is impossible. The last value is evidently a misprint for 0.05, since 0.4 + 0.3 + 0.15 + 0.1 + 0.05 = 1. The answer below uses p(A4) = 0.05.
The most efficient symbol-by-symbol code is the Huffman code.
Huffman algorithm
- Arrange the symbols in decreasing order of probability.
- Combine the two least probable symbols into one with the sum of their probabilities.
- Repeat (re-sorting) until only one symbol of probability 1 remains.
- Assign 0 and 1 to the two branches at every merge.
- The code of a symbol is the sequence of bits read from the root back to that symbol.
Merging steps
At every step the two smallest probabilities are combined (N1, N2, ... are the new nodes):
1. A4(0.05) + A3(0.1) = 0.15
2. A2(0.15) + N1(0.15) = 0.3
3. A1(0.3) + N2(0.3) = 0.6
4. A0(0.4) + N3(0.6) = 1
Code table
| Symbol | p | Code | Length l | p·l |
|---|---|---|---|---|
| A0 | 0.4 | 0 | 1 | 0.4000 |
| A1 | 0.3 | 10 | 2 | 0.6000 |
| A2 | 0.15 | 110 | 3 | 0.4500 |
| A3 | 0.1 | 1111 | 4 | 0.4000 |
| A4 | 0.05 | 1110 | 4 | 0.2000 |
Entropy, average length, efficiency
- H = −Σ p log₂ p = 2.0087 bits/symbol
- L = Σ p·l = 2.0500 bits/symbol
- Efficiency η = H/L = 2.0087/2.0500 = 97.99 % (redundancy = 2.01 %)
Huffman codes are not unique when probabilities tie, but L and η are the same for every valid choice.
Answer: L = 2.0500 bits/symbol, η = 97.99 %
✓ Answer checked by Claude Sonnet 5.5
Related questions
- Huffman code for eight symbols (1/2 ... 1/128) · Data Communication, chapter 8
- Huffman code for symbols A to E (0.4, 0.3, ...) · Data Communication, chapter 8
- Huffman code for five symbols (0.2, 0.35, ...) · Data Communication, chapter 8
- Huffman code for p = 0.5, 0.25, 0.125, 0.125 · Data Communication, chapter 8
- Huffman code for six symbols (0.04, 0.1, ...) · Data Communication, chapter 8
- Huffman code for p = 0.6, 0.2, 0.1, 0.05, 0.05 · Data Communication, chapter 8
- Huffman and Shannon-Fano coding of A0–A4 · Communication Systems, chapter 6
- Source coding; Huffman for five symbols (0.3, 0.25, 0.2, 0.15, 0.1) · Communication Systems, chapter 6
- Source vs channel coding; Huffman for five symbols · Communication Systems, chapter 6
- Importance of source coding; Huffman for eight symbols at 1000 symbols/s · Communication Systems, chapter 6