This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
1. CSE 326 Huffman coding Richard Anderson
2. Coding theory
Conversion, Encryption, Compression
Binary coding
Variable length coding
Code examples 000,001,010,011,100,101 1,01,001,0001,00001,000001
00,010,011,100,11,101 A B C D E F
3. Decode the following 11010010010101011 100100101010
Ambiguous Prefix code E 0 T 11 N 100 I 1010 S 1011 E 0 T 10 N 100 I
0111 S 1010
4. Prefix code
No prefix of a codeword is a codeword
Uniquely decodable
A 00 1 00 B 010 01 10 C 011 001 11 D 100 0001 0001 E 11 00001 11000
F 101 000001 101
5. Prefix codes and binary trees
Tree representation of prefix codes
A 00 B 010 C 0110 D 0111 E 10 F 11
6. Construct the tree for the following code E 0 T 11 N 100 I
1010 S 1011
7. Minimum length code
Average cost
Average leaf depth
Huffman tree tree with minimum weighted path length
C(T) weighted path length
8. Compute average leaf depth A 00 1/4 B 010 1/8 C 0110 1/16 D
0111 1/16 E 1 1/2
9. Huffman code algorithm
Derivation
Two rarest items will have the longest codewords
Codewords for rarest items differ only in the last bit
Idea: suppose the weights are with and the smallest
weights
Start with an optimal code for and
Extend the codeword for to get codewords for and
10. Huffman code H = new Heap() for each w i T = new Tree(w i )
H.Insert(T) while H.Size() > 1 T 1 = H.DeleteMin() T 2 =
H.DeleteMin() T 3 = Merge(T 1 , T 2 ) H.Insert(T 3 )