Information Theory and Coding Basics
Data compressed with the LZ77 method are to be restored. The data consist of "character A", "character B" and "(distance 2, length 5)", in that order. (distance d, length L) means repeating L times, one character at a time, "copy the character d characters back from the end of the restored string to its end". Which of the following is the restored string?
- AABAB
- BABABABA
- CABAAAAA
Show answer and explanation
Answer: B. ABABABA
Start from "AB", A followed by B. Copying the A two characters back gives "ABA", and then copying the B, now two characters back, gives "ABAB"; each copy moves the copy source forward by one, so copying five characters gives the seven-character "ABABABA". The length may thus exceed the distance, and by using just-copied characters as the source, a long repetition of a short pattern can be represented by a single pair.
- A. This treats only the two characters present at the start as the copy source. Since copying is done one character at a time, the copied characters also become sources for the next copies.
- B. Correct. A, B, A, B, A are copied after AB, giving seven characters.
- C. This copies the same A five times, but the end moves forward with each copied character, so the character two back alternates between A and B.
Continue: 9 more Information Theory and Coding Basics questions