Presentation is loading. Please wait.

Presentation is loading. Please wait.

Problem: Huffman Coding Def: binary character code = assignment of binary strings to characters e.g. ASCII code A = 01000001 B = 01000010 C = 01000011.

Similar presentations


Presentation on theme: "Problem: Huffman Coding Def: binary character code = assignment of binary strings to characters e.g. ASCII code A = 01000001 B = 01000010 C = 01000011."— Presentation transcript:

1 Problem: Huffman Coding Def: binary character code = assignment of binary strings to characters e.g. ASCII code A = 01000001 B = 01000010 C = 01000011 … fixed-length code How to decode: ? 01000001010000100100001101000001

2 Problem: Huffman Coding e.g. code A = 0 B = 10 C = 11 … variable-length code How to decode: ? 0101001111 Def: binary character code = assignment of binary strings to characters

3 Problem: Huffman Coding e.g. code A = 0 B = 10 C = 11 … How to decode: ? 0101001111 Def: A code is prefix-free if no codeword is a prefix of another codeword. variable-length code Def: binary character code = assignment of binary strings to characters

4 Problem: Huffman Coding Def: A code is prefix-free if no codeword is a prefix of another codeword. variable-length code Def: binary character code = assignment of binary strings to characters e.g. another code A = 1 B = 10 C = 11 … How to decode: ? 10101111

5 Problem: Huffman Coding Def: Huffman coding is an optimal prefix-free code. E11.1607% A8.4966% R7.5809% I7.5448% O7.1635% T6.9509% N6.6544% S5.7351% L5.4893% C4.5388% U3.6308% D3.3844% P3.1671% M3.0129% H3.0034% G2.4705% B2.0720% F1.8121% Y1.7779% W1.2899% K1.1016% V1.0074% X0.2902% Z0.2722% J0.1965% Q0.1962% Optimization problems - Input: - Output: - Objective:

6 an alphabet with frequencies a prefix-free code minimize expected number of bits per character Problem: Huffman Coding Def: Huffman coding is an optimal prefix-free code. E11.1607% A8.4966% R7.5809% I7.5448% O7.1635% T6.9509% N6.6544% S5.7351% L5.4893% C4.5388% U3.6308% D3.3844% P3.1671% M3.0129% H3.0034% G2.4705% B2.0720% F1.8121% Y1.7779% W1.2899% K1.1016% V1.0074% X0.2902% Z0.2722% J0.1965% Q0.1962% Huffman coding - Input: - Output: - Objective:

7 Problem: Huffman Coding A60% B20% C10% D10% an alphabet with frequencies a prefix-free code minimize expected number of bits per character Huffman coding - Input: - Output: - Objective: Example:Is fixed-width coding optimal ?

8 Problem: Huffman Coding A60% B20% C10% D10% an alphabet with frequencies a prefix-free code minimize expected number of bits per character Huffman coding - Input: - Output: - Objective: Example:Is fixed-width coding optimal ? NO, exists a prefix-free code using 1.6 bits per character !

9 Problem: Huffman Coding A60% B20% C10% D10% an alphabet with frequencies a prefix-free code minimize expected number of bits per character Huffman coding - Input: - Output: - Objective: Example:Is fixed-width coding optimal ? NO, exists a prefix-free code using 1.6 bits per character !

10 Problem: Huffman Coding an alphabet with frequencies a prefix-free code minimize expected number of bits per character Huffman coding - Input: - Output: - Objective: Huffman ( [a 1,f 1 ],[a 2,f 2 ],…,[a n,f n ]) 1. if n=1 then 2. code[a 1 ]  “” 3. else 4. let f i,f j be the 2 smallest f’s 5. Huffman ( [a i,f i +f j ],[a 1,f 1 ],…,[a n,f n ] ) omits a i,a j 6. code[a j ]  code[a i ] + “0” 7. code[a i ]  code[a i ] + “1”

11 Problem: Huffman Coding Let x,y be the symbols with frequencies f x > f y. Then in an optimal prefix code length(C x )  length(C y ). Lemma 1:

12 Problem: Huffman Coding Let x,y be the symbols with frequencies f x > f y. Then in an optimal prefix code length(C x )  length(C y ). Lemma 1: If w is a longest codeword in an optimal code then there exists another codeword of the same length. Lemma 2:

13 Problem: Huffman Coding Let x,y be the symbols with frequencies f x > f y. Then in an optimal prefix code length(C x )  length(C y ). Lemma 1: Let x,y be the symbols with the smallest frequencies. Then there exists an optimal prefix code such that the codewords for x and y differ only in the last bit. Lemma 3: If w is a longest codeword in an optimal code then there exists another codeword of the same length. Lemma 2:

14 Problem: Huffman Coding Let x,y be the symbols with frequencies f x > f y. Then in an optimal prefix code length(C x )  length(C y ). Lemma 1: Let x,y be the symbols with the smallest frequencies. Then there exists an optimal prefix code such that the codewords for x and y differ only in the last bit. Lemma 3: The prefix code output by the Huffman algorithm is optimal. Theorem: If w is a longest codeword in an optimal code then there exists another codeword of the same length. Lemma 2:


Download ppt "Problem: Huffman Coding Def: binary character code = assignment of binary strings to characters e.g. ASCII code A = 01000001 B = 01000010 C = 01000011."

Similar presentations


Ads by Google