Skip to content

irythmgarg/Huffman-compression-Algorithm

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Huffman-compression-Algorithm

📦✨ Huffman Coding - File Compression & Decompression 🚀

Huffman Tree C++ Status


🌟 Project Overview

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! 🔐


📂 File Structure

📦 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

⚙️ How It Works

  1. Build Frequency Table 📊 → Count frequency of each character.
  2. Construct Huffman Tree 🌳 → Greedy approach using min-heap.
  3. Generate Huffman Codes 🔢 → Shorter codes for frequent chars.
  4. Encode File 📦 → Replace characters with Huffman codes.
  5. Decode File 🔓 → Rebuild original text from encoded bits.

🚀 Getting Started

🔧 Compilation

# Compile the project
$ g++ encode.cpp huffman.cpp -o encode
$ g++ decode.cpp huffman.cpp -o decode

▶️ Usage

# To compress a file
$ ./encode inputFile.txt compressed.bin

# To decompress a file
$ ./decode compressed.bin outputFile.txt

🎯 Features

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) ⚡


📸 Screenshots

Input File

Image

Compressed File

Image

How to Compress

Image

How to Decompress

Image

📥 Input File A text file of size 2.2 MB 📝

📤 Compressed File Size significantly reduced 1.1 MB ⚡📉

📂 Decompressed File Exactly matches the original ✅


🧑‍💻 Author

👨‍🎓 Ridham Garg

🎓 Thapar Institute of Engineering and Technology, Patiala

🌟 Passionate about Data Structures, Algorithms & Real-World Applications 🚀


💡 Future Enhancements

  • 🌐 Add GUI for easier interaction.
  • 📊 Show real-time compression statistics.
  • 🗜️ Support for binary/image files.

💡 Note-

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).

⭐ Support

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! 🔥

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages