Optimal performance (better than Shannon-Fano) when a integer number
of bits is assigned to each symbol.
The VLC codec builds a binary tree where the symbols are stored in the
leafs and the distance of each symbol to the root of the tree is .
After label each binary branch in the tree, the Huffman code-word for the
symbol
is the sequence of bits (labels) that we must use to travel from the root to
the -leaf.
2 Algorithm to build the Huffman tree
Create a list of nodes. Each node stores a symbol and its probability.
While the number of nodes in the list > 1:
Extract from the list the 2 nodes with the lowest probability.
Insert in the list a new node (that is the root of a binary tree) whose
probability is the sum of the probability of its leafs.
Example
References
[1]D.A. Huffman. A Method for the Construction of Minimum Redundancy
Codes. Proceedings of the Institute of Radio Engineers, 40:1098–1101, 1952.