AP CSP Day 46: Data Compression | Cycle 2
Share
Run-length encoding (RLE) is a lossless compression method that replaces consecutive repeated values with a count and the value, such as encoding 'AAAABBB' as '4A3B'. RLE is highly efficient for data with long runs of identical values (like simple images) but can actually increase file size for data with no repetition. AP CSP Cycle 2 compression questions often ask students to apply RLE manually, calculate the compression ratio, or identify scenarios where a specific compression method would be inefficient. Comparing the compressed and original sizes to determine if compression was beneficial is a key skill.
📚 Study the Concept First (Optional) Click to expand ▼
Compression in Practice: Efficiency Analysis
Run-Length Encoding
Run-length encoding (RLE) replaces sequences of repeated values with a count and the value: AAAABBB becomes 4A3B. This works extremely well for images with large blocks of solid color and poorly for natural photos where almost no adjacent pixels share the same color.
When Compression Increases Size
Lossy compression applied to already-compressed data can actually increase file size if the codec cannot find additional redundancy to exploit. Compressing an already-compressed ZIP file almost always produces a larger file.
Practice Question
A video file is compressed using lossy compression, reducing its size from 500 MB to 50 MB. Which of the following statements are true?
I. Some visual or audio quality has been permanently lost.
II. The original 500 MB file can be perfectly reconstructed from the compressed version.
III. The compression achieved a 10:1 ratio.
Statement I is true: lossy compression permanently removes data, resulting in reduced quality. Statement III is true: 500 MB / 50 MB = 10:1 compression ratio. Statement II is false: lossy compression permanently discards data, so the original cannot be perfectly reconstructed.
B) Statement III is also true (simple division confirms the ratio). C) Statement II is false because lossy compression is irreversible. D) Statement II is false, so not all three are correct.
Students sometimes think lossy-compressed files can still be restored to their original quality. The word "lossy" specifically means some information is permanently lost in the compression process.
Compression ratio = original size / compressed size. Lossy = permanently removes data (irreversible). Lossless = preserves all data (fully reversible).
Keep Practicing!
Consistent daily practice is the key to AP CSP success.
AP CSP Resources Get 1-on-1 Help