1 / 9

Trees

Trees. Addenda. Huffman Codes. ASCII, EBCDIC (IBM Mainframes) & Unicode use 8 bits for all characters Morse code, others variable-length sequences. Variable-Length Codes. Each character has: Has a weight (a probability of ocurrence) A length Expected length of a string:

melchior
Download Presentation

Trees

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. Trees Addenda

  2. Huffman Codes • ASCII, EBCDIC (IBM Mainframes) & Unicode use 8 bits for all characters • Morse code, others • variable-length sequences

  3. Variable-Length Codes • Each character has: • Has a weight (a probability of ocurrence) • A length • Expected length of a string: • sum of the products of the weights and lengths of all characters in string ABCDE = 0.2 x 2 + 0.1 x 4 + 0.1 x 4 + 0.15 x 3 + 0.45 x 1 = 2.1

  4. Decoding • Examine code string • When complete sequence found • Announce recognition of the character • Start decoding next character

  5. Immediate Decodability • No code sequence is a prefix of another code (i.e.; every code has a unique start) • Can be decoded without waiting for remaining bits Must decode whole stringD is a prefix of B NO YES

  6. Huffman Codes • Immediately decodable • Minimal code length • Need an algorithm • Builds n-bit codes

  7. Huffman Encoding • Initialize list of n one-node binary trees T with a weight for each character • Do the following n – 1 times • Find two trees T' and T" in list with minimal weights w' and w" • Replace these two with 1 binary tree whose root is w'+ w" and whose subtrees are T' and T" • label the subtree edges: 0 and 1 • the code for character Ci is the bit string of labels from the root to Ci

  8. Huffman Encoding (Example) • Value of each parent=sum of children 1 0 1 .55 0 1 .2 .35 1 0 1 0 .1 .1 .15 .2 .45 B C D A E

  9. Huffman Decoding • Initialize pointer p to root of Huffman tree • While not end of message string: • a. Let xbe next bit in string • b. if x = 0 set p = left child pointer else set p = right child pointer • c. If p points to leaf • Display character with that leaf • Reset p to root of Huffman tree e.g.; code string: 0001011010 B E A D

More Related