This program implements a text compression algorithm using Huffman encoding in C++. The program provides a Command Line Interface (CLI) based GUI.
- A C++ compiler that supports C++11 standard.
- CMake
After running the program, the user will be presented with the following options:
- Compress text
- To compress text, select the Compress text option and enter the path to the input text file. The compressed output will be written to a file named output.huff.
- Decompress text
- To decompress text, select the Decompress text option and enter the path to the compressed text file (i.e.,output.huff). The decompressed output will be written to a file named output.txt.
- Exit
The program uses the Huffman encoding algorithm to compress text. Huffman encoding is a variable-length prefix coding algorithm that assigns shorter codes to more frequently occurring characters in the input text.
The program first reads the input text and computes the frequency of each character. It then constructs a Huffman tree by repeatedly merging the two least frequent characters until a single tree is formed. The Huffman codes for each character are determined by traversing the tree from the root to the leaf corresponding to that character.
The compressed output consists of the Huffman tree (in a serialized form) followed by the encoded text. The Huffman tree is used to decompress the text.
This program was developed as a project for the Data Structures and Algorithms course at NUST College of EME.