LZ77 Compressor Demo

Watch the sliding window scan left-to-right: on each step it finds the longest back-reference in the search window and emits a (offset, length, literal) token.

Loading interactive simulation...

Sliding-Window Algorithmic Data Compression 🖖

The LZ77 compression algorithm eliminates structural redundancy by substituting repeating data sequences with relative mathematical pointers. Utilizing a sliding operational window, it encodes data as length-distance pairs referencing previously processed buffers. This deterministic referencing dictates the foundation of DEFLATE protocols. The algorithm relies strictly on the statistical probability of repetitive strings, maximizing entropy reduction without fundamentally altering the original mathematical information.

Copying instead of repeating 🖖

When the algorithm meets text it has already read, it doesn't spell it out again — it jots a short note: "go back offset characters and copy length of them." Each token here is (offset, length, literal): a back-reference plus one fresh character. The practical upshot is that text full of repeated words or patterns shrinks a lot, while already-random data barely compresses at all.

When one token becomes a long run 🖖

A match can point just one character back yet copy more characters than exist there yet. With offset 1, the decoder copies each byte the instant it writes it, so a single token like (1, 5, ...) unfolds aaaaaa from one starting a. Classic run-length encoding therefore falls out of LZ77 for free — the "copy" overlaps text still being produced. Try the repetitive sample to watch a match region stretch past the current position.

Example problems