Huffman coding is a lossless data compression algorithm. The idea is to assign codes to input characters and the length of the assigned code is based on the frequency of character occurance. The most frequent character gets the smallest code and the least frequent character gets the largest code.
- Open input file, find the frequencies of the characters.
- Construct Huffman Tree, find and store Huffman Codes.
- Store Huffman Codes and encoded data into a desired file with
.hencextension.
- Open the compressed file (
.hencextension), recreate Huffman Tree based on Huffman Codes. - Decode the file based on the tree and store the results into the desired file.
Checkout encoding.cpp and decoding.cpp
-
Create an object of
Huffmanclass.
Huffman h; -
To compress, call
encodefunction which takes two arguments:
h.encode("file to be compressed", "name of compressed file") -
To decompress, call
decodefunction which takes two arguments:
h.decode("file to be decompressed", "name of decompressed file") -
Run the code.