LZW Dictionary Compression
Watch repeated phrases extend a shared dictionary and reconstruct the text from its emitted codes.
Free theory articleWatch repeated phrases extend a shared dictionary and reconstruct the text from its emitted codes.
Concept & interpretation
Lempel–Ziv–Welch (LZW) is a lossless dictionary compression algorithm that parses input text greedily into the longest recognized phrase w, emits its numeric code, and appends w + k (where k is the next lookahead character) as a new dictionary entry.
Experiment
Compare regular dictionary growth with the KwKwK special branch in https://riano.app/module/lzw-compression:
- Use default input
ABABABAand press Step four times to watch codes 0, 1, 3, 5 emit and observe Decoder special case used switch totrueon the final step. - Enter
ABCABCABCAand press Finish to verify emitted codes0, 1, 2, 3, 5, 4, 0where every phrase is already in the decoder table (special casefalse). - Enter the 12-symbol constant run
AAAAAAAAAAAAand press Finish to see phrase lengths grow from 1 to 4 with codes0, 3, 4, 5, 3.