LZ77 is a lossless compression algorithm introduced by Ziv and Lempel (1977). It parses an input string from left to right, using a bounded window of recent symbols as a dictionary. In the original scheme, both encoder and decoder start with the same prescribed dictionary. At each step the encoder finds a longest prefix of the remaining input that can be copied from a position in the window, subject to a phrase length limit and leaving room for a following symbol. It encodes the starting position, the number of symbols to copy, and that following literal symbol. An empty match encodes only one input symbol, with copy length zero.
In distance notation, if the next output position is and the copy starts
positions back, a copy of length
appends
for
in order. The next symbol
is the literal. Because
, every source symbol
is known when it is copied, even if the source and destination ranges overlap. For
example, if the decoded output ends in ab, a copy of length 5 at distance
2 appends ababa. Copying and then appending the literal reproduces each
encoded phrase, so the entire input is recovered by induction over the phrases.
In compressed DEFLATE blocks, an LZ77 variant uses literals and length-distance pairs as data tokens. Huffman coding encodes literal values and classes of lengths and distances, with extra bits for some lengths and distances (Deutsch 1996).