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.
- π 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.
- β C++ Compiler (e.g., g++)
- β Basic understanding of data structures like trees and priority queues
π 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
- Compile the code: g++ -o huffman huffman.cpp
- Run the executable: ./huffman
- Modify the text file path inside huffman.cpp (update inputFile variable accordingly).
- Choose an option from the menu:
- Encode a word into Huffman code.
- Decode a Huffman code back to text.
- Save results and exit.
Options:
- Encode a word to Huffman code
- Decode Huffman code to text
- Exit and Save Outputs Enter your choice: 1 Enter the word to encode: hello Huffman code for 'hello': 1010110110
This file stores:
- π Character frequencies and probabilities
- π’ Generated Huffman codes
- π Encoded and decoded text from user interactions
π€ Developed by [G. Siddartha Reddy]