While the number of nodes in the list > 1:
for i := 1 to n-1 do
String: BACADAEAFABBAAAGAH
A | B | C | D | E | F | G | H | |
Frequency (in thousands) | 50 | 20 | 5 | 5 | 5 | 5 | 5 | 5 |
Fixed-length codeword | 000 | 001 | 010 | 011 | 100 | 101 | 110 | 111 |
Variable-length codeword | 0 | 100 | 1010 | 1011 | 1100 | 1101 | 1110 | 1111 |
OUTPUT: 10001010010110110001101010010000111001111
while more than one node in tree do sub_nodes := key of node with smallest probability in tree sec_sub_nodes = key of := key of node with second smallest propability in tree
for node in sub_nodes do
for node in sec_sub_nodes do
for code in seq do
if temp in code_table then
[1] David A Huffman. A method for the construction of minimum-redundancy codes. Proceedings of the Institute of Radio Engineers (IRE), 40(9):1098–1101, 1952.
[2] Nelson M. and Gailly J. The Data Compression Book. M&T Books, 1996.