Huffman-Encoding:
Huffman encoding is a particular type of optimal prefix code that is commonly used for lossless data compression.
Wikipedia: https://en.wikipedia.org/wiki/Huffman_coding
Geeksforgeeks: https://www.geeksforgeeks.org/huffman-coding-greedy-algo-3/
How to use the project-code:
- Clone the repository.
- Open the source-code in Eclipse or any IDE.
- Make a package and add all the source-code in that.
- Run the Huffman_Client.java....... Boom, It's working.
How it works:
-
First of all take the input string.
-
Make frequency map for that string.
-
For each key in the map, now you need to create a Node & insert that node in a min Heap (here implemented using Priority Queue). [Node=> char character, int frequency, Node left_node, Node right_node]
-
Iterate whole queue, take 2 Node, combine them and push them in the queue.
-
Do 4th step until we are left with single Node.
-
Take the last node and parse that node to fill encoder and decoder Hash maps. while parsing the node if we are going in the left node add 0 and in right add 1.
Sample: For string s="abcdbbd"
- For more understanding refer to this: https://www.youtube.com/watch?v=uDS8AkTAcIU&t=566s