- 2075 Asoj (CS II) · 8 marks
Shannon-Fano and Huffman codes for six messages
Short answer
For probabilities 0.3,0.08,0.1,0.15,0.25,0.12, Shannon-Fano and Huffman codes both give average length 2.45 bits/message and efficiency 98.87%.
Six messages are transmitted with probabilities 0.3, 0.08, 0.1, 0.15, 0.25 and 0.12 respectively. Obtain their respective Shannon-Fano and Huffman's codes and code efficiencies.
Messages have (sum = 1). Arranged in decreasing order: 0.3, 0.25, 0.15, 0.12, 0.1, 0.08.
Entropy:
| Symbol | |||
|---|---|---|---|
| m1 | 0.3 | 1.7370 | 0.5211 |
| m2 | 0.08 | 3.6439 | 0.2915 |
| m3 | 0.1 | 3.3219 | 0.3322 |
| m4 | 0.15 | 2.7370 | 0.4105 |
| m5 | 0.25 | 2.0000 | 0.5000 |
| m6 | 0.12 | 3.0589 | 0.3671 |
| Total | 1 | 2.4224 |
Shannon–Fano code
Split into equal-probability halves: {0.3, 0.25} = 0.55 vs {0.15, 0.12, 0.1, 0.08} = 0.45; then {0.15, 0.12} = 0.27 vs {0.1, 0.08} = 0.18, and so on.
| Symbol | Step 1 | Step 2 | Step 3 | Code | ||
|---|---|---|---|---|---|---|
| m1 | 0.3 | 0 | 0 | 00 | 2 | |
| m5 | 0.25 | 0 | 1 | 01 | 2 | |
| m4 | 0.15 | 1 | 0 | 0 | 100 | 3 |
| m6 | 0.12 | 1 | 0 | 1 | 101 | 3 |
| m3 | 0.1 | 1 | 1 | 0 | 110 | 3 |
| m2 | 0.08 | 1 | 1 | 1 | 111 | 3 |
Huffman code
Reduction (sum of two lowest moved up as high as possible):
| Stage | Probabilities (descending) | Combined |
|---|---|---|
| 1 | 0.3, 0.25, 0.15, 0.12, 0.1, 0.08 | 0.1 + 0.08 = 0.18 |
| 2 | 0.3, 0.25, 0.18, 0.15, 0.12 | 0.15 + 0.12 = 0.27 |
| 3 | 0.3, 0.27, 0.25, 0.18 | 0.25 + 0.18 = 0.43 |
| 4 | 0.43, 0.3, 0.27 | 0.3 + 0.27 = 0.57 |
| 5 | 0.57, 0.43 | 0.57 + 0.43 = 1 |
| Symbol | Huffman code | ||
|---|---|---|---|
| m1 | 0.3 | 00 | 2 |
| m5 | 0.25 | 10 | 2 |
| m4 | 0.15 | 010 | 3 |
| m6 | 0.12 | 011 | 3 |
| m3 | 0.1 | 110 | 3 |
| m2 | 0.08 | 111 | 3 |
| Method | Efficiency | Redundancy | |
|---|---|---|---|
| Shannon–Fano | 2.45 | 98.87 % | 1.13 % |
| Huffman | 2.45 | 98.87 % | 1.13 % |
Answer: both codes give bits/message and efficiency 98.87 %.
✓ Answer checked by Claude Opus 5.5 (high effort)
Related questions
- Digital communication system; Shannon-Fano for six symbols · Communication Systems, chapter 6
- Types of noise; Shannon-Fano and Huffman coding efficiency · Communication Systems, chapter 6
- Coding efficiency: binary, Shannon-Fano and Huffman · Communication Systems, chapter 6
- Huffman and Shannon-Fano coding of A0–A4 · Communication Systems, chapter 6
- Importance of source coding; Shannon-Fano vs fixed length (seven symbols) · Communication Systems, chapter 6
- Importance of source coding; Shannon-Fano vs BCD (four symbols) · Communication Systems, chapter 6
- Shannon-Fano code for six symbols · Data Communication, chapter 8
- Shannon-Fano code for eight symbols · Data Communication, chapter 8
- Huffman code for six symbols (0.04, 0.1, ...) · Data Communication, chapter 8
- Huffman code for p = 0.5, 0.25, 0.125, 0.125 · Data Communication, chapter 8