- 2078 Kartik · 10 marks
Huffman code for a sentence (Kun Mandir)
Short answer
Using letter frequencies from the phrase, Huffman coding yields entropy H = 3.5093 bits/symbol, average length L = 3.5600 bits/symbol. Efficiency η = H/L ≈ 98.6%.
Write down the Huffman algorithm clearly and find an efficient code word and efficiency that can be assigned to the symbols using the Huffman algorithm for "Kun Mandir Ma Janchhau Yattri".
Assumptions: spaces are ignored, upper and lower case letters are treated as the same symbol, and each letter is a source symbol. The sentence has 25 letters and 13 distinct symbols.
Huffman algorithm
- List symbols with their probabilities.
- Merge the two smallest probabilities into one node (sum).
- Repeat until one node remains.
- Label branches 0 and 1; read each code from the root to the leaf.
Step 1: frequencies
a=5, n=3, h=2, i=2, m=2, r=2, t=2, u=2, c=1, d=1, j=1, k=1, y=1
Step 2: build the Huffman tree
Repeatedly merge the two smallest weights (N1, N2, ... are the new nodes):
1. c(1) + d(1) = 2 -> N1
2. j(1) + k(1) = 2 -> N2
3. y(1) + h(2) = 3 -> N3
4. i(2) + m(2) = 4 -> N4
5. r(2) + t(2) = 4 -> N5
6. u(2) + N1(2) = 4 -> N6
7. N2(2) + n(3) = 5 -> N7
8. N3(3) + N4(4) = 7 -> N8
9. N5(4) + N6(4) = 8 -> N9
10. a(5) + N7(5) = 10 -> N10
11. N8(7) + N9(8) = 15 -> N11
12. N10(10) + N11(15) = 25 -> N12
The branch to the smaller-weight node is labelled 0 and to the larger 1, and the codes are read from the root downwards.
Step 3: code table
| Symbol | Count | p | Code | Length |
|---|---|---|---|---|
| a | 5 | 5/25 | 00 | 2 |
| n | 3 | 3/25 | 011 | 3 |
| h | 2 | 2/25 | 1001 | 4 |
| i | 2 | 2/25 | 1010 | 4 |
| m | 2 | 2/25 | 1011 | 4 |
| r | 2 | 2/25 | 1100 | 4 |
| t | 2 | 2/25 | 1101 | 4 |
| u | 2 | 2/25 | 1110 | 4 |
| c | 1 | 1/25 | 11110 | 5 |
| d | 1 | 1/25 | 11111 | 5 |
| j | 1 | 1/25 | 0100 | 4 |
| k | 1 | 1/25 | 0101 | 4 |
| y | 1 | 1/25 | 1000 | 4 |
Step 4: entropy, average length and efficiency
- Entropy H = −Σ p log₂ p = 3.5093 bits/symbol
- Average length L = Σ p·l = 89/25 = 3.5600 bits/symbol
- Efficiency η = H / L = 3.5093 / 3.5600 = 98.58 %
- Total bits with Huffman = 89; with fixed-length codes (4 bits/symbol) = 100, so saving = 11 bits.
(Huffman codes are not unique when weights tie, but every choice gives the same average length and efficiency.)
Answer: η ≈ 98.6 %
✓ Answer checked by Claude Sonnet 5.5
Related questions
- Huffman code for p = 0.5, 0.25, 0.125, 0.125 · 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 eight symbols (1/2 ... 1/128) · Data Communication, chapter 8
- Huffman code for a sentence (Phool ko) · Data Communication, chapter 8
- Huffman code for symbols A0 to A4 · Data Communication, chapter 8
- Source coding aim; Huffman "Kun Mandir Ma Janchhau Yatri" · Communication Systems, chapter 6
- Huffman code for symbols A to E · Multimedia System, chapter 5