LZW decompression.



In the lower line we show the LZW code for a string of red and blue pixels, represented by a string of characters, R and B, which are the root characters.
In the upper line we reconstruct the string of pixels.
The numbers in the code refer to places in the sequence of the table.
The code table is constructed depending on what is found in the input code.
The elements of the code-table sequence are strings of root characters.
Let us denote here the i-th element by t(i).
Then 7R stands for t(7)R = 2BR = t(2)BR = BBR.
See also how compression works.