- 2075 Bhadra · 6 marks
How Huffman code reduces file size
Short answer
Huffman coding assigns short codes to frequent symbols and long codes to rare ones, reducing total bits. For 100 characters with frequencies A45, B20, C15, D10, E10, fixed 3-bit coding needs 300 bits, while Huffman needs 210 bits, saving 30%.
Explain with example how Huffman code reduces the file size.
Huffman coding reduces file size by replacing fixed-length codes (for example 8-bit ASCII or 3-bit codes) with variable-length codes: common symbols get very short codes and rare symbols get longer ones. Since common symbols occur most, the total number of bits falls.
Example
A file has 100 characters made of A, B, C, D, E with frequencies A = 45, B = 20, C = 15, D = 10, E = 10.
Fixed-length coding: 5 symbols need 3 bits each. Total = 100 x 3 = 300 bits.
Huffman tree:
- D (10) + E (10) = DE (20)
- C (15) + B (20) = CB (35)
- DE (20) + CB (35) = DECB (55)
- A (45) + DECB (55) = root (100)
Codes: A = 0, D = 100, E = 101, C = 110, B = 111.
| Symbol | Frequency | Code | Length | Bits used |
|---|---|---|---|---|
| A | 45 | 0 | 1 | 45 |
| B | 20 | 111 | 3 | 60 |
| C | 15 | 110 | 3 | 45 |
| D | 10 | 100 | 3 | 30 |
| E | 10 | 101 | 3 | 30 |
| Total | 100 | 210 |
Average length = 210/100 = 2.1 bits per symbol.
Saving = (300 - 210)/300 = 90/300 = 30%.
Against 8-bit ASCII (800 bits), the Huffman file is 210 bits, a reduction of about 73.8%.
The decoder needs the code table (or frequencies), which is stored as a small header. Because the codes are prefix-free, the bit stream is decoded without separators. The more skewed the symbol frequencies, the greater the saving.
✓ Answer checked by Claude Opus 5.5 (high effort)
Related questions
- Huffman code tree steps with example · Multimedia System, chapter 5 · asked 7×
- Huffman code for symbols A to E · Multimedia System, chapter 5
- File size: 60 s, 44.1 KHz, 8-bit stereo · Multimedia System, chapter 2 · asked 3×
- File size: 30 s, 44.1 KHz, 8-bit stereo · Multimedia System, chapter 2 · asked 3×
- File size: 20 s, 44.1 KHz, 16-bit stereo · Multimedia System, chapter 2 · asked 3×
- File size: 20 s, 44.1 KHz, 8-bit stereo · Multimedia System, chapter 2 · asked 2×
- Algorithm for Huffman code · Data Structure and Algorithm, chapter 6
- 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