Welcome to Huffman Coding - File Compression & Decompression Tool 🎉 This project demonstrates the powerful concept of Huffman Coding, a greedy algorithm for lossless data compression 📉➡️📈.
With this project, you can encode (compress) and decode (decompress) text files using Huffman’s algorithm ⚡. The goal is to minimize file size while ensuring no data is lost! 🔐
📦 Huffman-Coding
┣ 📜 decode.cpp # 💡 Logic for decompressing files
┣ 📜 encode.cpp # ⚡ Logic for compressing files
┣ 📜 huffman.cpp # 🧠 Implementation of Huffman Tree & algorithm
┣ 📜 huffman.hpp # 📘 Header file containing function & class declarations
┣ 📜 inputFile.txt # 📝 Sample input file to test compression
- Build Frequency Table 📊 → Count frequency of each character.
- Construct Huffman Tree 🌳 → Greedy approach using min-heap.
- Generate Huffman Codes 🔢 → Shorter codes for frequent chars.
- Encode File 📦 → Replace characters with Huffman codes.
- Decode File 🔓 → Rebuild original text from encoded bits.
# Compile the project
$ g++ encode.cpp huffman.cpp -o encode
$ g++ decode.cpp huffman.cpp -o decode# To compress a file
$ ./encode inputFile.txt compressed.bin
# To decompress a file
$ ./decode compressed.bin outputFile.txt✨ Lossless Compression → 100% original data recovery
✨ Greedy Algorithm → Optimal encoding using frequencies
✨ Modular Code → Clean separation of logic in .cpp and .hpp files
✨ Scalable → Works on large files (tested on MB-level data) ⚡
Input File
Compressed File
How to Compress
How to Decompress
📥 Input File
A text file of size 2.2 MB 📝
📤 Compressed File
Size significantly reduced 1.1 MB ⚡📉
📂 Decompressed File Exactly matches the original ✅
👨🎓 Ridham Garg
🎓 Thapar Institute of Engineering and Technology, Patiala
🌟 Passionate about Data Structures, Algorithms & Real-World Applications 🚀
- 🌐 Add GUI for easier interaction.
- 📊 Show real-time compression statistics.
- 🗜️ Support for binary/image files.
Result: This project is just an implementation of Huffman coding, it is not as efficient as the compression algorithm used currently to compress files.
Example: inputFile.txt (2.2MB) is compressed to compressedFile.huf (1.1MB) file and decompressed back to ouputFile.txt (2.2MB).
If you like this project, please give it a ⭐ on GitHub! 🌟 Let’s make file compression fun & efficient together 💻✨
🔥 Data Compression Made Simple with Huffman Coding! 🔥