The secret of huffman compression lies in the fact that not all characters are equally common. For instance, in typical English text the letter 'e' is much more common than the letter 'z'. If we could encode the letter 'e' with less number of bits and the least common letter 'z' with more bits, it makes a sense and that is the idea behind huffman coding.
Theseveral steps in huffman coding are:
- Examine text to be compressed to determine the relative frequencies of individual letters.
- Assign a binary code to each letter using shorter codes for the more frequent letters.
- Encode normal text into its compressed form as a string of '0's and '1's.
- Recover the original text from the compressed.
The complete javascript code for huffman compression is available here.
Decoded text
Comments
Post a Comment