problem huffman coding
play

Problem: Huffman Coding Def: binary character code = assignment of - PowerPoint PPT Presentation

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


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

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

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

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

  5. Problem: Huffman Coding Def: E 11.1607% M 3.0129% A 8.4966% H 3.0034% Huffman coding is an R 7.5809% G 2.4705% optimal prefix-free code. I 7.5448% B 2.0720% O 7.1635% F 1.8121% T 6.9509% Y 1.7779% N 6.6544% W 1.2899% S 5.7351% K 1.1016% L 5.4893% V 1.0074% C 4.5388% X 0.2902% U 3.6308% Z 0.2722% D 3.3844% J 0.1965% Optimization problems P 3.1671% Q 0.1962% - Input: - Output: - Objective:

  6. Problem: Huffman Coding Def: E 11.1607% M 3.0129% A 8.4966% H 3.0034% Huffman coding is an R 7.5809% G 2.4705% optimal prefix-free code. I 7.5448% B 2.0720% O 7.1635% F 1.8121% T 6.9509% Y 1.7779% N 6.6544% W 1.2899% S 5.7351% K 1.1016% L 5.4893% V 1.0074% C 4.5388% X 0.2902% U 3.6308% Z 0.2722% D 3.3844% J 0.1965% Huffman coding P 3.1671% Q 0.1962% - Input: an alphabet with frequencies - Output: a prefix-free code - Objective: minimize expected number of bits per character

  7. Problem: Huffman Coding Example: A 60% Is fixed-width coding optimal ? B 20% C 10% D 10% Huffman coding - Input: an alphabet with frequencies - Output: a prefix-free code - Objective: minimize expected number of bits per character

  8. Problem: Huffman Coding Example: A 60% Is fixed-width coding optimal ? B 20% NO, exists a prefix-free code C 10% using 1.6 bits per character ! D 10% Huffman coding - Input: an alphabet with frequencies - Output: a prefix-free code - Objective: minimize expected number of bits per character

  9. Problem: Huffman Coding 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” Huffman coding - Input: an alphabet with frequencies - Output: a prefix-free code - Objective: minimize expected number of bits per character

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

  11. Problem: Huffman Coding Lemma 1: 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 2: If w is a longest codeword in an optimal code then there exists another codeword of the same length.

  12. Problem: Huffman Coding Lemma 1: 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 2: If w is a longest codeword in an optimal code then there exists another codeword of the same length. Lemma 3: 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.

  13. Problem: Huffman Coding Lemma 1: 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 2: If w is a longest codeword in an optimal code then there exists another codeword of the same length. Lemma 3: 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. Theorem: The prefix code output by the Huffman algorithm is optimal.

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend