Skip to content

File compressor and decompressor using huffman coding Algorithm

Notifications You must be signed in to change notification settings

jiteshchawla1511/File-Compression

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

File Compression

The file compression project utilizing the Huffman algorithm is a software application designed to reduce the size of files while maintaining their integrity. This project leverages the principles of the Huffman algorithm to compress data efficiently and achieve significant reductions in file size.

The project typically consists of several components, including:

  1. File Input and Analysis: The application accepts input files and performs an initial analysis to determine the frequency of occurrence of symbols within the file. This analysis is crucial for constructing the Huffman tree and assigning variable-length codes to each symbol.

  2. Huffman Tree Construction: Based on the frequency analysis, the project constructs a Huffman tree, which is a binary tree representation of the symbols in the file. The tree is built using a priority queue or heap data structure, where symbols with lower frequencies are given higher priority. The construction process involves iteratively combining the least frequent symbols into internal nodes until the entire tree is formed.

  3. Variable-Length Code Assignment: Once the Huffman tree is constructed, the project assigns variable-length codes to each symbol based on its position within the tree. This step ensures that frequently occurring symbols are encoded with shorter codes, resulting in more efficient compression. The codes assigned to each symbol are stored in a lookup table for reference during compression and decompression.

  4. Compression: During compression, the project reads the input file and replaces each symbol with its corresponding Huffman code. The application traverses the Huffman tree for each symbol encountered, using the lookup table to retrieve the corresponding code. The encoded symbols are then written to an output file, along with any necessary metadata to facilitate decompression.

  5. Decompression: The compressed file generated by the project can be decompressed using the same Huffman algorithm. The application reads the compressed file, reconstructs the Huffman tree using the frequency information or metadata stored within the file, and decodes the encoded symbols by traversing the tree from the root to the leaf nodes. The original symbols are then written to an output file, resulting in the recovery of the original file.

The file compression project utilizing the Huffman algorithm offers advantages such as efficient storage utilization and faster data transmission. It finds applications in various domains where file size reduction is crucial, including text documents, images, videos, and more. The project's implementation can be customized and optimized to suit specific requirements and can serve as a valuable tool for data compression and optimization

Guide to compress the File

First open the director in which the code is present

*For Mac Users Here the input.txt file is the one we are compressing

g++-12 encode.cpp huffmancoding.cpp -o main
./main input.txt compressFile.huf

Guide to decompress the File

First open the director in which the code is present

*For Mac Users Here the output.txt file where we will get the decompressed file

g++-12 decode.cpp huffmancoding.cpp -o main
./main compressFile.huf output.txt

About

File compressor and decompressor using huffman coding Algorithm

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages