Huffman Coding - Explanation and Tree
Huffman coding is a lossless data compression algorithm. It assigns variable-length binary codes to
input characters, with shorter codes assigned to more frequent characters. The goal is to reduce the
total number of bits used to represent data.
Given Characters and Frequencies:
a: 10, e: 15, i: 12, o: 3, u: 4, s: 13, t: 1
Huffman Codes:
i: 00
s: 01
e: 10
u: 1100
t: 11010
o: 11011
a: 111
Average Code Length: 2.517 bits per character
Applications of Huffman Coding:
- Data compression (e.g., ZIP files)
- Image compression (e.g., JPEG)
- Multimedia codecs (e.g., MP3)
Time Complexity:
- Building the Huffman Tree: O(n log n)
- Generating codes: O(n), where n is the number of characters.