Skip to main content

Huffman code for seven-symbol source

Short answer

Huffman codes are S0=10, S1=11, S2=001, S3=010, S4=011, S5=0000, S6=0001. Average code length equals entropy at 2.625 bits/symbol, giving 100% efficiency since all probabilities are negative powers of two.

A discrete memoryless source has an alphabet of seven symbols whose probabilities occurrence are as under.

SymbolS0S1S2S3S4S5S6
Probability0.250.250.1250.1250.1250.06250.0625

Determine the Huffman code for above source.

Huffman procedure: arrange symbols in decreasing probability; combine the two lowest probabilities into one; place the sum in the list as high as possible; repeat until one probability (1.0) is left. Then trace back, giving 0 to the upper branch and 1 to the lower branch at each combination.

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

StageProbabilities (descending)Combined
10.25, 0.25, 0.125, 0.125, 0.125, 0.0625, 0.06250.0625 + 0.0625 = 0.125
20.25, 0.25, 0.125, 0.125, 0.125, 0.1250.125 + 0.125 = 0.25
30.25, 0.25, 0.25, 0.125, 0.1250.125 + 0.125 = 0.25
40.25, 0.25, 0.25, 0.250.25 + 0.25 = 0.5
50.5, 0.25, 0.250.25 + 0.25 = 0.5
60.5, 0.50.5 + 0.5 = 1
Symbolpip_iHuffman codelil_i
S00.25102
S10.25112
S20.1250013
S30.1250103
S40.1250113
S50.062500004
S60.062500014

Entropy:

H=∑pilog⁡21pi=2(0.25)(2)+3(0.125)(3)+2(0.0625)(4)=1.0+1.125+0.5=2.625 bits/symbol\begin{aligned} H &= \sum p_i\log_2\frac{1}{p_i} = 2(0.25)(2) + 3(0.125)(3) + 2(0.0625)(4) \\ &= 1.0 + 1.125 + 0.5 = 2.625\ \text{bits/symbol} \end{aligned}

Average code length:

Lˉ=2(0.25)(2)+3(0.125)(3)+2(0.0625)(4)=2.625 bits/symbol\bar L = 2(0.25)(2) + 3(0.125)(3) + 2(0.0625)(4) = 2.625\ \text{bits/symbol}

Efficiency:

η=HLˉ=2.6252.625=100%\eta = \frac{H}{\bar L} = \frac{2.625}{2.625} = 100\%

The efficiency is 100 % because every probability is a negative power of 2 (2−2,2−3,2−42^{-2}, 2^{-3}, 2^{-4}), so each code length equals log⁡2(1/pi)\log_2(1/p_i) exactly. A fixed-length code would need 3 bits/symbol (efficiency 2.625/3=87.5%2.625/3 = 87.5\%).

Answer: S0, S1 get 2-bit codes, S2, S3, S4 get 3-bit codes and S5, S6 get 4-bit codes (as in the table); Lˉ=H=2.625\bar L = H = 2.625 bits/symbol, efficiency 100 %.

✓ Answer checked by Claude Opus 5.5 (high effort)

All Communication Systems chapter 6 questions →