---
title: "Huffman code for symbols A0 to A4"
subject: "Data Communication"
chapter: 8
key: "semester_5/data_communication:huffman-a0-a4"
source: https://www.bctengineer.com/q/semester_5/data_communication/huffman-a0-a4
site: BCT Engineering
---

# Huffman code for symbols A0 to A4

Data Communication · Chapter 8: Information Theory and Coding

- Asked in: 2075 Asoj, 10 marks
- Video: [Calculate Efficiency of Huffman Code for the symbol whose probability of occurrence by Mahesh Huddar](https://www.youtube.com/watch?v=NNAGT1I94Gg) — Mahesh Huddar
- Answer checked by Claude Sonnet 5.5 on 2026-10-14
- Page: https://www.bctengineer.com/q/semester_5/data_communication/huffman-a0-a4
- Whole chapter: https://www.bctengineer.com/md/semester_5/data_communication/chapter-8

## Question

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.

## 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%.

## Answer

**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
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.

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

```text
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 %**

## Check yourself

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

1. The given probabilities sum to 1.45. What is the fix?
   A. Treat 0.5 as a misprint for 0.05 so the sum is 1
   B. Normalise by dividing by 1.45
   C. Drop A4
   D. Treat 0.4 as 0.04
   Answer: A. Probabilities must sum to 1, and replacing 0.5 by 0.05 gives exactly 1. (Key point: Data check)

2. Which scheme is the most efficient symbol-by-symbol code?
   A. Fixed-length code
   B. Huffman code
   C. Parity code
   D. CRC
   Answer: B. Huffman coding gives the minimum average length among symbol-by-symbol prefix codes. (Key point: Efficient coding scheme)

3. What are L and efficiency?
   A. L = 2.05 bits, eta = 97.99%
   B. L = 2.32 bits, eta = 86%
   C. L = 2.0087, eta = 100%
   D. L = 1.9, eta = 105%
   Answer: A. L = 0.4+0.6+0.45+0.4+0.2 = 2.05 and eta = 2.0087/2.05 = 97.99%. (Key point: Result)

## 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 five symbols (0.2, 0.35, ...)](https://www.bctengineer.com/question.md?key=semester_5%2Fdata_communication%3Ahuffman-five-symbols-02-035) — 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
- [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

## Related in other subjects

- [Huffman and Shannon-Fano coding of A0–A4](https://www.bctengineer.com/question.md?key=semester_6%2Fcommunication_systems%3Ahuffman-sf-a0-a4-compare) — 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
- [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
- [Importance of source coding; Huffman for eight symbols at 1000 symbols/s](https://www.bctengineer.com/question.md?key=semester_6%2Fcommunication_systems%3Asource-coding-huffman-eight-1000) — Communication Systems, chapter 6
