Skip to main content

Shannon-Fano code for six symbols

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

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.

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

StepGroupUpper (0)Lower (1)Sums
1all sixs4s6, s2, s3, s5, s10.4 / 0.6
2s6 s2 s3 s5 s1s6s2, s3, s5, s10.3 / 0.3
3s2 s3 s5 s1s2s3, s5, s10.1 / 0.2
4s3 s5 s1s3s5, s10.1 / 0.1
5s5 s1s5s10.06 / 0.04

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

Code table

SymbolpCodeLengthp·l
s40.4010.40
s60.31020.60
s20.111030.30
s30.1111040.40
s50.061111050.30
s10.041111150.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 %

✓ Answer checked by Claude Sonnet 5.5

All Data Communication chapter 8 questions →