the lempel ziv algorithm - tuxtina.de · lz78 (1) •maintain explicit dictionary •gradually...
TRANSCRIPT
![Page 2: The Lempel Ziv Algorithm - tuxtina.de · LZ78 (1) •Maintain explicit dictionary •Gradually build dictionary during encoding •Codeword consists of 2 elements: –index (reference](https://reader033.vdocuments.us/reader033/viewer/2022060500/5f1aa893f6f7e44297023926/html5/thumbnails/2.jpg)
The (?) Lempel Ziv Algorithm
LZ77 LZ78LZR
LZSS LZBLZH LZWLZC
LZTLZMW
LZJLZFG
Applications:• zip• gzip• Stacker• ...
Applications:• GIF• V.42• compress• ...
![Page 3: The Lempel Ziv Algorithm - tuxtina.de · LZ78 (1) •Maintain explicit dictionary •Gradually build dictionary during encoding •Codeword consists of 2 elements: –index (reference](https://reader033.vdocuments.us/reader033/viewer/2022060500/5f1aa893f6f7e44297023926/html5/thumbnails/3.jpg)
Overview• Introduction• Lossless Compression• Dictionary Coding• LZ77
– Algorithm– Modifications– Comparison
• LZ78– Algorithm– Modifications– Comparison
![Page 4: The Lempel Ziv Algorithm - tuxtina.de · LZ78 (1) •Maintain explicit dictionary •Gradually build dictionary during encoding •Codeword consists of 2 elements: –index (reference](https://reader033.vdocuments.us/reader033/viewer/2022060500/5f1aa893f6f7e44297023926/html5/thumbnails/4.jpg)
Data Compression
O
The eldest of these, and Bilbo’s favourite, was young FrodoBaggins. When Bilbo was ninety-nine he adopted Frodo as hisheir, and brought him to live at Bag End; and the hopes of theSackville- Bagginses were finally dashed. Bilbo and Frodohappened to have the same birthday, September 22nd. ‘You hadbetter come and live here, Frodo my lad,’ said Bilbo one day; ‘andthen we can celebrate our birthday-parties comfortably together.’At that time Frodo was still in his tweens, as the hobbits calledthe irresponsible twenties between childhood and coming of ageat thirty-three.
• Data shows patterns, constraints, ...• Compression algorithms exploit those
characteristics to reduce size
![Page 5: The Lempel Ziv Algorithm - tuxtina.de · LZ78 (1) •Maintain explicit dictionary •Gradually build dictionary during encoding •Codeword consists of 2 elements: –index (reference](https://reader033.vdocuments.us/reader033/viewer/2022060500/5f1aa893f6f7e44297023926/html5/thumbnails/5.jpg)
Lossless Compression
• Run-length coding• Statistical methods
– Huffman coding– Arithmetic coding– PPM
• Dictionary methods– Lempel Ziv algorithms
Lossless compression guarantees that the originalinformation can be exactly reproduced from thecompressed data.
![Page 6: The Lempel Ziv Algorithm - tuxtina.de · LZ78 (1) •Maintain explicit dictionary •Gradually build dictionary during encoding •Codeword consists of 2 elements: –index (reference](https://reader033.vdocuments.us/reader033/viewer/2022060500/5f1aa893f6f7e44297023926/html5/thumbnails/6.jpg)
Dictionary Coding (1)• Observation: Correlations between parts of
the data (patterns)• Idea: Replace recurring patterns with
references to a dictionary• Static, semi-adaptive, adaptive• LZ algorithms use adaptive approach¸coding scheme is universal¸no need to transmit/store dictionary¸single-pass (dictionary creation “on-the-fly”)
![Page 7: The Lempel Ziv Algorithm - tuxtina.de · LZ78 (1) •Maintain explicit dictionary •Gradually build dictionary during encoding •Codeword consists of 2 elements: –index (reference](https://reader033.vdocuments.us/reader033/viewer/2022060500/5f1aa893f6f7e44297023926/html5/thumbnails/7.jpg)
Dictionary Coding (2)
The eldest of these, and Bilbo’s favourite, was young FrodoBaggins. When Bilbo was ninety-nine he adopted Frodo as hisheir, and brought him to live at Bag End; and the hopes of theSackville- Bagginses were finally dashed. Bilbo and Frodo ...
• Keep explicit dictionary(LZ78 algorithm)
BilboFrodowas...
![Page 8: The Lempel Ziv Algorithm - tuxtina.de · LZ78 (1) •Maintain explicit dictionary •Gradually build dictionary during encoding •Codeword consists of 2 elements: –index (reference](https://reader033.vdocuments.us/reader033/viewer/2022060500/5f1aa893f6f7e44297023926/html5/thumbnails/8.jpg)
Dictionary Coding (3)
The eldest of these, and Bilbo’s favourite, was young FrodoBaggins. When Bilbo was ninety-nine he adopted Frodo as hisheir, and brought him to live at Bag End; and the hopes of theSackville- Bagginses were finally dashed. Bilbo and Frodo ...
• Use previously processed data asdictionary (LZ77 algorithm)
![Page 9: The Lempel Ziv Algorithm - tuxtina.de · LZ78 (1) •Maintain explicit dictionary •Gradually build dictionary during encoding •Codeword consists of 2 elements: –index (reference](https://reader033.vdocuments.us/reader033/viewer/2022060500/5f1aa893f6f7e44297023926/html5/thumbnails/9.jpg)
a b c b b a c d e b b a d e a a ...
LZ77 (1)
![Page 10: The Lempel Ziv Algorithm - tuxtina.de · LZ78 (1) •Maintain explicit dictionary •Gradually build dictionary during encoding •Codeword consists of 2 elements: –index (reference](https://reader033.vdocuments.us/reader033/viewer/2022060500/5f1aa893f6f7e44297023926/html5/thumbnails/10.jpg)
LZ77 (1)
![Page 11: The Lempel Ziv Algorithm - tuxtina.de · LZ78 (1) •Maintain explicit dictionary •Gradually build dictionary during encoding •Codeword consists of 2 elements: –index (reference](https://reader033.vdocuments.us/reader033/viewer/2022060500/5f1aa893f6f7e44297023926/html5/thumbnails/11.jpg)
LZ77 (1)
Match: “bba”Position: 3Length: 3Next symbol: ‘d’Output: (3, 3, ‘d’)
a b c b b a c d e b b a d e a a ...
![Page 12: The Lempel Ziv Algorithm - tuxtina.de · LZ78 (1) •Maintain explicit dictionary •Gradually build dictionary during encoding •Codeword consists of 2 elements: –index (reference](https://reader033.vdocuments.us/reader033/viewer/2022060500/5f1aa893f6f7e44297023926/html5/thumbnails/12.jpg)
LZ77 (1)
Match: “bba”Position: 3Length: 3Next symbol: ‘d’Output: (3, 3, ‘d’)
a b c b b a c d e b b a d e a a ...
window
• Memory / speed constraints require restrictions! use a fixed-size window (“sliding window”principle)
![Page 13: The Lempel Ziv Algorithm - tuxtina.de · LZ78 (1) •Maintain explicit dictionary •Gradually build dictionary during encoding •Codeword consists of 2 elements: –index (reference](https://reader033.vdocuments.us/reader033/viewer/2022060500/5f1aa893f6f7e44297023926/html5/thumbnails/13.jpg)
LZ77 (1)search buffer lookahead buffer Match: “bba”
Position: 3Length: 3Next symbol: ‘d’Output: (3, 3, ‘d’)
a b c b b a c d e b b a d e a a ...
window
• Memory / speed constraints require restrictions! use a fixed-size window (“sliding window”principle)
![Page 14: The Lempel Ziv Algorithm - tuxtina.de · LZ78 (1) •Maintain explicit dictionary •Gradually build dictionary during encoding •Codeword consists of 2 elements: –index (reference](https://reader033.vdocuments.us/reader033/viewer/2022060500/5f1aa893f6f7e44297023926/html5/thumbnails/14.jpg)
LZ77 (2)while (lookAheadBuffer not empty) {
get a reference (position ,length) to longest match;
if (length > 0) {
output (position, length, next symbol);
shift the window length+1 positions along;
} else {
output (0, 0, first symbol in lookahead buffer);
shift the window 1 position along;
}
}
![Page 15: The Lempel Ziv Algorithm - tuxtina.de · LZ78 (1) •Maintain explicit dictionary •Gradually build dictionary during encoding •Codeword consists of 2 elements: –index (reference](https://reader033.vdocuments.us/reader033/viewer/2022060500/5f1aa893f6f7e44297023926/html5/thumbnails/15.jpg)
LZ77 ExampleS = 0 0 1 0 1 0 2 1 0 2 1 0 2 1 2 0 2 1 0 2 1 2 0 0 . . .a = 3 (size of alphabet)Ls = 9 (lookahead buffer size)n = 18 (window size)
Codeword length:Lc = 1 + loga(n - Ls) + loga(Ls)
= 1 + log3(9) + log3(9)= 5
![Page 16: The Lempel Ziv Algorithm - tuxtina.de · LZ78 (1) •Maintain explicit dictionary •Gradually build dictionary during encoding •Codeword consists of 2 elements: –index (reference](https://reader033.vdocuments.us/reader033/viewer/2022060500/5f1aa893f6f7e44297023926/html5/thumbnails/16.jpg)
LZ77 Example – Encoder0 0 0 0 0 0 0 0 0 0 0 1 0 1 0 2 1 0 2 1 . . .1.
2.
3.
4.
![Page 17: The Lempel Ziv Algorithm - tuxtina.de · LZ78 (1) •Maintain explicit dictionary •Gradually build dictionary during encoding •Codeword consists of 2 elements: –index (reference](https://reader033.vdocuments.us/reader033/viewer/2022060500/5f1aa893f6f7e44297023926/html5/thumbnails/17.jpg)
C1=22 02 1
LZ77 Example – Encoder0 0 0 0 0 0 0 0 0 0 0 1 0 1 0 2 1 0 2 1 . . .1.
2.
3.
4.
![Page 18: The Lempel Ziv Algorithm - tuxtina.de · LZ78 (1) •Maintain explicit dictionary •Gradually build dictionary during encoding •Codeword consists of 2 elements: –index (reference](https://reader033.vdocuments.us/reader033/viewer/2022060500/5f1aa893f6f7e44297023926/html5/thumbnails/18.jpg)
C1=22 02 1
LZ77 Example – Encoder0 0 0 0 0 0 0 0 0 0 0 1 0 1 0 2 1 0 2 1 . . .1.
2. 0 0 0 0 0 0 0 0 1 0 1 0 2 1 0 2 1 0 2 1 . . .
3.
4.
![Page 19: The Lempel Ziv Algorithm - tuxtina.de · LZ78 (1) •Maintain explicit dictionary •Gradually build dictionary during encoding •Codeword consists of 2 elements: –index (reference](https://reader033.vdocuments.us/reader033/viewer/2022060500/5f1aa893f6f7e44297023926/html5/thumbnails/19.jpg)
C2=21 11 2
C1=22 02 1
LZ77 Example – Encoder0 0 0 0 0 0 0 0 0 0 0 1 0 1 0 2 1 0 2 1 . . .1.
2. 0 0 0 0 0 0 0 0 1 0 1 0 2 1 0 2 1 0 2 1 . . .
3.
4.
![Page 20: The Lempel Ziv Algorithm - tuxtina.de · LZ78 (1) •Maintain explicit dictionary •Gradually build dictionary during encoding •Codeword consists of 2 elements: –index (reference](https://reader033.vdocuments.us/reader033/viewer/2022060500/5f1aa893f6f7e44297023926/html5/thumbnails/20.jpg)
C2=21 11 2
C1=22 02 1
LZ77 Example – Encoder0 0 0 0 0 0 0 0 0 0 0 1 0 1 0 2 1 0 2 1 . . .1.
2. 0 0 0 0 0 0 0 0 1 0 1 0 2 1 0 2 1 0 2 1 . . .
3. 0 0 0 0 1 0 1 0 2 1 0 2 1 0 2 1 2 0 2 1 . . .
4.
![Page 21: The Lempel Ziv Algorithm - tuxtina.de · LZ78 (1) •Maintain explicit dictionary •Gradually build dictionary during encoding •Codeword consists of 2 elements: –index (reference](https://reader033.vdocuments.us/reader033/viewer/2022060500/5f1aa893f6f7e44297023926/html5/thumbnails/21.jpg)
C3=20 21 2
C2=21 11 2
C1=22 02 1
LZ77 Example – Encoder0 0 0 0 0 0 0 0 0 0 0 1 0 1 0 2 1 0 2 1 . . .1.
2. 0 0 0 0 0 0 0 0 1 0 1 0 2 1 0 2 1 0 2 1 . . .
3. 0 0 0 0 1 0 1 0 2 1 0 2 1 0 2 1 2 0 2 1 . . .
4.
![Page 22: The Lempel Ziv Algorithm - tuxtina.de · LZ78 (1) •Maintain explicit dictionary •Gradually build dictionary during encoding •Codeword consists of 2 elements: –index (reference](https://reader033.vdocuments.us/reader033/viewer/2022060500/5f1aa893f6f7e44297023926/html5/thumbnails/22.jpg)
C3=20 21 2
C2=21 11 2
C1=22 02 1
LZ77 Example – Encoder0 0 0 0 0 0 0 0 0 0 0 1 0 1 0 2 1 0 2 1 . . .1.
2. 0 0 0 0 0 0 0 0 1 0 1 0 2 1 0 2 1 0 2 1 . . .
3. 0 0 0 0 1 0 1 0 2 1 0 2 1 0 2 1 2 0 2 1 . . .
4. 2 1 0 2 1 0 2 1 2 0 2 1 0 2 1 2 0 0 . . .
![Page 23: The Lempel Ziv Algorithm - tuxtina.de · LZ78 (1) •Maintain explicit dictionary •Gradually build dictionary during encoding •Codeword consists of 2 elements: –index (reference](https://reader033.vdocuments.us/reader033/viewer/2022060500/5f1aa893f6f7e44297023926/html5/thumbnails/23.jpg)
C4=02 22 0
C3=20 21 2
C2=21 11 2
C1=22 02 1
LZ77 Example – Encoder0 0 0 0 0 0 0 0 0 0 0 1 0 1 0 2 1 0 2 1 . . .1.
2. 0 0 0 0 0 0 0 0 1 0 1 0 2 1 0 2 1 0 2 1 . . .
3. 0 0 0 0 1 0 1 0 2 1 0 2 1 0 2 1 2 0 2 1 . . .
4. 2 1 0 2 1 0 2 1 2 0 2 1 0 2 1 2 0 0 . . .
![Page 24: The Lempel Ziv Algorithm - tuxtina.de · LZ78 (1) •Maintain explicit dictionary •Gradually build dictionary during encoding •Codeword consists of 2 elements: –index (reference](https://reader033.vdocuments.us/reader033/viewer/2022060500/5f1aa893f6f7e44297023926/html5/thumbnails/24.jpg)
LZ77 Example – Decoder0 0 0 0 0 0 0 0 0C1=22 02 11.
2. C2=21 11 2
3. C3=20 21 2
4. C4=02 22 0
![Page 25: The Lempel Ziv Algorithm - tuxtina.de · LZ78 (1) •Maintain explicit dictionary •Gradually build dictionary during encoding •Codeword consists of 2 elements: –index (reference](https://reader033.vdocuments.us/reader033/viewer/2022060500/5f1aa893f6f7e44297023926/html5/thumbnails/25.jpg)
LZ77 Example – Decoder0 0 0 0 0 0 0 0 0C1=22 02 11.
2. C2=21 11 2
3. C3=20 21 2
4. C4=02 22 0
![Page 26: The Lempel Ziv Algorithm - tuxtina.de · LZ78 (1) •Maintain explicit dictionary •Gradually build dictionary during encoding •Codeword consists of 2 elements: –index (reference](https://reader033.vdocuments.us/reader033/viewer/2022060500/5f1aa893f6f7e44297023926/html5/thumbnails/26.jpg)
LZ77 Example – Decoder0 0 0 0 0 0 0 0 0C1=22 02 11.
2. C2=21 11 2
3. C3=20 21 2
4. C4=02 22 0
0 0 1
![Page 27: The Lempel Ziv Algorithm - tuxtina.de · LZ78 (1) •Maintain explicit dictionary •Gradually build dictionary during encoding •Codeword consists of 2 elements: –index (reference](https://reader033.vdocuments.us/reader033/viewer/2022060500/5f1aa893f6f7e44297023926/html5/thumbnails/27.jpg)
LZ77 Example – Decoder0 0 0 0 0 0 0 0 0C1=22 02 11.
2. 0 0 0 0 0 0 0 0 1C2=21 11 2
3. C3=20 21 2
4. C4=02 22 0
0 0 1
![Page 28: The Lempel Ziv Algorithm - tuxtina.de · LZ78 (1) •Maintain explicit dictionary •Gradually build dictionary during encoding •Codeword consists of 2 elements: –index (reference](https://reader033.vdocuments.us/reader033/viewer/2022060500/5f1aa893f6f7e44297023926/html5/thumbnails/28.jpg)
LZ77 Example – Decoder0 0 0 0 0 0 0 0 0C1=22 02 11.
2. 0 0 0 0 0 0 0 0 1C2=21 11 2
3. C3=20 21 2
4. C4=02 22 0
0 0 1
![Page 29: The Lempel Ziv Algorithm - tuxtina.de · LZ78 (1) •Maintain explicit dictionary •Gradually build dictionary during encoding •Codeword consists of 2 elements: –index (reference](https://reader033.vdocuments.us/reader033/viewer/2022060500/5f1aa893f6f7e44297023926/html5/thumbnails/29.jpg)
LZ77 Example – Decoder0 0 0 0 0 0 0 0 0C1=22 02 11.
2. 0 0 0 0 0 0 0 0 1C2=21 11 2
3. C3=20 21 2
4. C4=02 22 0
0 0 1
0 1 0 2
![Page 30: The Lempel Ziv Algorithm - tuxtina.de · LZ78 (1) •Maintain explicit dictionary •Gradually build dictionary during encoding •Codeword consists of 2 elements: –index (reference](https://reader033.vdocuments.us/reader033/viewer/2022060500/5f1aa893f6f7e44297023926/html5/thumbnails/30.jpg)
LZ77 Example – Decoder0 0 0 0 0 0 0 0 0C1=22 02 11.
2. 0 0 0 0 0 0 0 0 1C2=21 11 2
3. C3=20 21 2
4. C4=02 22 0
0 0 1
0 1 0 2
0 0 0 0 1 0 1 0 2
![Page 31: The Lempel Ziv Algorithm - tuxtina.de · LZ78 (1) •Maintain explicit dictionary •Gradually build dictionary during encoding •Codeword consists of 2 elements: –index (reference](https://reader033.vdocuments.us/reader033/viewer/2022060500/5f1aa893f6f7e44297023926/html5/thumbnails/31.jpg)
LZ77 Example – Decoder0 0 0 0 0 0 0 0 0C1=22 02 11.
2. 0 0 0 0 0 0 0 0 1C2=21 11 2
3. C3=20 21 2
4. C4=02 22 0
0 0 1
0 1 0 2
0 0 0 0 1 0 1 0 2
![Page 32: The Lempel Ziv Algorithm - tuxtina.de · LZ78 (1) •Maintain explicit dictionary •Gradually build dictionary during encoding •Codeword consists of 2 elements: –index (reference](https://reader033.vdocuments.us/reader033/viewer/2022060500/5f1aa893f6f7e44297023926/html5/thumbnails/32.jpg)
LZ77 Example – Decoder0 0 0 0 0 0 0 0 0C1=22 02 11.
2. 0 0 0 0 0 0 0 0 1C2=21 11 2
3. 1 0 2 1 0 2 1 2C3=20 21 2
4. C4=02 22 0
0 0 1
0 1 0 2
0 0 0 0 1 0 1 0 2
![Page 33: The Lempel Ziv Algorithm - tuxtina.de · LZ78 (1) •Maintain explicit dictionary •Gradually build dictionary during encoding •Codeword consists of 2 elements: –index (reference](https://reader033.vdocuments.us/reader033/viewer/2022060500/5f1aa893f6f7e44297023926/html5/thumbnails/33.jpg)
LZ77 Example – Decoder0 0 0 0 0 0 0 0 0C1=22 02 11.
2. 0 0 0 0 0 0 0 0 1C2=21 11 2
3. 1 0 2 1 0 2 1 2C3=20 21 2
4. C4=02 22 0
0 0 1
0 1 0 2
0 0 0 0 1 0 1 0 2
2 1 0 2 1 0 2 1 2
![Page 34: The Lempel Ziv Algorithm - tuxtina.de · LZ78 (1) •Maintain explicit dictionary •Gradually build dictionary during encoding •Codeword consists of 2 elements: –index (reference](https://reader033.vdocuments.us/reader033/viewer/2022060500/5f1aa893f6f7e44297023926/html5/thumbnails/34.jpg)
LZ77 Example – Decoder0 0 0 0 0 0 0 0 0C1=22 02 11.
2. 0 0 0 0 0 0 0 0 1C2=21 11 2
3. 1 0 2 1 0 2 1 2C3=20 21 2
4. C4=02 22 0
0 0 1
0 1 0 2
0 0 0 0 1 0 1 0 2
2 1 0 2 1 0 2 1 2
![Page 35: The Lempel Ziv Algorithm - tuxtina.de · LZ78 (1) •Maintain explicit dictionary •Gradually build dictionary during encoding •Codeword consists of 2 elements: –index (reference](https://reader033.vdocuments.us/reader033/viewer/2022060500/5f1aa893f6f7e44297023926/html5/thumbnails/35.jpg)
LZ77 Example – Decoder0 0 0 0 0 0 0 0 0C1=22 02 11.
2. 0 0 0 0 0 0 0 0 1C2=21 11 2
3. 1 0 2 1 0 2 1 2C3=20 21 2
4. C4=02 22 0
0 0 1
0 1 0 2
0 0 0 0 1 0 1 0 2
2 1 0 2 1 0 2 1 2 0 2 1 0 2 1 2 0 0
![Page 36: The Lempel Ziv Algorithm - tuxtina.de · LZ78 (1) •Maintain explicit dictionary •Gradually build dictionary during encoding •Codeword consists of 2 elements: –index (reference](https://reader033.vdocuments.us/reader033/viewer/2022060500/5f1aa893f6f7e44297023926/html5/thumbnails/36.jpg)
LZ77 Improvements
LZR references to any point in processed data,variable-length references
LZSS codewords without symbol, output (offset,length) or symbol, flag to distinguish
LZB increasing pointer size, variable-length matches(no lookahead buffer), min. match length
LZH LZSS and Huffman coding (2 passes), Huffmantable needs to be stored/transmitted
![Page 37: The Lempel Ziv Algorithm - tuxtina.de · LZ78 (1) •Maintain explicit dictionary •Gradually build dictionary during encoding •Codeword consists of 2 elements: –index (reference](https://reader033.vdocuments.us/reader033/viewer/2022060500/5f1aa893f6f7e44297023926/html5/thumbnails/37.jpg)
LZ77 Comparison
012345678
bib book* geo obj* paper* pic prog-c term
bits
/sym
bol
LZ77 LZR LZSS LZB LZH
All values taken from Bell/Cleary/Witten: Text Compression* combined result for two test files
![Page 38: The Lempel Ziv Algorithm - tuxtina.de · LZ78 (1) •Maintain explicit dictionary •Gradually build dictionary during encoding •Codeword consists of 2 elements: –index (reference](https://reader033.vdocuments.us/reader033/viewer/2022060500/5f1aa893f6f7e44297023926/html5/thumbnails/38.jpg)
LZ78 (1)
• Maintain explicit dictionary• Gradually build dictionary during encoding• Codeword consists of 2 elements:
– index (reference to longest match in dictionary)– first non-matching symbol
• Every codeword also becomes newdictionary entry
![Page 39: The Lempel Ziv Algorithm - tuxtina.de · LZ78 (1) •Maintain explicit dictionary •Gradually build dictionary during encoding •Codeword consists of 2 elements: –index (reference](https://reader033.vdocuments.us/reader033/viewer/2022060500/5f1aa893f6f7e44297023926/html5/thumbnails/39.jpg)
LZ78 (2)w := NIL;while (there is input) {K := next symbol from input;if (wK exists in the dictionary) {
w := wK;} else {
output (index(w), K);add wK to the dictionary;w := NIL;
}}
![Page 40: The Lempel Ziv Algorithm - tuxtina.de · LZ78 (1) •Maintain explicit dictionary •Gradually build dictionary during encoding •Codeword consists of 2 elements: –index (reference](https://reader033.vdocuments.us/reader033/viewer/2022060500/5f1aa893f6f7e44297023926/html5/thumbnails/40.jpg)
LZ78 Example – Encoder
0 0 1 2 1 2 1 2 1 0 2 1 0 1 2 1 0 1 2 2 1 0 1 1# entry phrase Output:123456789
(ternary)
![Page 41: The Lempel Ziv Algorithm - tuxtina.de · LZ78 (1) •Maintain explicit dictionary •Gradually build dictionary during encoding •Codeword consists of 2 elements: –index (reference](https://reader033.vdocuments.us/reader033/viewer/2022060500/5f1aa893f6f7e44297023926/html5/thumbnails/41.jpg)
LZ78 Example – Encoder
0 0 1 2 1 2 1 2 1 0 2 1 0 1 2 1 0 1 2 2 1 0 1 1# entry phrase Output:123456789
(ternary)0 0 (0 0)0 0
![Page 42: The Lempel Ziv Algorithm - tuxtina.de · LZ78 (1) •Maintain explicit dictionary •Gradually build dictionary during encoding •Codeword consists of 2 elements: –index (reference](https://reader033.vdocuments.us/reader033/viewer/2022060500/5f1aa893f6f7e44297023926/html5/thumbnails/42.jpg)
LZ78 Example – Encoder
0 0 1 2 1 2 1 2 1 0 2 1 0 1 2 1 0 1 2 2 1 0 1 1# entry phrase Output:123456789
(ternary)0 0 (0 0)0 0
1+1 1 1 (1 1)01
![Page 43: The Lempel Ziv Algorithm - tuxtina.de · LZ78 (1) •Maintain explicit dictionary •Gradually build dictionary during encoding •Codeword consists of 2 elements: –index (reference](https://reader033.vdocuments.us/reader033/viewer/2022060500/5f1aa893f6f7e44297023926/html5/thumbnails/43.jpg)
LZ78 Example – Encoder
0 0 1 2 1 2 1 2 1 0 2 1 0 1 2 1 0 1 2 2 1 0 1 1# entry phrase Output:123456789
(ternary)0 0 (0 0)0 0
1+1 1 1 (1 1)012 2 0 2 (0 2)
![Page 44: The Lempel Ziv Algorithm - tuxtina.de · LZ78 (1) •Maintain explicit dictionary •Gradually build dictionary during encoding •Codeword consists of 2 elements: –index (reference](https://reader033.vdocuments.us/reader033/viewer/2022060500/5f1aa893f6f7e44297023926/html5/thumbnails/44.jpg)
LZ78 Example – Encoder
0 0 1 2 1 2 1 2 1 0 2 1 0 1 2 1 0 1 2 2 1 0 1 1# entry phrase Output:123456789
(ternary)0 0 (0 0)0 0
1+1 1 1 (1 1)012 2 0 2 (0 2)1 1 0 1 (00 1)
![Page 45: The Lempel Ziv Algorithm - tuxtina.de · LZ78 (1) •Maintain explicit dictionary •Gradually build dictionary during encoding •Codeword consists of 2 elements: –index (reference](https://reader033.vdocuments.us/reader033/viewer/2022060500/5f1aa893f6f7e44297023926/html5/thumbnails/45.jpg)
LZ78 Example – Encoder
0 0 1 2 1 2 1 2 1 0 2 1 0 1 2 1 0 1 2 2 1 0 1 1# entry phrase Output:123456789
(ternary)0 0 (0 0)0 0
1+1 1 1 (1 1)012 2 0 2 (0 2)1 1 0 1 (00 1)
3+1 21 3 1 (10 1)
![Page 46: The Lempel Ziv Algorithm - tuxtina.de · LZ78 (1) •Maintain explicit dictionary •Gradually build dictionary during encoding •Codeword consists of 2 elements: –index (reference](https://reader033.vdocuments.us/reader033/viewer/2022060500/5f1aa893f6f7e44297023926/html5/thumbnails/46.jpg)
LZ78 Example – Encoder
0 0 1 2 1 2 1 2 1 0 2 1 0 1 2 1 0 1 2 2 1 0 1 1# entry phrase Output:123456789
(ternary)0 0 (0 0)0 0
1+1 1 1 (1 1)012 2 0 2 (0 2)1 1 0 1 (00 1)
3+1 21 3 1 (10 1)5+0 210 5 0 (12 0)
![Page 47: The Lempel Ziv Algorithm - tuxtina.de · LZ78 (1) •Maintain explicit dictionary •Gradually build dictionary during encoding •Codeword consists of 2 elements: –index (reference](https://reader033.vdocuments.us/reader033/viewer/2022060500/5f1aa893f6f7e44297023926/html5/thumbnails/47.jpg)
LZ78 Example – Encoder
0 0 1 2 1 2 1 2 1 0 2 1 0 1 2 1 0 1 2 2 1 0 1 1# entry phrase Output:123456789
(ternary)0 0 (0 0)0 0
1+1 1 1 (1 1)012 2 0 2 (0 2)1 1 0 1 (00 1)
3+1 21 3 1 (10 1)5+0 210 5 0 (12 0)6+1 2101 6 1 (20 1)
![Page 48: The Lempel Ziv Algorithm - tuxtina.de · LZ78 (1) •Maintain explicit dictionary •Gradually build dictionary during encoding •Codeword consists of 2 elements: –index (reference](https://reader033.vdocuments.us/reader033/viewer/2022060500/5f1aa893f6f7e44297023926/html5/thumbnails/48.jpg)
LZ78 Example – Encoder
0 0 1 2 1 2 1 2 1 0 2 1 0 1 2 1 0 1 2 2 1 0 1 1# entry phrase Output:123456789
(ternary)0 0 (0 0)0 0
1+1 1 1 (1 1)012 2 0 2 (0 2)1 1 0 1 (00 1)
3+1 21 3 1 (10 1)5+0 210 5 0 (12 0)6+1 2101 6 1 (20 1)7+2 21012 7 2 (21 2)
![Page 49: The Lempel Ziv Algorithm - tuxtina.de · LZ78 (1) •Maintain explicit dictionary •Gradually build dictionary during encoding •Codeword consists of 2 elements: –index (reference](https://reader033.vdocuments.us/reader033/viewer/2022060500/5f1aa893f6f7e44297023926/html5/thumbnails/49.jpg)
LZ78 Example – Encoder
0 0 1 2 1 2 1 2 1 0 2 1 0 1 2 1 0 1 2 2 1 0 1 1# entry phrase Output:123456789
(ternary)
7 1 (21 1)7+1 21011
0 0 (0 0)0 01+1 1 1 (1 1)01
2 2 0 2 (0 2)1 1 0 1 (00 1)
3+1 21 3 1 (10 1)5+0 210 5 0 (12 0)6+1 2101 6 1 (20 1)7+2 21012 7 2 (21 2)
![Page 50: The Lempel Ziv Algorithm - tuxtina.de · LZ78 (1) •Maintain explicit dictionary •Gradually build dictionary during encoding •Codeword consists of 2 elements: –index (reference](https://reader033.vdocuments.us/reader033/viewer/2022060500/5f1aa893f6f7e44297023926/html5/thumbnails/50.jpg)
LZ78 Example – Decoder# entry phraseInput:1234567897 1
0 01 10 20 13 15 06 17 2
![Page 51: The Lempel Ziv Algorithm - tuxtina.de · LZ78 (1) •Maintain explicit dictionary •Gradually build dictionary during encoding •Codeword consists of 2 elements: –index (reference](https://reader033.vdocuments.us/reader033/viewer/2022060500/5f1aa893f6f7e44297023926/html5/thumbnails/51.jpg)
LZ78 Example – Decoder# entry phraseInput:1234567897 1
0 01 10 20 13 15 06 17 2
0 0
0
¸
![Page 52: The Lempel Ziv Algorithm - tuxtina.de · LZ78 (1) •Maintain explicit dictionary •Gradually build dictionary during encoding •Codeword consists of 2 elements: –index (reference](https://reader033.vdocuments.us/reader033/viewer/2022060500/5f1aa893f6f7e44297023926/html5/thumbnails/52.jpg)
LZ78 Example – Decoder# entry phraseInput:1234567897 1
0 01 10 20 13 15 06 17 2
0 0
0
¸1+1 01
0 1
¸
![Page 53: The Lempel Ziv Algorithm - tuxtina.de · LZ78 (1) •Maintain explicit dictionary •Gradually build dictionary during encoding •Codeword consists of 2 elements: –index (reference](https://reader033.vdocuments.us/reader033/viewer/2022060500/5f1aa893f6f7e44297023926/html5/thumbnails/53.jpg)
LZ78 Example – Decoder# entry phraseInput:1234567897 1
0 01 10 20 13 15 06 17 2
0 0
0
¸1+1 01
0 1
¸2 2
2
¸
![Page 54: The Lempel Ziv Algorithm - tuxtina.de · LZ78 (1) •Maintain explicit dictionary •Gradually build dictionary during encoding •Codeword consists of 2 elements: –index (reference](https://reader033.vdocuments.us/reader033/viewer/2022060500/5f1aa893f6f7e44297023926/html5/thumbnails/54.jpg)
LZ78 Example – Decoder# entry phraseInput:1234567897 1
0 01 10 20 13 15 06 17 2
0 0
0
¸1+1 01
0 1
¸2 2
2
¸1 1
1
¸
![Page 55: The Lempel Ziv Algorithm - tuxtina.de · LZ78 (1) •Maintain explicit dictionary •Gradually build dictionary during encoding •Codeword consists of 2 elements: –index (reference](https://reader033.vdocuments.us/reader033/viewer/2022060500/5f1aa893f6f7e44297023926/html5/thumbnails/55.jpg)
LZ78 Example – Decoder# entry phraseInput:1234567897 1
0 01 10 20 13 15 06 17 2
0 0
0
¸1+1 01
0 1
¸2 2
2
¸1 1
1
¸3+1 21
2 1
¸
![Page 56: The Lempel Ziv Algorithm - tuxtina.de · LZ78 (1) •Maintain explicit dictionary •Gradually build dictionary during encoding •Codeword consists of 2 elements: –index (reference](https://reader033.vdocuments.us/reader033/viewer/2022060500/5f1aa893f6f7e44297023926/html5/thumbnails/56.jpg)
LZ78 Example – Decoder# entry phraseInput:1234567897 1
0 01 10 20 13 15 06 17 2
0 0
0
¸1+1 01
0 1
¸2 2
2
¸1 1
1
¸3+1 21
2 1
¸5+0 210
2 1 0
¸
![Page 57: The Lempel Ziv Algorithm - tuxtina.de · LZ78 (1) •Maintain explicit dictionary •Gradually build dictionary during encoding •Codeword consists of 2 elements: –index (reference](https://reader033.vdocuments.us/reader033/viewer/2022060500/5f1aa893f6f7e44297023926/html5/thumbnails/57.jpg)
LZ78 Example – Decoder# entry phraseInput:1234567897 1
0 01 10 20 13 15 06 17 2
0 0
0
¸1+1 01
0 1
¸2 2
2
¸1 1
1
¸3+1 21
2 1
¸5+0 210
2 1 0
¸6+1 2101
2 1 0 1
¸
![Page 58: The Lempel Ziv Algorithm - tuxtina.de · LZ78 (1) •Maintain explicit dictionary •Gradually build dictionary during encoding •Codeword consists of 2 elements: –index (reference](https://reader033.vdocuments.us/reader033/viewer/2022060500/5f1aa893f6f7e44297023926/html5/thumbnails/58.jpg)
LZ78 Example – Decoder# entry phraseInput:1234567897 1
0 01 10 20 13 15 06 17 2
0 0
0
¸1+1 01
0 1
¸2 2
2
¸1 1
1
¸3+1 21
2 1
¸5+0 210
2 1 0
¸6+1 2101
2 1 0 1
¸7+2 21012
2 1 0 1 2
¸
![Page 59: The Lempel Ziv Algorithm - tuxtina.de · LZ78 (1) •Maintain explicit dictionary •Gradually build dictionary during encoding •Codeword consists of 2 elements: –index (reference](https://reader033.vdocuments.us/reader033/viewer/2022060500/5f1aa893f6f7e44297023926/html5/thumbnails/59.jpg)
LZ78 Example – Decoder# entry phraseInput:1234567897 1
0 01 10 20 13 15 06 17 2
0 0
0
¸1+1 01
0 1
¸2 2
2
¸1 1
1
¸3+1 21
2 1
¸5+0 210
2 1 0
¸6+1 2101
2 1 0 1
¸7+2 21012
2 1 0 1 2
¸ 7+1 21011
2 1 0 1 1
¸
![Page 60: The Lempel Ziv Algorithm - tuxtina.de · LZ78 (1) •Maintain explicit dictionary •Gradually build dictionary during encoding •Codeword consists of 2 elements: –index (reference](https://reader033.vdocuments.us/reader033/viewer/2022060500/5f1aa893f6f7e44297023926/html5/thumbnails/60.jpg)
LZ78 Weaknesses
• Dictionary grows without bound• Long phrases appear late• Inclusion of first non-matching symbol
may prevent a good match• Few substrings of the processed input are
entered into the dictionary
![Page 61: The Lempel Ziv Algorithm - tuxtina.de · LZ78 (1) •Maintain explicit dictionary •Gradually build dictionary during encoding •Codeword consists of 2 elements: –index (reference](https://reader033.vdocuments.us/reader033/viewer/2022060500/5f1aa893f6f7e44297023926/html5/thumbnails/61.jpg)
LZW (1)
• Most popular modification to LZ78• Algorithm used to compress GIF images• LZW is patented (like many other LZ algorithms)
• Next symbol no longer included in codeword(! dictionary pre-filled with input alphabet)
• More substrings entered into dictionary• Fixed-length references (12 bit, 4096 entries)• Static after max. entries reached
![Page 62: The Lempel Ziv Algorithm - tuxtina.de · LZ78 (1) •Maintain explicit dictionary •Gradually build dictionary during encoding •Codeword consists of 2 elements: –index (reference](https://reader033.vdocuments.us/reader033/viewer/2022060500/5f1aa893f6f7e44297023926/html5/thumbnails/62.jpg)
LZW (2)w := NIL;while (there is input){
K := next symbol from input;if (wK exists in the dictionary) {
w := wK;} else {
output (index(w));add wK to the dictionary;w := K;
}}
![Page 63: The Lempel Ziv Algorithm - tuxtina.de · LZ78 (1) •Maintain explicit dictionary •Gradually build dictionary during encoding •Codeword consists of 2 elements: –index (reference](https://reader033.vdocuments.us/reader033/viewer/2022060500/5f1aa893f6f7e44297023926/html5/thumbnails/63.jpg)
LZ78 Other Improvements
dictionary contains every unique string of the dataup to certain length, delete entries used only onceLZJ
LZC variable-length pointers, increasing pointer size,monitor compression ratio
LZT LZW + removal of least recently used entries
LZMW new entries created by concatenating two lastencoded phrases
LZFG LZ78 with dictionary storage in a trie and sliding-window principle (remove oldest entries)
![Page 64: The Lempel Ziv Algorithm - tuxtina.de · LZ78 (1) •Maintain explicit dictionary •Gradually build dictionary during encoding •Codeword consists of 2 elements: –index (reference](https://reader033.vdocuments.us/reader033/viewer/2022060500/5f1aa893f6f7e44297023926/html5/thumbnails/64.jpg)
LZ78 Comparison
0123456789
bib book* geo obj* paper* pic prog-c term
bits
/sym
bol
LZ78 LZW LZC LZT LZMW LZFG LZJ'
All values taken from Bell/Cleary/Witten: Text Compression* combined result for two test files
![Page 65: The Lempel Ziv Algorithm - tuxtina.de · LZ78 (1) •Maintain explicit dictionary •Gradually build dictionary during encoding •Codeword consists of 2 elements: –index (reference](https://reader033.vdocuments.us/reader033/viewer/2022060500/5f1aa893f6f7e44297023926/html5/thumbnails/65.jpg)
Comparison LZ and Statistical Coding
01234567
bib book* geo obj* paper* pic prog-c term
bits
/sym
bol
LZB LZFG PPMC
All values taken from Bell/Cleary/Witten: Text Compression* combined result for two test files
![Page 66: The Lempel Ziv Algorithm - tuxtina.de · LZ78 (1) •Maintain explicit dictionary •Gradually build dictionary during encoding •Codeword consists of 2 elements: –index (reference](https://reader033.vdocuments.us/reader033/viewer/2022060500/5f1aa893f6f7e44297023926/html5/thumbnails/66.jpg)
Questions?