Sri writes the shipping note as LZ77 triples: you set the window and look-ahead, every reference drawn as the same as N letters back, the note opened back…
Why it matters
LZ77 is the first stage of DEFLATE, inside ZIP, gzip, PNG and HTTP compression; its descendants (LZ4, Zstandard, Brotli) are everywhere. The window, the longest match and how the triples are coded decide how much it saves.
The key idea
The same as N letters back
Common mistakes
Random text gets bigger after "compression" Random or already-compressed data has no repeated runs, so every letter becomes a triple (0, 0, letter): its 8 bits plus the offset and length bits. Only patterned data shrinks.
A token (2, 6) is longer than its offset That is fine: the decoder copies one letter at a time, so after 2 letters it reads letters it has just written. (2, 6) repeats a 2-letter pattern three times, like run-length, for free.
Thinking LZ77 alone makes zip/gzip LZ77 only swaps repeats for tokens; DEFLATE then gives those tokens Huffman codes, plus the file format. Those two stages are zip and gzip.
Try it in this playground
Open the note Run until the note is opened back.
A copy into itself Run to the end with a triple longer than its offset.
Write your note Type your own text under the scene.
Even longer Run to the end with a text whose note is longer than the text.