---
title: "Shannon-Fano code for six symbols"
subject: "Data Communication"
chapter: 8
key: "semester_5/data_communication:shannon-fano-six-symbols"
source: https://www.bctengineer.com/q/semester_5/data_communication/shannon-fano-six-symbols
site: BCT Engineering
---

# Shannon-Fano code for six symbols

Data Communication · Chapter 8: Information Theory and Coding

- Asked in: 2076 Asoj, 7+3 marks
- Video: [1 Shannon Fano Encoding (Algorithm, Procedure & Example) Explained in Digital Communication](https://www.youtube.com/watch?v=g2UlDNamG84) — Engineering Funda
- Answer checked by Claude Sonnet 5.5 on 2026-10-14
- Page: https://www.bctengineer.com/q/semester_5/data_communication/shannon-fano-six-symbols
- Whole chapter: https://www.bctengineer.com/md/semester_5/data_communication/chapter-8

## Question

Design a Binary Shannon-Fano code with a six symbol source with probability assignment as P(s1)=0.04, P(s2)=0.1, P(s3)=0.1, P(s4)=0.4, P(s5)=0.06, P(s6)=0.3. Test its transmission efficiency.

## Short answer

Sorted probabilities: s4=0.4, s6=0.3, s2=0.1, s3=0.1, s5=0.06, s1=0.04. Shannon-Fano codes: s4=0, s6=10, s2=110, s3=1110, s5=11110, s1=11111. Average length L=2.2 bits/symbol, entropy H=2.1435, efficiency 97.4%.

## Answer

**Shannon-Fano procedure:** arrange symbols in decreasing probability, split the list into two groups whose total probabilities are as nearly equal as possible, give 0 to the upper group and 1 to the lower, and repeat inside each group until every group has one symbol.

#### Sorted symbols
s4 = 0.4, s6 = 0.3, s2 = 0.1, s3 = 0.1, s5 = 0.06, s1 = 0.04

#### Partitioning
| Step | Group | Upper (0) | Lower (1) | Sums |
|---|---|---|---|---|
| 1 | all six | s4 | s6, s2, s3, s5, s1 | 0.4 / 0.6 |
| 2 | s6 s2 s3 s5 s1 | s6 | s2, s3, s5, s1 | 0.3 / 0.3 |
| 3 | s2 s3 s5 s1 | s2 | s3, s5, s1 | 0.1 / 0.2 |
| 4 | s3 s5 s1 | s3 | s5, s1 | 0.1 / 0.1 |
| 5 | s5 s1 | s5 | s1 | 0.06 / 0.04 |

(In step 3 the split 0.2 | 0.1 is equally good; either gives the same average length.)

#### Code table
| Symbol | p | Code | Length | p·l |
|---|---|---|---|---|
| s4 | 0.4 | 0 | 1 | 0.40 |
| s6 | 0.3 | 10 | 2 | 0.60 |
| s2 | 0.1 | 110 | 3 | 0.30 |
| s3 | 0.1 | 1110 | 4 | 0.40 |
| s5 | 0.06 | 11110 | 5 | 0.30 |
| s1 | 0.04 | 11111 | 5 | 0.20 |

#### Transmission efficiency
- H = −Σ p log₂ p = **2.1435 bits/symbol**
- L = Σ p·l = 0.40 + 0.60 + 0.30 + 0.40 + 0.30 + 0.20 = **2.20 bits/symbol**
- η = H / L = 2.1435 / 2.20 = **97.43 %**

**Answer: L = 2.2 bits/symbol, η ≈ 97.4 %**

## Check yourself

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

1. How does Shannon-Fano form codes?
   A. Merges the two smallest probabilities
   B. Sorts by decreasing probability, splits into groups of nearly equal total probability, assigns 0/1 and repeats
   C. Assigns equal-length codes
   D. Uses polynomial division
   Answer: B. Symbols are sorted, repeatedly split into two nearly equal-probability groups, and labelled 0 and 1. (Key point: Shannon-Fano procedure)

2. For the sorted list 0.4, 0.3, 0.1, 0.1, 0.06, 0.04, what is the first split?
   A. s4 alone (0.4) versus the other five (0.6)
   B. s4 and s6 (0.7) versus the rest (0.3)
   C. Three and three symbols
   D. s1 versus the rest
   Answer: A. 0.4 / 0.6 is the closest to equal split, so s4 gets code 0. (Key point: First split)

3. With L = 2.20 and H = 2.1435, what is the efficiency?
   A. 102.6%
   B. 97.4%
   C. 85%
   D. 91.2%
   Answer: B. eta = H / L = 2.1435 / 2.20 = 97.43%. (Key point: Average length and efficiency)

## Related in Data Communication

- [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
- [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
- [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

## 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
- [Digital communication system; Shannon-Fano for six symbols](https://www.bctengineer.com/question.md?key=semester_6%2Fcommunication_systems%3Adcs-block-shannon-fano-six) — Communication Systems, chapter 6
- [Importance of source coding; Shannon-Fano vs fixed length (seven symbols)](https://www.bctengineer.com/question.md?key=semester_6%2Fcommunication_systems%3Asource-coding-sf-fixed-seven) — Communication Systems, chapter 6
- [Importance of source coding; Shannon-Fano vs BCD (four symbols)](https://www.bctengineer.com/question.md?key=semester_6%2Fcommunication_systems%3Asource-coding-sf-bcd-four) — Communication Systems, chapter 6
