https://github.com/geekyharsh05/huffman-encoder
The algorithm assigns shorter codes to more frequent characters, optimizing the overall compression.
https://github.com/geekyharsh05/huffman-encoder
binarytree huffman-algorithm huffman-compression-algorithm python
Last synced: 9 months ago
JSON representation
The algorithm assigns shorter codes to more frequent characters, optimizing the overall compression.
- Host: GitHub
- URL: https://github.com/geekyharsh05/huffman-encoder
- Owner: geekyharsh05
- License: mit
- Created: 2023-12-19T18:06:01.000Z (almost 2 years ago)
- Default Branch: main
- Last Pushed: 2023-12-19T18:55:54.000Z (almost 2 years ago)
- Last Synced: 2025-01-02T20:19:28.808Z (10 months ago)
- Topics: binarytree, huffman-algorithm, huffman-compression-algorithm, python
- Language: Python
- Homepage:
- Size: 17.6 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Huffman Encoding Implementation
## Overview
This Python implementation demonstrates the Huffman coding algorithm for text compression. The algorithm assigns shorter codes to more frequent characters, optimizing the overall compression.
## Installation
To use the Huffman Encoder, follow these steps:
1. Clone the repository:
```bash
git clone git@github.com:geekyharsh05/Huffman-Encoder.git
```
2. Navigate to the project directory:
```bash
cd Huffman-Encoder
```
## Visualization
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:
1. After running the script, check the current working directory for the generated 'huffman_tree.png' file.
2. 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.
## Example
```bash
python src/main.py
```
## User Input Example
```bash
Enter the text you want to encode: HELLO
```
## Expected Output
```bash
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'
```