Presentation is loading. Please wait.

Presentation is loading. Please wait.

Dynamic Huffman Coding Computer Networks Assignment.

Similar presentations


Presentation on theme: "Dynamic Huffman Coding Computer Networks Assignment."— Presentation transcript:

1 Dynamic Huffman Coding Computer Networks Assignment

2 2 T Stage 1 (First occurrence of t ) Stage 1 (First occurrence of t ) r / \ / \ 0 t(1) 0 t(1) Order: 0,t(1) Order: 0,t(1) * r represents the root * 0 represents the null node * t(1) denotes the occurrence of T with a frequency of 1

3 3 TE Stage 2 (First occurrence of e) Stage 2 (First occurrence of e) r / \ / \ 1 t(1) 1 t(1) / \ / \ 0 e(1) 0 e(1) Order: 0,e(1),1,t(1) Order: 0,e(1),1,t(1)

4 4 TEN Stage 3 (First occurrence of n ) Stage 3 (First occurrence of n ) r / \ / \ 2 t(1) 2 t(1) / \ / \ 1 e(1) 1 e(1) / \ / \ 0 n(1) 0 n(1) Order: 0,n(1),1,e(1),2,t(1) : Misfit Order: 0,n(1),1,e(1),2,t(1) : Misfit

5 5 Reorder: TEN r / \ / \ t(1) 2 t(1) 2 / \ / \ 1 e(1) 1 e(1) / \ / \ 0 n(1) 0 n(1) Order: 0,n(1),1,e(1),t(1),2 Order: 0,n(1),1,e(1),t(1),2

6 6 TENN Stage 4 ( Repetition of n ) Stage 4 ( Repetition of n ) r / \ / \ t(1) 3 t(1) 3 / \ / \ 2 e(1) 2 e(1) / \ / \ 0 n(2) 0 n(2) Order: 0,n(2),2,e(1),t(1),3 : Misfit Order: 0,n(2),2,e(1),t(1),3 : Misfit

7 7 Reorder: TENN r / \ / \ n(2) 2 n(2) 2 / \ / \ 1 e(1) 1 e(1) / \ / \ 0 t(1) 0 t(1) Order: 0,t(1),1,e(1),n(2),2 Order: 0,t(1),1,e(1),n(2),2 t(1),n(2) are swapped t(1),n(2) are swapped

8 8 TENNE Stage 5 (Repetition of e ) Stage 5 (Repetition of e ) r / \ / \ n(2) 3 n(2) 3 / \ / \ 1 e(2) 1 e(2) / \ / \ 0 t(1) 0 t(1) Order: 0,t(1),1,e(2),n(2),3 Order: 0,t(1),1,e(2),n(2),3

9 9 TENNES Stage 6 (First occurrence of s) Stage 6 (First occurrence of s) r / \ / \ n(2) 4 n(2) 4 / \ / \ 2 e(2) 2 e(2) / \ / \ 1 t(1) 1 t(1) / \ / \ 0 s(1) 0 s(1) Order: 0,s(1),1,t(1),2,e(2),n(2),4 Order: 0,s(1),1,t(1),2,e(2),n(2),4

10 10 TENNESS Stage 7 (Repetition of s) Stage 7 (Repetition of s) r / \ / \ n(2) 5 n(2) 5 / \ / \ 3 e(2) 3 e(2) / \ / \ 2 t(1) 2 t(1) / \ / \ 0 s(2) 0 s(2) Order: 0,s(2),2,t(1),3,e(2),n(2),5 : Misfit Order: 0,s(2),2,t(1),3,e(2),n(2),5 : Misfit

11 11 Reorder: TENNESS r / \ / \ n(2) 5 n(2) 5 / \ / \ 3 e(2) 3 e(2) / \ / \ 1 s (2) 1 s (2) / \ / \ 0 t(1) 0 t(1) Order : 0,t(1),1,s(2),3,e(2),n(2),5 Order : 0,t(1),1,s(2),3,e(2),n(2),5 s(2) and t(1) are swapped s(2) and t(1) are swapped

12 12 TENNESSE Stage 8 (Second repetition of e ) Stage 8 (Second repetition of e ) r / \ / \ n(2) 6 n(2) 6 / \ / \ 3 e(3) 3 e(3) / \ / \ 1 s(2) 1 s(2) / \ / \ 0 t(1) 0 t(1) Order : 0,t(1),1,s(2),3,e(3),n(2),6 : Misfit Order : 0,t(1),1,s(2),3,e(3),n(2),6 : Misfit

13 13 Reorder: TENNESSE r / \ / \ e(3) 5 e(3) 5 / \ / \ 3 n(2) 3 n(2) / \ / \ 1 s(2) 1 s(2) / \ / \ 0 t(1) 0 t(1) Order : 1,t(1),1,s(2),3,n(2),e(3),5 Order : 1,t(1),1,s(2),3,n(2),e(3),5 N(2) and e(3) are swapped N(2) and e(3) are swapped

14 14 TENNESSEE Stage 9 (Second repetition of e ) Stage 9 (Second repetition of e ) r 0 / \ 1 0 / \ 1 e(4) 5 e(4) 5 0 / \ 1 0 / \ 1 3 n(2) 3 n(2) 0 / \ 1 0 / \ 1 1 s(2) 1 s(2) 0 / \ 1 0 / \ 1 0 t(1) 0 t(1) Order : 1,t(1),1,s(2),3,n(2),e(4),5 Order : 1,t(1),1,s(2),3,n(2),e(4),5

15 15 ENCODING The letters can be encoded as follows: e : 0 e : 0 n : 11 n : 11 s : 101 s : 101 t : 1001 t : 1001

16 16 Average Code Length Average code length =  i=0,n (length*frequency)/  i=0,n frequency Average code length =  i=0,n (length*frequency)/  i=0,n frequency = { 1(4) + 2(2) + 3(2) + 1(4) } / (4+2+2+1) = { 1(4) + 2(2) + 3(2) + 1(4) } / (4+2+2+1) = 18 / 9 = 2 = 18 / 9 = 2

17 17 ENTROPY Entropy = -  i=1, n (p i log 2 p i ) Entropy = -  i=1, n (p i log 2 p i ) = - ( 0.44 * log 2 0.44 + 0.22 * log 2 0.22 = - ( 0.44 * log 2 0.44 + 0.22 * log 2 0.22 + 0.22 * log 2 0.22 + 0.11 * log 2 0.11 ) + 0.22 * log 2 0.22 + 0.11 * log 2 0.11 ) = - (0.44 * log0.44 + 2(0.22 * log0.22 + 0.11 * log0.11) = - (0.44 * log0.44 + 2(0.22 * log0.22 + 0.11 * log0.11) / log2 / log2 = 1.8367 = 1.8367

18 18 Ordinary Huffman Coding TENNESSE TENNESSE 9 0 / \ 1 0 / \ 1 5 e(4) 5 e(4) 0 / \ 1 0 / \ 1 s(2) 3 s(2) 3 0 / \ 1 0 / \ 1 t(1) n(2) t(1) n(2) ENCODING E : 1 S : 00 T : 010 N : 011 Average code length = (1*4 + 2*2 + 2*3 + 3*1) / 9 = 1.89

19 19 SUMMARY The average code length of ordinary Huffman coding seems to be better than the Dynamic version,in this exercise. The average code length of ordinary Huffman coding seems to be better than the Dynamic version,in this exercise. But, actually the performance of dynamic coding is better. The problem with static coding is that the tree has to be constructed in the transmitter and sent to the receiver. The tree may change because the frequency distribution of the English letters may change in plain text technical paper, piece of code etc. But, actually the performance of dynamic coding is better. The problem with static coding is that the tree has to be constructed in the transmitter and sent to the receiver. The tree may change because the frequency distribution of the English letters may change in plain text technical paper, piece of code etc. Since the tree in dynamic coding is constructed on the receiver as well, it need not be sent. Considering this, Dynamic coding is better. Since the tree in dynamic coding is constructed on the receiver as well, it need not be sent. Considering this, Dynamic coding is better. Also, the average code length will improve if the transmitted text is bigger. Also, the average code length will improve if the transmitted text is bigger.


Download ppt "Dynamic Huffman Coding Computer Networks Assignment."

Similar presentations


Ads by Google