Presentation is loading. Please wait.

Presentation is loading. Please wait.

CSE 326 Huffman coding Richard Anderson.

Similar presentations


Presentation on theme: "CSE 326 Huffman coding Richard Anderson."— Presentation transcript:

1 CSE 326 Huffman coding Richard Anderson

2 Coding theory A B Conversion, Encryption, Compression C D
Code examples 000,001,010,011,100,101 1,01,001,0001,00001,000001 00,010,011,100,11,101 Conversion, Encryption, Compression Binary coding Variable length coding A B C D E F

3 Decode the following 11010010010101011 100100101010 E T 11 N 100 I
T 11 N 100 I 1010 S 1011 E T 10 N 100 I 0111 S 1010 Prefix code Ambiguous

4 Prefix code No prefix of a codeword is a codeword Uniquely decodable A
00 1 B 010 01 10 C 011 001 11 D 100 0001 E 00001 11000 F 101 000001

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
T 11 N 100 I 1010 S 1011

7 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

8 Huffman code H = new Heap() for each wi T = new Tree(wi) H.Insert(T)
while H.Size() > 1 T1 = H.DeleteMin() T2 = H.DeleteMin() T3 = Merge(T1, T2) H.Insert(T3)

9 Example: Weights 4, 5, 6, 7, 11, 14, 21 21 14 11 6 7 4 5

10 Draw a Huffman tree for the following data values and show internal weights: 3, 5, 9, 14, 16, 35


Download ppt "CSE 326 Huffman coding Richard Anderson."

Similar presentations


Ads by Google