Skip to content

shafinalam07/huffman-file-compressor

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 

Repository files navigation

Huffman Coding File Compressor

What it does

Instead of just reading about greedy algorithms and trees in textbooks, I built a working text compressor in C using the Huffman Coding algorithm!

The program takes a list of letters and counts how often they appear. It puts them into a custom-built, self-sorting list called a "Min-Heap" and links them together to form a binary Huffman Tree. From this tree, it creates unique, short binary codes (0s and 1s) for each letter. Letters that show up a lot get very short codes, which shrinks the overall file size!

Why I built this

I built this project to challenge myself with tougher data structures and see algorithms work in real life. It helped me learn:

  1. Advanced Trees and Heaps: How to build and handle binary trees and sorting queues from scratch in C without using pre-made libraries.
  2. How Compression Works: Understanding the actual programming logic behind shrinking a file without messing up or losing any data.
  3. Optimizing Space: Learning how file encoders look at data streams to map out characters efficiently.

Features

  • Custom Min-Heap (Priority Queue): I built a sorting queue from scratch using arrays to track the characters with the lowest frequencies automatically.
  • Smart Binary Codes: It assigns short codes to common letters (like 0) and longer codes to rare letters (like 1101), which drastically cuts down memory usage.
  • Tree Traversal: Uses a clean recursive loop to walk down the tree branches and print out the final binary shortcuts for each character.

How to run it

  1. Open your terminal inside this folder and compile the code: gcc huffman.c -o huffman

  2. Run the program: ./huffman

Tech Used

  • C Language
  • GCC Compiler
  • Core Concepts: Binary Trees, Min-Heaps, and Greedy Algorithms

Author

Shafin Alam GitHub: shafinalam07

About

A custom data compression utility implementing Huffman Coding using Trees and custom Priority Queues in C

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages