Open any text file and you will find it repeating itself. The same words, the same phrases, the same chunks of HTML come back again and again. LZ77 — published by Abraham Lempel and Jacob Ziv in 1977 — is the algorithm that noticed this and made it pay.
The idea is almost embarrassingly simple. As the algorithm reads through the text it keeps a sliding window of everything it has seen recently. Whenever the next few characters have already appeared inside that window, it does not write them out again. Instead it writes a tiny back-reference: a pair of numbers saying "go back this far, copy this many characters."
Take the word banana. After emitting , , , the next ana is a copy of text three positions back — so banana becomes followed by (go back 2, copy 3). That single trick, repeated millions of times, is the engine inside gzip, zip, PNG and the DEFLATE format that quietly moves most of the web.
Comments
Loading comments...