Skip to main content

Huffman code for five-symbol DMS vs fixed length

Short answer

Huffman codes: x1: 1, x2: 000, x3: 001, x4: 010, x5: 011. Average length L = 2.20 bits/symbol, entropy H = 2.1498 bits/symbol. Efficiency η = H/L = 97.72%. Fixed-length (3 bits) efficiency is 71.66%; Huffman saves 0.8 bits/symbol.

A DMS has five symbols with probability of p(x₁) = 0.4, p(x₂) = 0.19, p(x₃) = 0.16, p(x₄) = 0.15 and p(x₅) = 0.1. Construct the Huffman code for X and calculate its efficiency and compare with fixed length coding.

Huffman code construction

Arrange the symbols by probability and repeatedly combine the two smallest. In each merge, the first group gets bit 0 and the second gets bit 1.

  1. x4x_4 (0.15) + x5x_5 (0.10) → 0.25
  2. x2x_2 (0.19) + x3x_3 (0.16) → 0.35
  3. {x2,x3} (0.35) + {x4,x5} (0.25) → 0.60
  4. {x2..x5} (0.60) + x1x_1 (0.40) → 1.00
              (1.00)
           0 /      \ 1
        (0.60)      x1 (0.40)
       0/    \1
   (0.35)    (0.25)
   0/  \1    0/  \1
  x2   x3   x4   x5
Symbolpip_iCodelil_ipilip_i l_i
x1x_10.40110.40
x2x_20.1900030.57
x3x_30.1600130.48
x4x_40.1501030.45
x5x_50.1001130.30

Efficiency

Lˉ=∑pili=0.40+0.57+0.48+0.45+0.30=2.20 bits/symbolH=−∑pilog⁡2pi=0.4(1.3219)+0.19(2.3959)+0.16(2.6439)+0.15(2.7370)+0.1(3.3219)=2.1498 bits/symbolη=HLˉ=2.14982.20=0.9772=97.72%\begin{aligned} \bar L &= \sum p_i l_i = 0.40 + 0.57 + 0.48 + 0.45 + 0.30 = 2.20\ \text{bits/symbol} \\ H &= -\sum p_i \log_2 p_i \\ &= 0.4(1.3219) + 0.19(2.3959) + 0.16(2.6439) \\ &\quad + 0.15(2.7370) + 0.1(3.3219) \\ &= 2.1498\ \text{bits/symbol} \\ \eta &= \frac{H}{\bar L} = \frac{2.1498}{2.20} = 0.9772 = 97.72\% \end{aligned}

Comparison with fixed-length coding

Five symbols need ⌈log⁡25⌉=3\lceil \log_2 5 \rceil = 3 bits each:

ηfixed=H3=2.14983=0.7166=71.66%\eta_{fixed} = \frac{H}{3} = \frac{2.1498}{3} = 0.7166 = 71.66\%
CodeAvg. lengthEfficiency
Fixed length3 bits71.66%
Huffman2.20 bits97.72%

Huffman coding saves 3−2.2=0.83 - 2.2 = 0.8 bits/symbol (about 26.7%). Its efficiency is close to the entropy limit.

✓ Answer checked by Claude Opus 5.5 (high effort)

All Communication Systems chapter 6 questions →