demo lzw
DESCRIPTION
TRANSCRIPT
![Page 1: Demo lzw](https://reader037.vdocuments.net/reader037/viewer/2022103110/54798968b4af9fd60e8b474c/html5/thumbnails/1.jpg)
Princeton University • COS 226 • Algorithms and Data Structures • Spring 2004 • Kevin Wayne • http://www.Princeton.EDU/~cos226
LZW Encoding
The input message was taken from:
• http://www-mtl.mit.edu/Courses/6.095/notes/LZW-examples.html
![Page 2: Demo lzw](https://reader037.vdocuments.net/reader037/viewer/2022103110/54798968b4af9fd60e8b474c/html5/thumbnails/2.jpg)
2
LZW Encoding
Word
_
a
b
z
0
Index
…
32
…
97
98
122
SEND
…
256
STOP257
…
it
Word
tt
ty
y_
_b
bi
ty_
_bi
it_
_bin
258
Index
259
260
261
262
263
265
266
267
268
itt264
Dictionary
105
Send
116
116
121
32
98
258
260
i
Input
t
t
y
_
b
t
t
y
_
262b
i
258t
i
_
266
b
i
110n
257STOP
256SEND
![Page 3: Demo lzw](https://reader037.vdocuments.net/reader037/viewer/2022103110/54798968b4af9fd60e8b474c/html5/thumbnails/3.jpg)
3
LZW Encoding
Word
_
a
b
z
0
Index
…
32
…
97
98
122
SEND
…
256
STOP257
…
it
Word
tt
ty
y_
_b
bi
ty_
_bi
it_
_bin
258
Index
259
260
261
262
263
265
266
267
268
itt264
Dictionary
105
Send
116
116
121
32
98
258
260
i
Input
t
t
y
_
b
t
t
y
_
262b
i
258t
i
_
266
b
i
110n
257STOP
256SEND
![Page 4: Demo lzw](https://reader037.vdocuments.net/reader037/viewer/2022103110/54798968b4af9fd60e8b474c/html5/thumbnails/4.jpg)
4
LZW Encoding
Word
_
a
b
z
0
Index
…
32
…
97
98
122
SEND
…
256
STOP257
…
it
Word
tt
ty
y_
_b
bi
ty_
_bi
it_
_bin
258
Index
259
260
261
262
263
265
266
267
268
itt264
Dictionary
105
Send
116
116
121
32
98
258
260
i
Input
t
t
y
_
b
t
t
y
_
262b
i
258t
i
_
266
b
i
110n
257STOP
256SEND
it
![Page 5: Demo lzw](https://reader037.vdocuments.net/reader037/viewer/2022103110/54798968b4af9fd60e8b474c/html5/thumbnails/5.jpg)
5
LZW Encoding
Word
_
a
b
z
0
Index
…
32
…
97
98
122
SEND
…
256
STOP257
…
it
Word
tt
ty
y_
_b
bi
ty_
_bi
it_
_bin
258
Index
259
260
261
262
263
265
266
267
268
itt264
Dictionary
105
Send
116
116
121
32
98
258
260
i
Input
t
t
y
_
b
t
t
y
_
262b
i
258t
i
_
266
b
i
110n
257STOP
256SEND
tt
![Page 6: Demo lzw](https://reader037.vdocuments.net/reader037/viewer/2022103110/54798968b4af9fd60e8b474c/html5/thumbnails/6.jpg)
6
LZW Encoding
Word
_
a
b
z
0
Index
…
32
…
97
98
122
SEND
…
256
STOP257
…
it
Word
tt
ty
y_
_b
bi
ty_
_bi
it_
_bin
258
Index
259
260
261
262
263
265
266
267
268
itt264
Dictionary
105
Send
116
116
121
32
98
258
260
i
Input
t
t
y
_
b
t
t
y
_
262b
i
258t
i
_
266
b
i
110n
257STOP
256SEND
ty
![Page 7: Demo lzw](https://reader037.vdocuments.net/reader037/viewer/2022103110/54798968b4af9fd60e8b474c/html5/thumbnails/7.jpg)
7
LZW Encoding
Word
_
a
b
z
0
Index
…
32
…
97
98
122
SEND
…
256
STOP257
…
it
Word
tt
ty
y_
_b
bi
ty_
_bi
it_
_bin
258
Index
259
260
261
262
263
265
266
267
268
itt264
Dictionary
105
Send
116
116
121
32
98
258
260
i
Input
t
t
y
_
b
t
t
y
_
262b
i
258t
i
_
266
b
i
110n
257STOP
256SEND
y_
![Page 8: Demo lzw](https://reader037.vdocuments.net/reader037/viewer/2022103110/54798968b4af9fd60e8b474c/html5/thumbnails/8.jpg)
8
LZW Encoding
Word
_
a
b
z
0
Index
…
32
…
97
98
122
SEND
…
256
STOP257
…
it
Word
tt
ty
y_
_b
bi
ty_
_bi
it_
_bin
258
Index
259
260
261
262
263
265
266
267
268
itt264
Dictionary
105
Send
116
116
121
32
98
258
260
i
Input
t
t
y
_
b
t
t
y
_
262b
i
258t
i
_
266
b
i
110n
257STOP
256SEND
_b
![Page 9: Demo lzw](https://reader037.vdocuments.net/reader037/viewer/2022103110/54798968b4af9fd60e8b474c/html5/thumbnails/9.jpg)
9
LZW Encoding
Word
_
a
b
z
0
Index
…
32
…
97
98
122
SEND
…
256
STOP257
…
it
Word
tt
ty
y_
_b
bi
ty_
_bi
it_
_bin
258
Index
259
260
261
262
263
265
266
267
268
itt264
Dictionary
105
Send
116
116
121
32
98
258
260
i
Input
t
t
y
_
b
t
t
y
_
262b
i
258t
i
_
266
b
i
110n
257STOP
256SEND
bi
![Page 10: Demo lzw](https://reader037.vdocuments.net/reader037/viewer/2022103110/54798968b4af9fd60e8b474c/html5/thumbnails/10.jpg)
10
LZW Encoding
Word
_
a
b
z
0
Index
…
32
…
97
98
122
SEND
…
256
STOP257
…
it
Word
tt
ty
y_
_b
bi
ty_
_bi
it_
_bin
258
Index
259
260
261
262
263
265
266
267
268
itt264
Dictionary
105
Send
116
116
121
32
98
258
260
i
Input
t
t
y
_
b
t
t
y
_
262b
i
258t
i
_
266
b
i
110n
257STOP
256SEND
itt
![Page 11: Demo lzw](https://reader037.vdocuments.net/reader037/viewer/2022103110/54798968b4af9fd60e8b474c/html5/thumbnails/11.jpg)
11
LZW Encoding
Word
_
a
b
z
0
Index
…
32
…
97
98
122
SEND
…
256
STOP257
…
it
Word
tt
ty
y_
_b
bi
ty_
_bi
it_
_bin
258
Index
259
260
261
262
263
265
266
267
268
itt264
Dictionary
105
Send
116
116
121
32
98
258
260
i
Input
t
t
y
_
b
t
t
y
_
262b
i
258t
i
_
266
b
i
110n
257STOP
256SEND
ty_
![Page 12: Demo lzw](https://reader037.vdocuments.net/reader037/viewer/2022103110/54798968b4af9fd60e8b474c/html5/thumbnails/12.jpg)
12
LZW Encoding
Word
_
a
b
z
0
Index
…
32
…
97
98
122
SEND
…
256
STOP257
…
it
Word
tt
ty
y_
_b
bi
ty_
_bi
it_
_bin
258
Index
259
260
261
262
263
265
266
267
268
itt264
Dictionary
105
Send
116
116
121
32
98
258
260
i
Input
t
t
y
_
b
t
t
y
_
262b
i
258t
i
_
266
b
i
110n
257STOP
256SEND
_bi
![Page 13: Demo lzw](https://reader037.vdocuments.net/reader037/viewer/2022103110/54798968b4af9fd60e8b474c/html5/thumbnails/13.jpg)
13
LZW Encoding
Word
_
a
b
z
0
Index
…
32
…
97
98
122
SEND
…
256
STOP257
…
it
Word
tt
ty
y_
_b
bi
ty_
_bi
it_
_bin
258
Index
259
260
261
262
263
265
266
267
268
itt264
Dictionary
105
Send
116
116
121
32
98
258
260
i
Input
t
t
y
_
b
t
t
y
_
262b
i
258t
i
_
266
b
i
110n
257STOP
256SEND
it_
![Page 14: Demo lzw](https://reader037.vdocuments.net/reader037/viewer/2022103110/54798968b4af9fd60e8b474c/html5/thumbnails/14.jpg)
14
LZW Encoding
Word
_
a
b
z
0
Index
…
32
…
97
98
122
SEND
…
256
STOP257
…
it
Word
tt
ty
y_
_b
bi
ty_
_bi
it_
_bin
258
Index
259
260
261
262
263
265
266
267
268
itt264
Dictionary
105
Send
116
116
121
32
98
258
260
i
Input
t
t
y
_
b
t
t
y
_
262b
i
258t
i
_
266
b
i
110n
257STOP
256SEND
_bin
![Page 15: Demo lzw](https://reader037.vdocuments.net/reader037/viewer/2022103110/54798968b4af9fd60e8b474c/html5/thumbnails/15.jpg)
15
LZW Encoding
Word
_
a
b
z
0
Index
…
32
…
97
98
122
SEND
…
256
STOP257
…
it
Word
tt
ty
y_
_b
bi
ty_
_bi
it_
_bin
258
Index
259
260
261
262
263
265
266
267
268
itt264
Dictionary
105
Send
116
116
121
32
98
258
260
i
Input
t
t
y
_
b
t
t
y
_
262b
i
258t
i
_
266
b
i
110n
257STOP
256SEND
![Page 16: Demo lzw](https://reader037.vdocuments.net/reader037/viewer/2022103110/54798968b4af9fd60e8b474c/html5/thumbnails/16.jpg)
16
LZW Encoding
Word
_
a
b
z
0
Index
…
32
…
97
98
122
SEND
…
256
STOP257
…
it
Word
tt
ty
y_
_b
bi
ty_
_bi
it_
_bin
258
Index
259
260
261
262
263
265
266
267
268
itt264
Dictionary
105
Send
116
116
121
32
98
258
260
i
Input
t
t
y
_
b
t
t
y
_
262b
i
258t
i
_
266
b
i
110n
257STOP
256SEND
![Page 17: Demo lzw](https://reader037.vdocuments.net/reader037/viewer/2022103110/54798968b4af9fd60e8b474c/html5/thumbnails/17.jpg)
17
105
Send
116
116
121
32
98
258
260
i
Input
t
t
y
_
b
t
t
y
_
262b
i
258t
i
_
266
b
i
110n
257STOP
256SEND
LZW Encoding
Words
Original
Message
18
Compression Achieved
Bits / word
8
Total
144
LZW message 14 9 126
![Page 18: Demo lzw](https://reader037.vdocuments.net/reader037/viewer/2022103110/54798968b4af9fd60e8b474c/html5/thumbnails/18.jpg)
Princeton University • COS 226 • Algorithms and Data Structures • Spring 2004 • Kevin Wayne • http://www.Princeton.EDU/~cos226
LZW Decoding
The input message was taken from:
• http://www-mtl.mit.edu/Courses/6.095/notes/LZW-examples.html
![Page 19: Demo lzw](https://reader037.vdocuments.net/reader037/viewer/2022103110/54798968b4af9fd60e8b474c/html5/thumbnails/19.jpg)
19
LZW Decoding
Word
_
a
b
z
0
Index
…
32
…
97
98
122
SEND
…
256
STOP257
…
it
Word
tt
ty
y_
_b
bi
ty_
_bi
it_
_bin
258
Index
259
260
261
262
263
265
266
267
268
itt264
Dictionary
105
Received
116
116
121
32
98
260
262
i
Input
t
t
y
_
b
t
t
y
_
258
b
i
t
258 i
266 _
b
i
110 n
257 STOP
256 SEND
![Page 20: Demo lzw](https://reader037.vdocuments.net/reader037/viewer/2022103110/54798968b4af9fd60e8b474c/html5/thumbnails/20.jpg)
20
LZW Decoding
Word
_
a
b
z
0
Index
…
32
…
97
98
122
SEND
…
256
STOP257
…
it
Word
tt
ty
y_
_b
bi
ty_
_bi
it_
_bin
258
Index
259
260
261
262
263
265
266
267
268
itt264
Dictionary
105
Received
116
116
121
32
98
260
262
i
Input
t
t
y
_
b
t
t
y
_
258
b
i
t
258 i
266 _
b
i
110 n
257 STOP
256 SEND
![Page 21: Demo lzw](https://reader037.vdocuments.net/reader037/viewer/2022103110/54798968b4af9fd60e8b474c/html5/thumbnails/21.jpg)
21
LZW Decoding
Word
_
a
b
z
0
Index
…
32
…
97
98
122
SEND
…
256
STOP257
…
it
Word
tt
ty
y_
_b
bi
ty_
_bi
it_
_bin
258
Index
259
260
261
262
263
265
266
267
268
itt264
Dictionary
105
Received
116
116
121
32
98
260
262
i
Input
t
t
y
_
b
t
t
y
_
258
b
i
t
258 i
266 _
b
i
110 n
257 STOP
256 SEND
![Page 22: Demo lzw](https://reader037.vdocuments.net/reader037/viewer/2022103110/54798968b4af9fd60e8b474c/html5/thumbnails/22.jpg)
22
LZW Decoding
Word
_
a
b
z
0
Index
…
32
…
97
98
122
SEND
…
256
STOP257
…
it
Word
tt
ty
y_
_b
bi
ty_
_bi
it_
_bin
258
Index
259
260
261
262
263
265
266
267
268
itt264
Dictionary
105
Received
116
116
121
32
98
260
262
i
Input
t
t
y
_
b
t
t
y
_
258
b
i
t
258 i
266 _
b
i
110 n
257 STOP
256 SEND
![Page 23: Demo lzw](https://reader037.vdocuments.net/reader037/viewer/2022103110/54798968b4af9fd60e8b474c/html5/thumbnails/23.jpg)
23
LZW Decoding
Word
_
a
b
z
0
Index
…
32
…
97
98
122
SEND
…
256
STOP257
…
it
Word
tt
ty
y_
_b
bi
ty_
_bi
it_
_bin
258
Index
259
260
261
262
263
265
266
267
268
itt264
Dictionary
105
Received
116
116
121
32
98
260
262
i
Input
t
t
y
_
b
t
t
y
_
258
b
i
t
258 i
266 _
b
i
110 n
257 STOP
256 SEND
![Page 24: Demo lzw](https://reader037.vdocuments.net/reader037/viewer/2022103110/54798968b4af9fd60e8b474c/html5/thumbnails/24.jpg)
24
LZW Decoding
Word
_
a
b
z
0
Index
…
32
…
97
98
122
SEND
…
256
STOP257
…
it
Word
tt
ty
y_
_b
bi
ty_
_bi
it_
_bin
258
Index
259
260
261
262
263
265
266
267
268
itt264
Dictionary
105
Received
116
116
121
32
98
260
262
i
Input
t
t
y
_
b
t
t
y
_
258
b
i
t
258 i
266 _
b
i
110 n
257 STOP
256 SEND
![Page 25: Demo lzw](https://reader037.vdocuments.net/reader037/viewer/2022103110/54798968b4af9fd60e8b474c/html5/thumbnails/25.jpg)
25
LZW Decoding
Word
_
a
b
z
0
Index
…
32
…
97
98
122
SEND
…
256
STOP257
…
it
Word
tt
ty
y_
_b
bi
ty_
_bi
it_
_bin
258
Index
259
260
261
262
263
265
266
267
268
itt264
Dictionary
105
Received
116
116
121
32
98
260
262
i
Input
t
t
y
_
b
t
t
y
_
258
b
i
t
258 i
266 _
b
i
110 n
257 STOP
256 SEND
![Page 26: Demo lzw](https://reader037.vdocuments.net/reader037/viewer/2022103110/54798968b4af9fd60e8b474c/html5/thumbnails/26.jpg)
26
LZW Decoding
Word
_
a
b
z
0
Index
…
32
…
97
98
122
SEND
…
256
STOP257
…
it
Word
tt
ty
y_
_b
bi
ty_
_bi
it_
_bin
258
Index
259
260
261
262
263
265
266
267
268
itt264
Dictionary
105
Received
116
116
121
32
98
260
262
i
Input
t
t
y
_
b
t
t
y
_
258
b
i
t
258 i
266 _
b
i
110 n
257 STOP
256 SEND
![Page 27: Demo lzw](https://reader037.vdocuments.net/reader037/viewer/2022103110/54798968b4af9fd60e8b474c/html5/thumbnails/27.jpg)
27
LZW Decoding
Word
_
a
b
z
0
Index
…
32
…
97
98
122
SEND
…
256
STOP257
…
it
Word
tt
ty
y_
_b
bi
ty_
_bi
it_
_bin
258
Index
259
260
261
262
263
265
266
267
268
itt264
Dictionary
105
Received
116
116
121
32
98
260
262
i
Input
t
t
y
_
b
t
t
y
_
258
b
i
t
258 i
266 _
b
i
110 n
257 STOP
256 SEND
![Page 28: Demo lzw](https://reader037.vdocuments.net/reader037/viewer/2022103110/54798968b4af9fd60e8b474c/html5/thumbnails/28.jpg)
28
LZW Decoding
Word
_
a
b
z
0
Index
…
32
…
97
98
122
SEND
…
256
STOP257
…
it
Word
tt
ty
y_
_b
bi
ty_
_bi
it_
_bin
258
Index
259
260
261
262
263
265
266
267
268
itt264
Dictionary
105
Received
116
116
121
32
98
260
262
i
Input
t
t
y
_
b
t
t
y
_
258
b
i
t
258 i
266 _
b
i
110 n
257 STOP
256 SEND
![Page 29: Demo lzw](https://reader037.vdocuments.net/reader037/viewer/2022103110/54798968b4af9fd60e8b474c/html5/thumbnails/29.jpg)
29
LZW Decoding
Word
_
a
b
z
0
Index
…
32
…
97
98
122
SEND
…
256
STOP257
…
it
Word
tt
ty
y_
_b
bi
ty_
_bi
it_
_bin
258
Index
259
260
261
262
263
265
266
267
268
itt264
Dictionary
105
Received
116
116
121
32
98
260
262
i
Input
t
t
y
_
b
t
t
y
_
258
b
i
t
258 i
266 _
b
i
110 n
257 STOP
256 SEND
![Page 30: Demo lzw](https://reader037.vdocuments.net/reader037/viewer/2022103110/54798968b4af9fd60e8b474c/html5/thumbnails/30.jpg)
30
LZW Decoding
Word
_
a
b
z
0
Index
…
32
…
97
98
122
SEND
…
256
STOP257
…
it
Word
tt
ty
y_
_b
bi
ty_
_bi
it_
_bin
258
Index
259
260
261
262
263
265
266
267
268
itt264
Dictionary
105
Received
116
116
121
32
98
260
262
i
Input
t
t
y
_
b
t
t
y
_
258
b
i
t
258 i
266 _
b
i
110 n
257 STOP
256 SEND
![Page 31: Demo lzw](https://reader037.vdocuments.net/reader037/viewer/2022103110/54798968b4af9fd60e8b474c/html5/thumbnails/31.jpg)
31
LZW Decoding
Word
_
a
b
z
0
Index
…
32
…
97
98
122
SEND
…
256
STOP257
…
it
Word
tt
ty
y_
_b
bi
ty_
_bi
it_
_bin
258
Index
259
260
261
262
263
265
266
267
268
itt264
Dictionary
105
Received
116
116
121
32
98
260
262
i
Input
t
t
y
_
b
t
t
y
_
258
b
i
t
258 i
266 _
b
i
110 n
257 STOP
256 SEND
![Page 32: Demo lzw](https://reader037.vdocuments.net/reader037/viewer/2022103110/54798968b4af9fd60e8b474c/html5/thumbnails/32.jpg)
32
LZW Decoding
Word
_
a
b
z
0
Index
…
32
…
97
98
122
SEND
…
256
STOP257
…
it
Word
tt
ty
y_
_b
bi
ty_
_bi
it_
_bin
258
Index
259
260
261
262
263
265
266
267
268
itt264
Dictionary
105
Received
116
116
121
32
98
260
262
i
Input
t
t
y
_
b
t
t
y
_
258
b
i
t
258 i
266 _
b
i
110 n
257 STOP
256 SEND
![Page 33: Demo lzw](https://reader037.vdocuments.net/reader037/viewer/2022103110/54798968b4af9fd60e8b474c/html5/thumbnails/33.jpg)
33
LZW Decoding
Word
_
a
b
z
0
Index
…
32
…
97
98
122
SEND
…
256
STOP257
…
it
Word
tt
ty
y_
_b
bi
ty_
_bi
it_
_bin
258
Index
259
260
261
262
263
265
266
267
268
itt264
Dictionary
105
Received
116
116
121
32
98
260
262
i
Input
t
t
y
_
b
t
t
y
_
258
b
i
t
258 i
266 _
b
i
110 n
257 STOP
256 SEND
![Page 34: Demo lzw](https://reader037.vdocuments.net/reader037/viewer/2022103110/54798968b4af9fd60e8b474c/html5/thumbnails/34.jpg)
34
LZW Decoding
Word
_
a
b
z
0
Index
…
32
…
97
98
122
SEND
…
256
STOP257
…
it
Word
tt
ty
y_
_b
bi
ty_
_bi
it_
_bin
258
Index
259
260
261
262
263
265
266
267
268
itt264
Dictionary
105
Received
116
116
121
32
98
260
262
i
Input
t
t
y
_
b
t
t
y
_
258
b
i
t
258 i
266 _
b
i
110 n
257 STOP
256 SEND
![Page 35: Demo lzw](https://reader037.vdocuments.net/reader037/viewer/2022103110/54798968b4af9fd60e8b474c/html5/thumbnails/35.jpg)
35
LZW Decoding
Word
_
a
b
z
0
Index
…
32
…
97
98
122
SEND
…
256
STOP257
…
it
Word
tt
ty
y_
_b
bi
ty_
_bi
it_
_bin
258
Index
259
260
261
262
263
265
266
267
268
itt264
Dictionary
105
Received
116
116
121
32
98
260
262
i
Input
t
t
y
_
b
t
t
y
_
258
b
i
t
258 i
266 _
b
i
110 n
257 STOP
256 SEND
![Page 36: Demo lzw](https://reader037.vdocuments.net/reader037/viewer/2022103110/54798968b4af9fd60e8b474c/html5/thumbnails/36.jpg)
36
LZW Decoding
Word
_
a
b
z
0
Index
…
32
…
97
98
122
SEND
…
256
STOP257
…
it
Word
tt
ty
y_
_b
bi
ty_
_bi
it_
_bin
258
Index
259
260
261
262
263
265
266
267
268
itt264
Dictionary
105
Received
116
116
121
32
98
260
262
i
Input
t
t
y
_
b
t
t
y
_
258
b
i
t
258 i
266 _
b
i
110 n
257 STOP
256 SEND
![Page 37: Demo lzw](https://reader037.vdocuments.net/reader037/viewer/2022103110/54798968b4af9fd60e8b474c/html5/thumbnails/37.jpg)
37
LZW Decoding
Word
_
a
b
z
0
Index
…
32
…
97
98
122
SEND
…
256
STOP257
…
it
Word
tt
ty
y_
_b
bi
ty_
_bi
it_
_bin
258
Index
259
260
261
262
263
265
266
267
268
itt264
Dictionary
105
Received
116
116
121
32
98
260
262
i
Input
t
t
y
_
b
t
t
y
_
258
b
i
t
258 i
266 _
b
i
110 n
257 STOP
256 SEND
![Page 38: Demo lzw](https://reader037.vdocuments.net/reader037/viewer/2022103110/54798968b4af9fd60e8b474c/html5/thumbnails/38.jpg)
38
LZW Decoding
Word
_
a
b
z
0
Index
…
32
…
97
98
122
SEND
…
256
STOP257
…
it
Word
tt
ty
y_
_b
bi
ty_
_bi
it_
_bin
258
Index
259
260
261
262
263
265
266
267
268
itt264
Dictionary
105
Received
116
116
121
32
98
260
262
i
Input
t
t
y
_
b
t
t
y
_
258
b
i
t
258 i
266 _
b
i
110 n
257 STOP
256 SEND