---
title: "Huffman code for five symbols (0.2, 0.35, ...)"
subject: "Data Communication"
chapter: 8
key: "semester_5/data_communication:huffman-five-symbols-02-035"
source: https://www.bctengineer.com/q/semester_5/data_communication/huffman-five-symbols-02-035
site: BCT Engineering
---

# Huffman code for five symbols (0.2, 0.35, ...)

Data Communication · Chapter 8: Information Theory and Coding

- Asked in: 2074 Asoj, 10 marks
- Video: [L-4.3: Huffman Coding Algorithm in Hindi with Example | Greedy Techniques(Algorithm)](https://www.youtube.com/watch?v=uDS8AkTAcIU) — Gate Smashers
- Answer checked by Claude Sonnet 5.5 on 2026-10-14
- Page: https://www.bctengineer.com/q/semester_5/data_communication/huffman-five-symbols-02-035
- Whole chapter: https://www.bctengineer.com/md/semester_5/data_communication/chapter-8

## Question

Consider a five symbol source with probability assignment as P(X1)=0.2, P(X2)=0.35, P(X3)=0.1, P(X4)=0.2, P(X5)=0.15. By using Huffman algorithm, find the source code for these symbols and determine efficiency of the code.

## Short answer

Huffman coding yields average length 2.2500 bits/symbol and efficiency 97.85%.

## Answer

#### Huffman algorithm
1. Arrange the symbols in decreasing order of probability.
2. Combine the two least probable symbols into one with the sum of their probabilities.
3. Repeat (re-sorting) until only one symbol of probability 1 remains.
4. Assign 0 and 1 to the two branches at every merge.
5. The code of a symbol is the sequence of bits read from the root back to that symbol.

Probabilities: P(X1) = 0.2, P(X2) = 0.35, P(X3) = 0.1, P(X4) = 0.2, P(X5) = 0.15 (sum = 1).

#### Merging steps
At every step the two smallest probabilities are combined (N1, N2, ... are the new nodes):

```text
1. X3(0.1) + X5(0.15) = 0.25
2. X1(0.2) + X4(0.2) = 0.4
3. N1(0.25) + X2(0.35) = 0.6
4. N2(0.4) + N3(0.6) = 1
```

#### Code table

| Symbol | p | Code | Length l | p·l |
|---|---|---|---|---|
| X2 | 0.35 | 11 | 2 | 0.7000 |
| X1 | 0.2 | 00 | 2 | 0.4000 |
| X4 | 0.2 | 01 | 2 | 0.4000 |
| X5 | 0.15 | 101 | 3 | 0.4500 |
| X3 | 0.1 | 100 | 3 | 0.3000 |

#### Entropy, average length, efficiency
- H = −Σ p log₂ p = **2.2016 bits/symbol**
- L = Σ p·l = **2.2500 bits/symbol**
- Efficiency η = H/L = 2.2016/2.2500 = **97.85 %**   (redundancy = 2.15 %)

Huffman codes are not unique when probabilities tie, but L and η are the same for every valid choice.

**Answer: L = 2.2500 bits/symbol, η = 97.85 %**

## Check yourself

The answer's key points as multiple-choice questions, with the correct option and why.

1. For probabilities 0.2, 0.35, 0.1, 0.2, 0.15, what is merged first?
   A. X1 and X4
   B. X3 (0.1) and X5 (0.15) to give 0.25
   C. X2 and X1
   D. X2 and X3
   Answer: B. The two smallest, 0.1 and 0.15, merge first. (Key point: First merge)

2. Which symbols get 3-bit codes?
   A. X1 and X4
   B. X2 only
   C. X3 and X5, the least probable
   D. All symbols
   Answer: C. X3 and X5 are the smallest and end up deepest in the tree, with codes 100 and 101. (Key point: Code lengths)

3. What is L and the efficiency?
   A. L = 2.25 bits, eta = 97.85%
   B. L = 2.0, eta = 110%
   C. L = 2.2016, eta = 100%
   D. L = 3, eta = 73%
   Answer: A. L = 0.7+0.4+0.4+0.45+0.3 = 2.25; eta = 2.2016/2.25 = 97.85%. (Key point: Efficiency)

## Related in Data Communication

- [Huffman code for eight symbols (1/2 ... 1/128)](https://www.bctengineer.com/question.md?key=semester_5%2Fdata_communication%3Ahuffman-eight-symbols) — Data Communication, chapter 8
- [Huffman code for symbols A to E (0.4, 0.3, ...)](https://www.bctengineer.com/question.md?key=semester_5%2Fdata_communication%3Ahuffman-table-abcde) — Data Communication, chapter 8
- [Huffman code for six symbols (0.04, 0.1, ...)](https://www.bctengineer.com/question.md?key=semester_5%2Fdata_communication%3Ahuffman-six-symbols-004) — Data Communication, chapter 8
- [Huffman code for p = 0.6, 0.2, 0.1, 0.05, 0.05](https://www.bctengineer.com/question.md?key=semester_5%2Fdata_communication%3Ahuffman-p06-02-01) — Data Communication, chapter 8
- [Huffman code for p = 0.5, 0.25, 0.125, 0.125](https://www.bctengineer.com/question.md?key=semester_5%2Fdata_communication%3Ahuffman-p05-025-0125) — Data Communication, chapter 8
- [Shannon-Fano code for eight symbols](https://www.bctengineer.com/question.md?key=semester_5%2Fdata_communication%3Ashannon-fano-eight-symbols) — Data Communication, chapter 8

## Related in other subjects

- [Source vs channel coding; Huffman for five symbols](https://www.bctengineer.com/question.md?key=semester_6%2Fcommunication_systems%3Asource-channel-huffman-five) — Communication Systems, chapter 6
- [Source coding; Huffman for five symbols (0.3, 0.25, 0.2, 0.15, 0.1)](https://www.bctengineer.com/question.md?key=semester_6%2Fcommunication_systems%3Asource-coding-huffman-five-s0) — Communication Systems, chapter 6
- [Huffman code for five-symbol DMS vs fixed length](https://www.bctengineer.com/question.md?key=semester_6%2Fcommunication_systems%3Ahuffman-dms-five-symbols) — Communication Systems, chapter 6
- [Huffman code for seven-symbol source](https://www.bctengineer.com/question.md?key=semester_6%2Fcommunication_systems%3Ahuffman-seven-symbols) — Communication Systems, chapter 6
