What is Huffman coding in C?
Huffman coding first creates a tree using the frequencies of the character and then generates code for each character. Once the data is encoded, it has to be decoded. Decoding is done using the same tree. Huffman Coding prevents any ambiguity in the decoding process using the concept of prefix code ie.
How do you write a Huffman code?
Huffman code is obtained from the Huffman tree. Huffman code is a = 000, b = 001, c = 010, d = 011, e = 1. This is the optimum (minimum-cost) prefix code for this distribution. Given an alphabet A with frequency distribution f(a) : a ∈ A.
How do you print a Huffman tree?
Steps to print codes from Huffman Tree:
Maintain an auxiliary array. While moving to the left child, write 0 to the array. While moving to the right child, write 1 to the array. Print the array when a leaf node is encountered.