Data Structures and Algorithms 
Operation of the Huffman algorithm 
These diagrams show how a Huffman encoding tree is built using a straightforward greedy algorithm which combines the two smallestweight trees at every step.
Initial data sorted by frequency  
Combine the two lowest frequencies, F and E, to form a subtree of weight 14. Move it into its correct place. 

Again combine the two lowest frequencies, C and B, to form a subtree of weight 25. Move it into its correct place. 

Now the subtree with weight, 14, and
D are combined to make a tree of
weight, 30.
Move it to its correct place. 

Now the two lowest weights are held by the
"25" and "30" subtrees, so combine them to
make one of weight, 55.
Move it after the A. 

Finally, combine the A and the
"55" subtree to produce the final tree.
The encoding table is: A 0 C 100 B 101 F 1100 E 1101 D 111 
Back to Huffman encoding  Back to the Table of Contents 