Huffman coding is a compression technique used to reduce the number of bits required to send or store a message or string. It is based on the idea that frequently appearing characters will have shorter bit representation, and less frequent characters will have longer bit representation. If we consider the Huffman coding as a tree structure, the less frequent characters or items will be at the top part of the tree and more frequent items will be at the bottom of the tree or in the leaf. Huffman encoding relies a lot on the priority queue. Huffman encoding can be computed by first creating a tree of nodes.
Process to create a tree of nodes:
- We have to create a leaf node for each symbol and add it to the priority queue.
- While there is more than one node in the queue, do the following:
1. Remove the node of highest priority (lowest probability...