Skip to content

yanbentes/huffman-coding

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 

Repository files navigation

Huffman coding

Hi, this is my C++ implementation of the Huffman coding algorithm

What is Huffman coding?

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.

How to use the program

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

charfreqcode
68110
,4000000
i401100111
D1011010110

01101011001100111…

About

Huffman coding algorithm

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages