COM347J1/COM552J1 Networks and Data

advertisement
COM342
Networks and Data Communications
Lecture 4B: Further examples of Huffman
codes (Data Compression)
Ian McCrum
Room 5B18
Tel: 90 366364 voice mail on 6th ring
Email: IJ.McCrum@Ulster.ac.uk
Web site: http://www.eej.ulst.ac.uk
http://www.eej.ulst.ac.uk/~ian/modules/COM342
COM342_L4B 1/8
Decoding Huffman codes
Given the Huffman
1
0
Tree on the left decode the
pattern
A
0
1
C
0011100
B
0 0 11 10 0
A A B C A
http://www.eej.ulst.ac.uk/~ian/modules/COM342
COM342_L4B 2/8
Another example of generating Huffman
trees and codes
e.g Consider just the six letters below and their
frequencies in a large message, placed in ascending order!
E
0.1250
T
0.0925
A
0.0805
O
0.0760
I
0.0729
N
0.0710
We are going to pick the least two
frequent and add their probabilities
together, then remove the two and
insert the new combined probability
up the list, the list is now shorter.
We repeat for the next two least
frequent and the list gets shorter
again. Until we have a single total.
http://www.eej.ulst.ac.uk/~ian/modules/COM342
COM342_L4B 3/8
E= .1250
0
.2175
T= .0925
1
A= .0805
0
O= .0760
.5179
.1565
1
0
I= .0729
N= .0710
0
.1439
0
1
.3004
1
1
Hence A=100, E=00, I=110, N=111, O=101 and T=01
http://www.eej.ulst.ac.uk/~ian/modules/COM342
COM342_L4B 4/8
Given the tree code …EATANIT
Given A=100, E=00, I=110, N=111, O=101 and T=01
E
T
A
O
0
1
0
0
1
0
I
0
N
1
1
1
00 100 01 100 111 110 01
we would need a 3 bit code if size was fixed. Here we managed to send 18
bits instead of 21 bits so we get a 16% saving in message length.
http://www.eej.ulst.ac.uk/~ian/modules/COM342
COM342_L4B 5/8
Given the tree decode
1001110100111111100
A
N
T E
E
O
N
A
0
T
A
N
1
0
0
1
0
I
0
N
1
1
1
http://www.eej.ulst.ac.uk/~ian/modules/COM342
COM342_L4B 6/8
Tutorial Question
•
The five vowels have a frequency as
follows (A=0.3, E=0.3, I=0.15, O=0.15
and U=0.1)
1. Derive a huffman code for these.
2. Code the sequence AEIOUIOU
3. Write down a binary pattern using your
codes and decode it, NB only pick codes
from your calculated set
http://www.eej.ulst.ac.uk/~ian/modules/COM342
COM342_L4B 7/8
Download