Presentation is loading. Please wait.

Presentation is loading. Please wait.

The Huffman Algorithm We use Huffman algorithm to encode a long message as a long bit string - by assigning a bit string code to each symbol of the alphabet.

Similar presentations


Presentation on theme: "The Huffman Algorithm We use Huffman algorithm to encode a long message as a long bit string - by assigning a bit string code to each symbol of the alphabet."— Presentation transcript:

1 The Huffman Algorithm We use Huffman algorithm to encode a long message as a long bit string - by assigning a bit string code to each symbol of the alphabet and - concatenating the individual codes of the symbols making up the message. Example: Alphabet consists of the four symbols A, B, C, D. Symbol Code A B C D The message ABACD would be encoded as Such encoding is inefficient.

2 The Huffman Algorithm If we examine any message, we will see that some letters appear more frequently than others. If the frequently appeared letters are assigned shorter bit strings, then the length of the encoded message will be substantially reduced. Symbol Code A B C D The message ABACD would be encoded as Such encoding is efficient.

3 Huffman Tree The message is ABACCDA Choose two symbols with
smallest frequency ( B and D). Combine these two symbols into the single symbol BD of frequency 2. Next two symbols with smallest frequency are C and BD 0 is assigned for left branch 1 is assigned for right branch ACBD, 7 1 CBD, 4 A, 3 1 C, 2 BD, 2 1 Symbol code A B C D B, 1 D, 1

4 Huffman Algorithm Generally, codes are not constructed on the basis of the frequency of characters within a single massage alone. Codes are constructed on the basis of their frequency within a whole set of messages. The same code set is then used for each message. For example, if messages consists of English words, the known relative frequency of occurrence of the letters of the alphabet in English language might be used. The relative frequency of the letters in any single message is not necessarily the same.


Download ppt "The Huffman Algorithm We use Huffman algorithm to encode a long message as a long bit string - by assigning a bit string code to each symbol of the alphabet."

Similar presentations


Ads by Google