Algorithm of Huffman CodeHuffman (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: ![]() i.e. ![]() Again for i=2 ![]() ![]() ![]() Similarly, we apply the same process we get ![]() ![]() Thus, the final output is: ![]()
Next TopicActivity or Task Scheduling Problem
|