Skip to content

A project done in College Level where Huffman Encoding is implemented in C++ and verified by this decoding.

Notifications You must be signed in to change notification settings

sidd-07/Huffman_Coding

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

11 Commits
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Huffman Coding Compression and Decompression

Overview

This project implements Huffman Coding, a lossless data compression algorithm, in C++. It reads text from a file, calculates character frequencies and probabilities, builds a Huffman Tree, and generates Huffman codes. Additionally, it allows users to encode words into Huffman codes and decode Huffman-encoded text interactively.

Features

  • πŸ“„ Reads a text file and calculates character frequencies.
  • 🌳 Builds a Huffman Tree and generates Huffman codes.
  • πŸ”  Encodes a user-input word into Huffman code.
  • πŸ”„ Decodes a given Huffman code back into text.
  • πŸ’Ύ Saves character frequencies, probabilities, Huffman codes, and user interactions into an output file.

Prerequisites

  • βœ… C++ Compiler (e.g., g++)
  • βœ… Basic understanding of data structures like trees and priority queues

File Structure

πŸ“‚ Project Folder

  • │── πŸ“œ huffman.cpp # Main implementation file
  • │── πŸ“œ James C. Maxwell Biography.txt # Sample input file (replace as needed)
  • │── πŸ“œ Out_text.txt # Output file storing results

How to Run

  1. Compile the code: g++ -o huffman huffman.cpp
  2. Run the executable: ./huffman
  3. Modify the text file path inside huffman.cpp (update inputFile variable accordingly).
  4. Choose an option from the menu:
  • Encode a word into Huffman code.
  • Decode a Huffman code back to text.
  • Save results and exit.

Example Usage

Options:

  1. Encode a word to Huffman code
  2. Decode Huffman code to text
  3. Exit and Save Outputs Enter your choice: 1 Enter the word to encode: hello Huffman code for 'hello': 1010110110

Output File (Out_text.txt)

This file stores:

  • πŸ“Š Character frequencies and probabilities
  • πŸ”’ Generated Huffman codes
  • πŸ“ Encoded and decoded text from user interactions

Author

πŸ‘€ Developed by [G. Siddartha Reddy]

About

A project done in College Level where Huffman Encoding is implemented in C++ and verified by this decoding.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages