Dynamic Huffman Coding: Computer Networks Assignment
Dynamic Huffman Coding: Computer Networks Assignment
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
TE
TEN
Reorder: TEN
r
Order: 0,n(1),1,e(1),t(1),2
5
TENN
Reorder: TENN
r
TENNE
TENNES
TENNESS
Reorder: TENNESS
r
TENNESSE
Stage 8 (Second repetition of e ) r / \ n(2) 6 / \ 3 e(3) / \ 1 s(2) / \ 0 t(1) Order : 0,t(1),1,s(2),3,e(3),n(2),6 : Misfit
12
Reorder: TENNESSE
r
TENNESSEE
Order : 1,t(1),1,s(2),3,n(2),e(4),5
14
ENCODING
The letters can be encoded as follows:
15
16
ENTROPY
Entropy = -i=1,n (pi log2 pi)
= - ( 0.44 * log20.44 + 0.22 * log20.22 + 0.22 * log20.22 + 0.11 * log20.11 ) = - (0.44 * log0.44 + 2(0.22 * log0.22 + 0.11 * log0.11) / log2 = 1.8367
17
18
SUMMARY
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. 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.
19