Problem solved in full
-
Six tokens of "abracadabra" with a search window of 16 characters 5 steps
The panel reads 5.18ร after one token. Work out what it reads after all six. The input is "abracadabra", the search window is 16 characters and the look-ahead buffer is 8.
-
A token is three fixed-width fields, so its cost is decided by the two settings and not by the data. The offset has to address any position in the window, the length any value up to the buffer size, and the literal is a raw byte.
-
The encoder scans left to right and takes the longest match the window offers. Nothing sits behind the first three characters, so 'a', 'b' and 'r' each cost a whole token to say once. Only the final token earns its keep, copying "abra" from position 0.
-
The ratio on the panel is a running figure, and it divides the whole input by the output produced so far. After one token it is weighing eleven characters against seventeen bits, which is why it opens so high.
-
Six tokens at seventeen bits each is 102 bits, against an input of 88. The encoding is bigger than the thing it encodes.
-
The break-even is one division. A token costs 17 bits and buys some number of characters worth 8 bits each, so the scheme wins only when the average token advances more than 17/8 characters โ and of these six, only the last one does.
Answer
The panel prints 5.18ร after the first token and 0.86ร after the sixth: the same string, the same encoding, on opposite sides of 1.0. The figure worth keeping is 2.125 characters per token, which is just the token width divided by eight, and it is the whole test of whether LZ77 helps a given input. It also prices a knob that looks free. Widening the search window to 64 adds two bits to every offset field, and on this string it finds no longer match at all โ the parse is the same six tokens โ so the ratio drops to 0.77ร. Every doubling of the reach costs one more bit on every token, used or not.
-
Learning path
Compression by hand
References (1)
- The algorithm, and the offset-1 trick block 3 turns on: J. Ziv and A. Lempel, "A universal algorithm for sequential data compression." IEEE Transactions on Information Theory 23(3), 337โ343, 1977.