| Algorithm 1: Modified LZW encoding algorithm | |
| 1 | Task 1: Encoding the sequence S and finding the LZW table T |
| 2 | Initialization: Initializing table T with single character in the sequence S |
| 3 | Output: code and table T |
| 4 | Set P = first input character in S |
| 5 | while not end of the sequence S |
| 6 | C = next input character in S |
| 7 | if P + C is in the table T |
| 8 | P = P + C |
| 9 | else |
| 10 | add P + C to the table T |
| 11 | P = C |
| 12 | end if |
| 13 | end while |
| 14 | Set P = first input character in S |
| 15 | while not end of the sequence S |
| 16 | C = next input character in S |
| 17 | if P + C is in the table T |
| 18 | P = P + C |
| 19 | else |
| 20 | output the code for P |
| 21 | P = C |
| 22 | end if |
| 23 | end while |
| 24 | output code for P |