1HashCode / HuffmanCoder

Implementing the Huffman encoding and decoding algorithms

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Huffman encoding is a technique used for lossless data compression.

This algorithm helps in compressing digital information in the most efficient manner which was developed by Huffman from the Claude Shannon's compression algorithm,this algorithm works on information probability theory. Therefore, we take the occurrence of each letter in the text and then put it into a MinHeap to get a tree where the MinHeap takes care of the fact that the least occurred letters will have the least bits representing them. the process boils down to asking questions on each node of the tree and representing the path by 1 and 0;

Huffman Encoder:

The encoder takes input data (usually text or binary data) and generates a Huffman tree based on the frequency of characters in the input. It then assigns variable-length codes to each character based on their frequency in the input. Finally, it encodes the input data using the generated Huffman codes, producing a compressed output.

Huffman Decoder:

The decoder takes the compressed data generated by the encoder and the Huffman tree used for encoding. It reads the compressed data bit by bit and traverses the Huffman tree to decode each encoded character, reconstructing the original input data.

How to use the project?

Create an instance of the class in the main function and pass the string text into the constructor and the encode method. The encode method returns the binary encoded string. The decode method returns the original string by accepting the binary encoded string as the parameter.

About

Implementing the Huffman encoding and decoding algorithms


Languages

Language:Java 100.0%