Skip to main content

Variable length coding; entropy and fixed code efficiency

Short answer

Variable-length coding assigns shorter codewords to more frequent symbols, reducing average length and approaching entropy. For example, four symbols 0.5,0.25,0.125,0.125 achieve 100% efficiency vs 87.5% fixed. For given probabilities, entropy is 2.3282 bits/symbol; fixed-length code has maximum efficiency 77.61%.

Write down the significance of variable length coding with relevant example. A fixed length source encoder generates six symbols with probabilities {0.2, 0.15, 0.25, 0.05, 0.3, 0.05} and encoded by unique code word. Find entropy and maximum code efficiency.

Significance of variable length coding

In variable-length coding, frequent symbols get short code words and rare symbols get long code words. Its significance:

  • The average length Lˉ=∑pili\bar L = \sum p_i l_i becomes smaller than a fixed-length code and can approach the entropy HH, so bit rate, bandwidth and storage are reduced.
  • It uses the source statistics; when probabilities are unequal, fixed-length codes waste bits.
  • Prefix (instantaneous) variable-length codes such as Huffman and Shannon–Fano remain uniquely decodable.

Example: four symbols with p=0.5,0.25,0.125,0.125p = 0.5, 0.25, 0.125, 0.125. Fixed code: 2 bits each, Lˉ=2\bar L = 2. Variable code 0, 10, 110, 111: Lˉ=0.5(1)+0.25(2)+0.125(3)+0.125(3)=1.75\bar L = 0.5(1) + 0.25(2) + 0.125(3) + 0.125(3) = 1.75 bits = HH, so efficiency rises from 87.5 % to 100 %. (Morse code uses the same idea: "E" is a single dot.)

Numerical

Probabilities {0.2,0.15,0.25,0.05,0.3,0.05}\{0.2, 0.15, 0.25, 0.05, 0.3, 0.05\} (sum = 1).

Entropy:

Symbolpip_ilog⁡2(1/pi)\log_2(1/p_i)pilog⁡2(1/pi)p_i\log_2(1/p_i)
x10.22.32190.4644
x20.152.73700.4105
x30.252.00000.5000
x40.054.32190.2161
x50.31.73700.5211
x60.054.32190.2161
Total12.3282
H=2.3282 bits/symbolH = 2.3282\ \text{bits/symbol}

Fixed-length code: 6 symbols need ⌈log⁡26⌉=3\lceil\log_2 6\rceil = 3 bits each, so Lˉ=3\bar L = 3 bits/symbol.

Maximum code efficiency of this fixed-length encoder:

ηmax=HLˉ=2.32823=0.7761=77.61%\eta_{max} = \frac{H}{\bar L} = \frac{2.3282}{3} = 0.7761 = 77.61\%

(Redundancy = 22.39 %.) A variable-length code, e.g. Huffman with Lˉ=2.35\bar L = 2.35 bits, would raise the efficiency to 2.3282/2.35=99.07%2.3282/2.35 = 99.07\%.

(If "maximum efficiency" is read instead as the source efficiency relative to the maximum entropy Hmax=log⁡26=2.585H_{max} = \log_2 6 = 2.585 bits/symbol, it is 2.3282/2.585=90.07%2.3282/2.585 = 90.07\%.)

Answer: H=2.3282H = 2.3282 bits/symbol; maximum efficiency of the fixed-length code = 77.61 %.

✓ Answer checked by Claude Opus 5.5 (high effort)

All Communication Systems chapter 6 questions →