Information Theory and Coding Basics
The 40-character string AAAAAAAAAAAABBBBCCCCCCCCCCCCCCCCCCCCDDDD (12 As, 4 Bs, 20 Cs and 4 Ds) is compressed with run-length encoding, which represents each run of the same character as a pair of "character (1 byte) and count (1 byte)". The original string uses 1 byte per character. Defining the compression ratio as "size after compression ÷ size before compression", which of the following is the compression ratio?
- A10%
- B20%
- C80%
Show answer and explanation
Answer: B. 20%
There are four runs of the same character, A, B, C and D, so the compressed data are 4 × 2 = 8 bytes. The original is 40 bytes, so the compression ratio is 8 ÷ 40 = 0.2, that is, 20%. Run-length encoding shrinks data better the longer the same value continues.
- A. 10% is 4 ÷ 40, which leaves out the bytes that hold the count of each run.
- B. Correct. 8 ÷ 40 = 20%.
- C. 80% is the fraction removed by compression (1 − 0.2), not the compression ratio as defined in this question.
Continue: 9 more Information Theory and Coding Basics questions