Create Presentation
Download Presentation

Download Presentation
## Huffman Encoding Example

- - - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - - -

**Huffman Encoding Example**Prepared by: Yamen Nasrallah Presented to : Professor Abdulmotaleb El Saddik ELG 5121: Multimedia Communications September 2009 ELG5121_Multimedia communications**Huffman encoding of the word : The theatre**• The Goal • In order to complete the encoding, we should construct a binary tree with nodes containing the characters and weights associated to them • First step • We’ll give each character a weight which is the number of its occurrence in the word • Second step • Select two nodes with smallest weight • Third step • Create a new node which is the parent of the previous 2 nodes. The new node’s weight is equal to the sum of the weights of the previous node • Fourth step • We repeat the same process until one node is left ELG5121_Multimedia communications**Huffman encoding of the word : The theatre**• First step • Third step • Fourth step • Second step 4 T ““ t a r h 4 7 2 2 T “ “te T “ “ a r 11 h t a e r 1 3 1 1 1 T “ “ ELG5121_Multimedia communications**Huffman encoding of the word : The theatre**• Fifth step • We assign the binary value “0 “ to the branches to the left, and the binary value “1 “ to the branches to the right • Sixth step • We assign to each character the proper code 0 1 0 1 0 1 0 1 h t a e r 0 0 1 1 T “ “ ELG5121_Multimedia communications**Huffman encoding of the word : The theatre**• We could build the tree in a different way as the following: 4 0 1 6 5 h t 0 1 0 1 2 2 h t 2 2 T “ “ a r e a 3 T 1 1 1 1 0 1 0 1 0 1 r “ “ ELG5121_Multimedia communications**Huffman encoding of the word : The theatre**• Based on the first code scheme, the encoding of the word “The theatre” is: • “010010000101011100011001111100”. (30 bits) • Based on the second code scheme, the encoding of the word “The theatre” is: • “010000110110010001110000110111” (30 bits) • So, in both ways the same number of bits (30 bits) is required to encode the same word. Which means that there are several ways to encode the same text with Huffman encoding method, and all the ways will lead to the optimal encoding solution. • But, what is the main difference between the two ways???? • In the first method, the letter “T” is presented by 4 bits and “h” by 2 bits. However, in the second method, “T” is presented by 3 bits and “h” by 3 bits. And the number of occurrence of “h” is bigger than the number of occurrence of “T”, so in terms of memory and storage capacity, it is better to use the first way instead of the second, because in this case the memory that will be allocated for “h” (which will be used much more than “T”) is smaller. ELG5121_Multimedia communications**Huffman encoding of the word : The theatre**Thank You ELG5121_Multimedia communications