Huffman
Huffman
• Can we do better?
Huffman Codes
cC cC
f [ x]dT ( x) f [a ]dT (a ) f [ x]dT ( x) f [a ]dT (a )
' '
z:14
B(T’) = 45*1+12*3+13*3+(5+9)*3+16*3
= B(T) - 5 - 9
B(T) = 45*1+12*3+13*3+5*4+9*4+16*3
Proof of Lemma B
• Prove by contradiction.
• Suppose that T does not represent an optimal prefix code
for C. Then there exists a tree T’’ such that B(T’’) < B(T).
• Without loss of generality, by Lemma A, T’’ has x and y
as siblings. Let T’’’ be the tree T’’ with the common
parent x and y replaced by a leaf with frequency f[z] =
f[x] + f[y]. Then
• B(T’’’) = B(T’’) - f[x] – f[y] < B(T) – f[x] – f[y] = B(T’)
– T’’’ is better than T’ contradiction to the
assumption that T’ is an optimal prefix code for C’