- Asked 3/20
- 2073 Shrawan · 4 marks
- 2072 Kartik · 3 marks
- 2071 Chaitra · 3 marks
Huffman coding principle
Short answer
Huffman coding assigns shorter variable-length prefix codes to more frequent symbols, minimizing average code length. The algorithm repeatedly merges the two least probable nodes, building a binary tree, then assigns 0/1 to branches. Example: probabilities 0.4,0.3,0.2,0.1 yield codes A=0, B=10, C=111, D=110 with average length 1.9 bits.
Explain the general working principle of the Huffman coding algorithm.
Huffman coding is a lossless source-coding method that assigns variable-length prefix codes to symbols, shorter codes to more probable symbols and longer codes to rare ones, so that the average code length is minimum and close to the entropy.
Principle
- A prefix code has no codeword that is a prefix of another, so decoding is instant and unambiguous.
- Frequent symbols get short codes, so the average length L = Σ pᵢ lᵢ is minimised. Huffman's algorithm produces an optimal prefix code for given probabilities, with H ≤ L < H + 1.
Algorithm
- List the symbols with their probabilities (or frequencies).
- Pick the two symbols with the smallest probabilities and merge them into a new node whose probability is the sum.
- Repeat step 2 with the new node in the list until only one node (the root, probability 1) remains.
- Label the two branches at each node 0 and 1.
- Read the code for each symbol from the root down to its leaf.
Small example
A = 0.4, B = 0.3, C = 0.2, D = 0.1.
D(0.1)+C(0.2)=0.3 ; 0.3+B(0.3)=0.6 ; 0.6+A(0.4)=1
A=0 B=10 C=111 D=110
L = 0.4(1) + 0.3(2) + 0.2(3) + 0.1(3) = 1.9 bits; H = 1.846 bits; efficiency = 97.2 %.
Properties
- Efficiency η = H / L. No other symbol-by-symbol code gives a smaller L.
- Codes are not unique when ties occur, but L is the same.
- The code table must be sent to the decoder (or both sides must know probabilities).
- Used in JPEG, MP3, ZIP and fax.
✓ Answer checked by Claude Sonnet 5.5
Related questions
- Huffman coding of a sentence (Khoji Rahechha) · Data Communication, chapter 8
- Source coding; fixed vs variable length codes · Data Communication, chapter 8
- FHSS working principle · Data Communication, chapter 6 · asked 4×
- Huffman code for a sentence (Kun Mandir) · Data Communication, chapter 8
- Huffman code for p = 0.6, 0.2, 0.1, 0.05, 0.05 · Data Communication, chapter 8
- Huffman code for five symbols (0.2, 0.35, ...) · Data Communication, chapter 8
- Importance of source encoder; Huffman algorithm · Communication Systems, chapter 6
- Source coding aim; Huffman "Kun Mandir Ma Janchhau Yatri" · Communication Systems, chapter 6
- Types of noise; Shannon-Fano and Huffman coding efficiency · Communication Systems, chapter 6
- Coding efficiency: binary, Shannon-Fano and Huffman · Communication Systems, chapter 6