This Python implementation demonstrates the Huffman coding algorithm for text compression. The algorithm assigns shorter codes to more frequent characters, optimizing the overall compression.
To use the Huffman Encoder, follow these steps:
-
Clone the repository:
git clone git@github.com:geekyharsh05/Huffman-Encoder.git
-
Navigate to the project directory:
cd Huffman-Encoder
The script generates a visual representation of the Huffman tree using the graphviz
library. The visualization is saved as 'huffman_tree.png' in the current working directory.
To view the Huffman tree visualization, follow these steps:
-
After running the script, check the current working directory for the generated 'huffman_tree.png' file.
-
Open the 'huffman_tree.png' file using an image viewer of your choice.
The visualization provides a graphical representation of the Huffman tree structure, showing the relationships between nodes and their frequencies.
Feel free to explore and analyze the generated Huffman tree to gain insights into the encoding structure of the input text.
python src/main.py
Enter the text you want to encode: HELLO
Encoded text: 00 01 11 11 10
Codes: {'H': ' 00', 'E': ' 01', 'O': ' 10', 'L': ' 11'}
Huffman Tree has been drawn and saved as 'huffman_tree.png'