Home » Algorithm of Huffman Code

Algorithm of Huffman Code

by Online Tutorials Library

Algorithm of Huffman Code

Huffman (C)  1. n=|C|  2. Q ← C  3. for i=1 to n-1  4. do  5. z= allocate-Node ()  6. x=  left[z]=Extract-Min(Q)  7. y= right[z] =Extract-Min(Q)  8. f [z]=f[x]+f[y]  9. Insert (Q, z)  10. return Extract-Min (Q)  

Example: Find an optimal Huffman Code for the following set of frequencies:

Solution:

Algorithm of Huffman Code

i.e.

Algorithm of Huffman Code

Again for i=2

Algorithm of Huffman Code
Algorithm of Huffman Code
Algorithm of Huffman Code

Similarly, we apply the same process we get

Algorithm of Huffman Code
Algorithm of Huffman Code

Thus, the final output is:

Algorithm of Huffman Code

You may also like