Professional Documents
Culture Documents
Huffman Coding: Eric Dubois
Huffman Coding: Eric Dubois
Eric Dubois
September 2012
Codewords
0 10
p1 = 0.25
0 00
p2 = 0.2
0.4 0
1.0
p3 = 0.2 01
1 0.6
0 1
p4 = 0.18 110
0 0.35 1110
p5 = 0.09
1
0 0.17 11110
p6 = 0.05 1
0.08
0 111110
p7 = 0.02 1
0.03
1 111111
p8 = 0.01
1
`Shann = 3.04
`fixed = 3
Example of Huffman and Shannon code
Shannon code Huffman code
p_i ‐log_2(p_i) ‐p_i*log_2(p_i) l_i p_i*l_i 2^(‐l_i) l_i p_i*l_i 2^(‐l_i)
0.25 2.0000 0.5000 2 0.5 0.25 2 0.5 0.25
0.20 2.3219 0.4644 3 0.6 0.125 2 0.4 0.25
0.20 2.3219 0.4644 3 0.6 0.125 2 0.4 0.25
0.18 2.4739 0.4453 3 0.54 0.125 3 0.54 0.125
0.09 3.4739 0.3127 4 0.36 0.0625 4 0.36 0.0625
0.05 4.3219 0.2161 5 0.25 0.03125 5 0.25 0.03125
0.02 5.6439 0.1129 6 0.12 0.015625 6 0.12 0.015625
0.01 6.6439 0.0664 7 0.07 0.0078125 6 0.06 0.015625
0 1
0 1 0 1
c (a4)
0 1
c (a5)
0 1
c (a6)
0 1
c (a7) c (a8)
Note that not all optimal codes need satisfy these properties, but at least
one does.
cM (aM-1) cM (aM)
cM-1 (a’M-1)