AP® Computer Science Principles · Big Idea 2 · Topic 2.2
Redundancy and How Much Compression You Get
Compression shrinks files by exploiting repeated patterns in data, so the more redundancy an original file has, the smaller a compressed version can get.
Compression works by spotting repetition and storing it more cheaply. A photo of clear blue sky is mostly the same pixel value repeated thousands of times, so an algorithm can replace all those repeats with a short instruction like 'this color, 50000 times.' Television static has no pattern at all; every pixel is a surprise, so there is nothing to shorten. The amount of redundancy in the original data sets a hard ceiling on compression: no algorithm can shrink pure randomness much, no matter how clever it is.
Compression ratio measures the result: original size divided by compressed size, with both sizes in the same unit. A ratio of 8 means the compressed file is one eighth the size of the original. This number depends entirely on how redundant the source data was, not just on which algorithm you ran.
Lossless compression keeps every bit needed to rebuild the file exactly, while lossy compression permanently throws away detail the eye or ear barely notices, trading accuracy for smaller size. Smaller is not automatically better: the right choice depends on whether the file must be reconstructed perfectly. This sets up the next question in the unit, which is how image and sound formats decide what counts as safe to discard.
Key terms
- Redundancy
- Repeated or predictable patterns within data that compression algorithms can exploit to save space.
- Compression ratio
- Original file size divided by compressed file size, measured in the same units.
- Lossless compression
- A method that shrinks a file while keeping all information needed to reconstruct it exactly.
- Lossy compression
- A method that permanently discards some detail to achieve a smaller file size.
Watch it explained
- How it worksHow does the amount of repetition in the original data set the ceiling on any compression?
- Worked exampleFind the compression ratio when a 4 megabyte file ends up stored in 500 kilobytes.
- Common mistakeWhy isn't lossy compression always the better pick just because it produces smaller files?
- Going furtherWhat changes about the choice of algorithm when the file is a legal contract instead of a meme?
Check yourself
End of topic.