Lecture19 PDF
Lecture19 PDF
1
LZW Encoding Example (4) LZW Encoding Example (5)
Dictionary Dictionary
ababababa ababababa
0 a 01 2 0 a 01 2 4
1 b 1 b
2 ab 2 ab
3 ba 3 ba
4 aba 4 aba
5 abab
2
LZW Decoding Example (2b) LZW Decoding Example (3a)
Dictionary Dictionary
012436 012436
0 a a b 0 a a ba
1 b 1 b
2 ab 2 ab
3 b? 3 ba
3
LZW Decoding Example (5b) LZW Decoding Example (6a)
Dictionary Dictionary
012436 012436
0 a a b ab aba ba 0 a a b ab aba ba b
1 b 1 b
2 ab 2 ab
3 ba 3 ba
4 aba 4 aba
5 abab 5 abab
6 ba? 6 bab
4
Encoder Uses a Trie (2) Decoder’s Data Structure
0 1 2 3 4 • Simply an array of strings
a b c d r
0 a 9 ca
b 5 c 8 d 10 r 6 a 9 a 11 a 7 1 b 10 ad
2 c 11 da 0 1 4 0 2 0 3 5 7 12 8 ...
r 12 a 15 a 13 3 d 12 abr a b r a c a d ab ra abr
4 r 13 raa
5 ab 14 abr?
a 14
6 br
7 ra
abracadabraabracadabra 8 ac
0 1 4 0 2 0 3 5 7 12 8
abracadabraabracadabra
Most Recent 0 1 4 0 2 0 3 5 7 12 8
5
LZ77 Solution A
• Ziv and Lempel, 1977 • If xn+1xn+2...xn+k is a substring of x1x2...xn then
• Dictionary is implicit xn+1xn+2...xn+k can be coded by <j,k> where j is
• Use the string coded so far as a dictionary. the beginning of the match.
• Given that x1x2...xn has been coded we want • Example
to code xn+1xn+2...xn+k for the largest k ababababa babababababababab....
possible. coded
ababababa babababa babababab....
<2,8>
6
Surprise Decoding Surprise Decoding
<0,0,a><0,0,b><1,22,$> <0,0,a><0,0,b><1,22,$>
<0,0,a> a <0,0,a> a
<0,0,b> b <0,0,b> b
<1,22,$> a <1,22,$> a
<2,21,$> b <2,21,$> b
<3,20,$> a <3,20,$> a
<4,19,$> b <4,19,$> b
... ...
<22,1,$> b <22,1,$> b
<23,0,$> $ <23,0,$> $
7
Coding Example Coding the Tuples
s = 4, t = 4, a = 3
• Simple fixed length code
tuple log2 (s + 1) + log2 (s + t + 1) + log2a
aaaabababaaab$ <0,0,a>
aaaabababaaab$ <1,3,b> tuple fixed code
s = 4, t = 4, a = 3
aaaabababaaab$ <2,5,a> 010 0101 00
<2,5,a>
aaaabababaaab$ <4,2,$> • Variable length code using adaptive Huffman
or arithmetic code on Tuples
– Two passes, first to create the tuples, second to
code the tuples
– One pass, by pipelining tuples into a variable
length coder
Dictionary Data Compression - Lecture 19 43 Dictionary Data Compression - Lecture 19 44
15 14 10 2 1