Skip to main content

Source coding aim; Huffman "Kun Mandir Ma Janchhau Yatri"

Short answer

Source coding aims to compress data by removing redundancy, using short codes for frequent symbols to reduce average bit rate while allowing exact recovery. Huffman coding of the phrase yields average length 3.607 bits/symbol, entropy 3.580 bits/symbol, and efficiency 99.25%.

What is the aim of source coding? Encode "Kun Mandir Ma Janchhau Yatri" using Huffman codes and find its efficiency.

Aim of source coding

Source coding represents the output of an information source with as few bits as possible, while still allowing the receiver to recover it exactly (lossless coding) or acceptably (lossy coding). Its aims are:

  • Remove redundancy: give short code words to frequent symbols and long ones to rare symbols, so the average code length Lˉ\bar L approaches the entropy HH (Shannon's source coding theorem: Lˉ≥H\bar L \ge H).
  • Raise efficiency η=H/Lˉ\eta = H/\bar L towards 100%.
  • Lower the bit rate, which saves bandwidth, storage and transmission power.
  • Produce a uniquely decodable (prefix) code so the receiver can decode it without separators.

Examples are Huffman, Shannon–Fano and LZW coding, as well as speech and image compression.

Huffman coding of "Kun Mandir Ma Janchhau Yatri"

Assumptions: case is ignored, and the space is counted as a symbol. The message has 28 symbols and 14 distinct symbols.

Huffman procedure: list the symbols by probability. Repeatedly combine the two least probable entries into one node whose weight is their sum, until only one node is left. In each merge, the first group listed gets bit 0 and the second group gets bit 1. Each symbol's code word is read from the root down to that symbol.

Merge steps:

  1. {d} (1) + {c} (1) → 2
  2. {k} (1) + {j} (1) → 2
  3. {y} (1) + {t} (1) → 2
  4. {i} (2) + {h} (2) → 4
  5. {r} (2) + {m} (2) → 4
  6. {d, c} (2) + {u} (2) → 4
  7. {y, t} (2) + {k, j} (2) → 4
  8. {space} (4) + {n} (3) → 7
  9. {r, m} (4) + {i, h} (4) → 8
  10. {y, t, k, j} (4) + {d, c, u} (4) → 8
  11. {space, n} (7) + {a} (5) → 12
  12. {y, t, k, j, d, c, u} (8) + {r, m, i, h} (8) → 16
  13. {y, t, k, j, d, c, u, r, m, i, h} (16) + {space, n, a} (12) → 28
SymbolCountpip_iCodelil_ipilip_i l_i
a55/28 = 0.17861120.3571
space44/28 = 0.142910030.4286
n33/28 = 0.107110130.3214
h22/28 = 0.0714011140.2857
i22/28 = 0.0714011040.2857
m22/28 = 0.0714010140.2857
r22/28 = 0.0714010040.2857
u22/28 = 0.0714001140.2857
c11/28 = 0.03570010150.1786
d11/28 = 0.03570010050.1786
j11/28 = 0.03570001150.1786
k11/28 = 0.03570001050.1786
t11/28 = 0.03570000150.1786
y11/28 = 0.03570000050.1786

Average code length:

Lˉ=∑pili=10128=3.6071 bits/symbol\bar L = \sum p_i l_i = \frac{101}{28} = 3.6071\ \text{bits/symbol}

Here the numerator is the total number of bits in the encoded message: 5(2)+4(3)+3(3)+2(4)+2(4)+2(4)+2(4)+2(4)+1(5)+1(5)+1(5)+1(5)+1(5)+1(5)=1015(2) + 4(3) + 3(3) + 2(4) + 2(4) + 2(4) + 2(4) + 2(4) + 1(5) + 1(5) + 1(5) + 1(5) + 1(5) + 1(5) = 101 bits.

Entropy:

H=−∑pilog⁡2pi=3.5801 bits/symbolH = -\sum p_i \log_2 p_i = 3.5801\ \text{bits/symbol}

Efficiency:

η=HLˉ=3.58013.6071=0.9925=99.25%\eta = \frac{H}{\bar L} = \frac{3.5801}{3.6071} = 0.9925 = 99.25\%

Redundancy =1−η=0.75%= 1 - \eta = 0.75\%.

A fixed-length code for 14 symbols needs ⌈log⁡214⌉=4\lceil \log_2 14 \rceil = 4 bits/symbol (η=89.50%\eta = 89.50\%). Huffman saves 9.82% of the bits.

Answer: Lˉ=3.607\bar L = 3.607 bits/symbol, H=3.580H = 3.580 bits/symbol, efficiency η ≈ 99.25%. The message needs 101 bits instead of 112 bits with a 4-bit fixed code.

✓ Answer checked by Claude Opus 5.5 (high effort)

All Communication Systems chapter 6 questions →