---
title: "Huffman code for symbols A to E"
subject: "Multimedia System"
chapter: 5
key: "semester_8/multimedia_system:huffman-numerical-abcde"
source: https://www.bctengineer.com/q/semester_8/multimedia_system/huffman-numerical-abcde
site: BCT Engineering
---

# Huffman code for symbols A to E

Multimedia System · Chapter 5: Data Compression

- Asked in: 2074 Bhadra, 5+5 marks
- Video: [Huffman coding || Easy method](https://www.youtube.com/watch?v=CKbgVHg0w1U) — Easy to Learn
- Answer checked by Claude Opus 5.5 (high effort) on 2026-10-14
- Page: https://www.bctengineer.com/q/semester_8/multimedia_system/huffman-numerical-abcde
- Whole chapter: https://www.bctengineer.com/md/semester_8/multimedia_system/chapter-5

## Question

A certain source emits symbols {A, B, C, D, E} with corresponding probabilities P(A)=0.06, P(B)=0.48, P(C)=0.02, P(D)=0.20, P(E)=0.24. Create a Huffman code tree and also derive the Huffman code for each symbol.

## Short answer

The Huffman tree merges C+A=0.08, then +D=0.28, then +E=0.52, then +B=1.00. Codes are B=0, E=10, D=111, A=1101, C=1100, giving an average length of 1.88 bits/symbol.

## Answer

Given: P(A) = 0.06, P(B) = 0.48, P(C) = 0.02, P(D) = 0.20, P(E) = 0.24 (sum = 1.00).

#### Part 1: Huffman code tree

Sort ascending: C (0.02), A (0.06), D (0.20), E (0.24), B (0.48).

| Step | Two smallest | Merged node |
|---|---|---|
| 1 | C (0.02) + A (0.06) | CA = 0.08 |
| 2 | CA (0.08) + D (0.20) | CAD = 0.28 |
| 3 | E (0.24) + CAD (0.28) | ECAD = 0.52 |
| 4 | B (0.48) + ECAD (0.52) | Root = 1.00 |

Lists after each step: (0.08, 0.20, 0.24, 0.48), then (0.24, 0.28, 0.48), then (0.48, 0.52), then (1.00).

```text
              Root(1.00)
             0/        \1
          B(.48)      ECAD(.52)
                     0/       \1
                  E(.24)     CAD(.28)
                            0/     \1
                        CA(.08)   D(.20)
                       0/    \1
                    C(.02)  A(.06)
```

Labelling: at every node the left branch is 0 and the right branch is 1.

#### Part 2: Huffman codes

Follow the path from the root to each leaf:

| Symbol | Probability | Path | Code | Length |
|---|---|---|---|---|
| B | 0.48 | 0 | 0 | 1 |
| E | 0.24 | 1, 0 | 10 | 2 |
| D | 0.20 | 1, 1, 1 | 111 | 3 |
| A | 0.06 | 1, 1, 0, 1 | 1101 | 4 |
| C | 0.02 | 1, 1, 0, 0 | 1100 | 4 |

**Check - prefix property:** none of 0, 10, 111, 1101, 1100 is a prefix of another.

**Average length** = 0.48(1) + 0.24(2) + 0.20(3) + 0.06(4) + 0.02(4) = 0.48 + 0.48 + 0.60 + 0.24 + 0.08 = **1.88 bits/symbol**.

A fixed code needs 3 bits, so Huffman saves (3 - 1.88)/3 = 37.3%. The source entropy is H = 1.823 bits, so the code is close to the theoretical minimum.

## Check yourself

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

1. For P(A)=0.06, P(B)=0.48, P(C)=0.02, P(D)=0.20, P(E)=0.24, which two nodes are merged first?
   A. C (0.02) and A (0.06), giving 0.08
   B. B (0.48) and E (0.24)
   C. A (0.06) and D (0.20)
   D. D (0.20) and E (0.24)
   Answer: A. Huffman always merges the two smallest probabilities first. (Key point: First merge)

2. Which set of codes results from the tree built in the answer?
   A. B=1, E=01, D=001, A=0001, C=0000
   B. B=0, E=10, D=111, A=1101, C=1100
   C. B=00, E=01, D=10, A=110, C=111
   D. B=0, E=10, D=110, A=1110, C=1111
   Answer: B. B (0.48) is the left branch from the root; E, D, A and C follow the tree, giving 0, 10, 111, 1101, 1100. (Key point: Resulting codes)

3. What is the average code length of this code?
   A. 2.00 bits
   B. 1.88 bits
   C. 1.23 bits
   D. 3.00 bits
   Answer: B. 0.48(1)+0.24(2)+0.20(3)+0.06(4)+0.02(4) = 1.88 bits/symbol. (Key point: Average length)

4. How does 1.88 bits/symbol compare with the source entropy of 1.823 bits and a 3-bit fixed code?
   A. Below entropy, which is impossible to beat
   B. Close to entropy and about 37% saving over 3 bits
   C. Far above entropy, with no saving over 3 bits
   D. Equal to the fixed code
   Answer: B. The code is near the theoretical minimum and saves (3 - 1.88)/3 = 37.3%. (Key point: Efficiency check)

## Related in Multimedia System

- [Huffman code tree steps with example](https://www.bctengineer.com/question.md?key=semester_8%2Fmultimedia_system%3Ahuffman-code-tree-steps) — Multimedia System, chapter 5, asked 7×
- [How Huffman code reduces file size](https://www.bctengineer.com/question.md?key=semester_8%2Fmultimedia_system%3Ahuffman-reduces-file-size) — Multimedia System, chapter 5

## Related in other subjects

- [Huffman code for seven-symbol source](https://www.bctengineer.com/question.md?key=semester_6%2Fcommunication_systems%3Ahuffman-seven-symbols) — 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
- [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
- [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
