1 / 15

RAIK 283 Data Structures & Algorithms

RAIK 283 Data Structures & Algorithms. Huffman Coding Dr. Ying Lu ylu@cse.unl.edu. RAIK 283 Data Structures & Algorithms. Giving credit where credit is due: Most of slides for this lecture are based on slides created by Dr. Richard Anderson, University of Washington.

gwyn
Download Presentation

RAIK 283 Data Structures & Algorithms

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. RAIK 283 Data Structures & Algorithms Huffman Coding Dr. Ying Lu ylu@cse.unl.edu

  2. RAIK 283 Data Structures & Algorithms • 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

  3. Coding theory Code examples 000,001,010,011,100,101 1,01,001,0001,00001,000001 00,010,011,100,11,101 • ASCII coding • Conversion, Encryption, Compression • Binary coding For fixed-length binary coding of a 6-character alphabet, how many bits are needed?

  4. Coding theory (cont.) Code examples 000,001,010,011,100,101 1,01,001,0001,00001,000001 00,010,011,100,11,101 • ASCII coding • Conversion, Encryption, Compression • Binary coding

  5. Coding theory (cont.) Code examples 000,001,010,011,100,101 1,01,001,0001,00001,000001 00,010,011,100,11,101 Probability • ASCII coding • Conversion, Encryption, Compression • Binary coding • Variable length coding Average bits/character = ? Compression Ratio = ?

  6. Decode the following 11010010010101011 100100101010 Prefix code Ambiguous

  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 0 1 0 1 1 0 F A 0 1 E B 0 1 D C

  9. Minimum length code How to code so that average bits/character is minimized? Probability

  10. Minimum length code (cont.) • Huffman tree – prefix codes tree with minimum weighted path length • C(T) – weighted path length

  11. 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

  12. Huffman code H = new minHeap() 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)

  13. Example 21 14 11 6 7 4 5

  14. In-class exercises • P332 Exercises 9.4.1

  15. In-class exercises • 9.4.3 What is the maximal length of a codeword possible in a Huffman encoding of an alphabet of n characters? • 9.4.5 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.

More Related