- 2068 Bhadra · 6+2 marks
Huffman encoding of symbols A to F
Short answer
Combine smallest frequencies stepwise: B(0.08)+A(0.10)=0.18, D(0.12)+C(0.15)=0.27, (BA)+F(0.25)=0.43, (DC)+E(0.30)=0.57, merge for root. Codes: A=001, B=000, C=101, D=100, E=11, F=01. Average bits = sum(freq × length) = 2.45 bits/symbol.
Encode the symbols A, B, C, D, E and F with frequencies 0.10, 0.08, 0.15, 0.12, 0.30 and 0.25 respectively by using Huffman algorithm. Also calculate average number of bits used to encode a symbol.
Arrange the symbols by frequency: B 0.08, A 0.10, D 0.12, C 0.15, F 0.25, E 0.30. At each step join the two smallest weights; the smaller one is placed on the left (edge 0).
Construction
| Step | Two smallest | Merged weight | List after step |
|---|---|---|---|
| 1 | B 0.08 + A 0.10 | 0.18 | D 0.12, C 0.15, (BA) 0.18, F 0.25, E 0.30 |
| 2 | D 0.12 + C 0.15 | 0.27 | (BA) 0.18, F 0.25, (DC) 0.27, E 0.30 |
| 3 | (BA) 0.18 + F 0.25 | 0.43 | (DC) 0.27, E 0.30, (BAF) 0.43 |
| 4 | (DC) 0.27 + E 0.30 | 0.57 | (BAF) 0.43, (DCE) 0.57 |
| 5 | (BAF) 0.43 + (DCE) 0.57 | 1.00 | root |
Huffman tree
1.00
/ \
0.43 0.57
/ \ / \
0.18 F:0.25 0.27 E:0.30
/ \ / \
B:.08 A:.10 D:.12 C:.15
Codes (left = 0, right = 1)
| Symbol | Frequency | Code | Length | Freq × length |
|---|---|---|---|---|
| A | 0.10 | 001 | 3 | 0.30 |
| B | 0.08 | 000 | 3 | 0.24 |
| C | 0.15 | 101 | 3 | 0.45 |
| D | 0.12 | 100 | 3 | 0.36 |
| E | 0.30 | 11 | 2 | 0.60 |
| F | 0.25 | 01 | 2 | 0.50 |
Average number of bits per symbol
L = Σ (frequency × code length) = 0.30 + 0.24 + 0.45 + 0.36 + 0.60 + 0.50 = 2.45
Answer: 2.45 bits per symbol (a fixed-length code would need 3 bits). The exact codes may differ if the left/right choice is reversed, but the average length is always 2.45.
✓ Answer checked by Claude Opus 5.5 (high effort)
Related questions
- Algorithm for Huffman code · Data Structure and Algorithm, chapter 6
- AVL tree for 24, 12, 8, 15, 35, ... · Data Structure and Algorithm, chapter 6
- AVL tree for 10, 20, 30, 35, 50, ... · Data Structure and Algorithm, chapter 6
- AVL tree for 10 20 30 50 45 40 8 5 3 · Data Structure and Algorithm, chapter 6
- Huffman tree definition and example · Data Structure and Algorithm, chapter 6
- Best, average, worst case of sorts · Data Structure and Algorithm, chapter 7
- Source coding; Huffman for five symbols (0.3, 0.25, 0.2, 0.15, 0.1) · Communication Systems, chapter 6
- Symbol rate, entropy and information rate (6 symbols per 10 μs) · Communication Systems, chapter 6
- Importance of source coding; Huffman for eight symbols at 1000 symbols/s · Communication Systems, chapter 6
- Huffman code for symbols A to E (0.4, 0.3, ...) · Data Communication, chapter 8