Skip to main content

Coding efficiency: binary, Shannon-Fano and Huffman

Short answer

Entropy H = 2.0087 bits/symbol. Fixed-length (3 bits) efficiency is 66.96%. Shannon-Fano and Huffman both yield average length 2.05 bits/symbol, giving 97.99% efficiency.

Compute coding efficiency of a source with symbols {A₀, A₁, A₂, A₃, A₄} with corresponding probabilities {0.4, 0.3, 0.15, 0.1, 0.05} using (i) Binary coding (ii) Shannon-Fano Coding (iii) Binary Huffman Coding

Entropy of the source:

Symbolpip_ilog⁡2(1/pi)\log_2(1/p_i)pilog⁡2(1/pi)p_i\log_2(1/p_i)
A00.41.32190.5288
A10.31.73700.5211
A20.152.73700.4105
A30.13.32190.3322
A40.054.32190.2161
Total12.0087
H=∑pilog⁡21pi=2.0087 bits/symbolH = \sum p_i\log_2\frac{1}{p_i} = 2.0087\ \text{bits/symbol}

Efficiency is η=H/Lˉ\eta = H/\bar L in each case.

(i) Binary (fixed-length) coding

Five symbols need ⌈log⁡25⌉=3\lceil\log_2 5\rceil = 3 bits each (000, 001, 010, 011, 100), so Lˉ=3\bar L = 3.

η=2.00873=66.96%\eta = \frac{2.0087}{3} = 66.96\%

(ii) Shannon–Fano coding

First split: {0.4} vs {0.3, 0.15, 0.1, 0.05} (0.4 vs 0.6; the other split 0.7 vs 0.3 is worse).

Symbolpip_iStep 1Step 2Step 3Step 4Codelil_i
A00.4001
A10.310102
A20.151101103
A30.1111011104
A40.05111111114
Lˉ=0.4(1)+0.3(2)+0.15(3)+0.1(4)+0.05(4)=2.05 bits/symbolη=2.00872.05=97.99%\begin{aligned} \bar L &= 0.4(1)+0.3(2)+0.15(3)+0.1(4)+0.05(4) = 2.05\ \text{bits/symbol} \\ \eta &= \frac{2.0087}{2.05} = 97.99\% \end{aligned}

(iii) Binary Huffman coding

Reduction (sum of two lowest moved up as high as possible):

StageProbabilities (descending)Combined
10.4, 0.3, 0.15, 0.1, 0.050.1 + 0.05 = 0.15
20.4, 0.3, 0.15, 0.150.15 + 0.15 = 0.3
30.4, 0.3, 0.30.3 + 0.3 = 0.6
40.6, 0.40.6 + 0.4 = 1
Symbolpip_iHuffman codelil_i
A00.411
A10.3012
A20.150013
A30.100004
A40.0500014
Lˉ=0.4(1)+0.3(2)+0.15(3)+0.1(4)+0.05(4)=2.05 bits/symbolη=2.00872.05=97.99%\begin{aligned} \bar L &= 0.4(1)+0.3(2)+0.15(3)+0.1(4)+0.05(4) = 2.05\ \text{bits/symbol} \\ \eta &= \frac{2.0087}{2.05} = 97.99\% \end{aligned}
CodingLˉ\bar LEfficiency
Binary (fixed)366.96 %
Shannon–Fano2.0597.99 %
Huffman2.0597.99 %

Answer: 66.96 %, 97.99 % and 97.99 % respectively.

✓ Answer checked by Claude Opus 5.5 (high effort)

All Communication Systems chapter 6 questions →