LZW Compression

Input Sring =
"*WED*WE*WEE*WEB*WET"


LZW Compression Algorithm:
   	w = NIL;
   	while ( read a character k )
       {
         if wk exists in the dictionary
          w = wk;
         else
           add wk to the dictionary;
           output the code for w;
           w = k;
       }
	
w

w

k

Output

Index

Symbol

NIL

*

     

*

W

*

256

*W

W

E

W

257

WE

E

D

E

258

ED

D

*

D

259

D*

*

W

     

*W

E

256

260

*WE

E

*

E

261

E*

*

W

     

*W

E

     

*WE

E

260

262

*WEE

E

*

     

E*

W

261

263

E*W

W

E

     

WE

B

257

264

WEB

B

*

B

265

B*

*

W

     

*W

E

     

*WE

T

260

266

*WET

T

EOF

T

   
Lecture 3   Slide 29a   6.837 Fall '01