Hi, this is my C++ implementation of the Huffman coding algorithm
Huffman coding is a lossless data compression algorithm. The idea is to assign variable-length codes to input characters, lengths of the assigned codes are based on the frequencies of corresponding characters. The most frequent character gets the smallest code and the least frequent character gets the largest code. The variable-length codes assigned to input characters are Prefix Codes, means the codes(bit sequences) are assigned in such a way that the code assigned to one character is not the prefix of code assigned to any other character.
More on Wikipedia Huffman coding.
First
git clone https://github.com/yanbentes/huffman-coding
Compile the program
g++ huffman.cpp -o huffman
Before executing create a .txt file with the text that you want to assign codes. After that execute the program
./huffman
Enter with the file name that you want to assign codes. The program will print the characters frequencies, their respective code and the final coding.
Exemple output
char | freq | code |
68 | 110 | |
, | 4 | 000000 |
i | 4 | 01100111 |
D | 1 | 011010110 |
… | … | … |
01101011001100111…