160 likes | 379 Views
Giving credit where credit is due:Most of slides for this lecture are based on slides created by Dr. Richard Anderson, University of Washington.I have modified them and added new slides. CSCE 310 Data Structures
E N D
1. CSCE 310 Data Structures & Algorithms
2. Giving credit where credit is due:
Most of slides for this lecture are based on slides created by Dr. Richard Anderson, University of Washington.
I have modified them and added new slides CSCE 310 Data Structures & Algorithms
3. Coding theory ASCII coding
Conversion, Encryption, Compression
Binary coding
4. Coding theory (cont.) ASCII coding
Conversion, Encryption, Compression
Binary coding
5. Coding theory (cont.) ASCII coding
Conversion, Encryption, Compression
Binary coding
Variable length coding
Average bits/character = 2*0.3+3*0.1+3*0.1+3*0.1+2*0.3+3*0.1=2.4
Compression Ratio = (3-2.4)/3=20%Average bits/character = 2*0.3+3*0.1+3*0.1+3*0.1+2*0.3+3*0.1=2.4
Compression Ratio = (3-2.4)/3=20%
6. Decode the following
7. Prefix(-free) codes No prefix of a codeword is a codeword
Uniquely decodable
8. Prefix codes and binary trees Tree representation of prefix codes
9. Construct the tree for the following code
10. Minimum length code
11. Minimum length code (cont.) Average leaf depth
Huffman tree – tree with minimum weighted path length
C(T) – weighted path length
12. Compute average leaf depth (weighted path length) 1/4*2+1/8*3+1/16*4+1/16*4+1/2*1=1.8751/4*2+1/8*3+1/16*4+1/16*4+1/2*1=1.875
13. 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
14. Huffman code
15. Example
16. In-class exercises P332 Exercises 9.4.1
17. In-class exercises 9.4.4 What is the maximal length of a codeword possible in a Huffman encoding of an alphabet of n characters?
9.4.6 Show that a Huffman tree can be constructed in linear time if the alphabet’s characters are given in a sorted order of their frequencies.