AP Computer Science Principles · Unit 2: Data
2.2 Data Compression
Why compress data?
Data compression shrinks file size, saving storage space and reducing time needed to transmit data over networks. Compression algorithms convert data into a more compact representation before storage/transmission, then a corresponding algorithm restores it when needed. Smaller files mean faster uploads, downloads, and streaming, especially on limited bandwidth.
Lossless vs. lossy compression
Lossless compression reduces file size while allowing the *exact* original data to be reconstructed — critical for text or program files where every bit matters. Lossy compression permanently discards some data to shrink files further, trading some fidelity (quality/precision) for a much smaller size — common in images, audio, and video where minor loss is imperceptible.
Compression trade-offs
Compression involves trade-offs between file size, fidelity, and processing/transmission time. Higher compression usually means smaller files but slower processing or lower quality. Choosing lossless vs. lossy depends on the data's purpose: a legal document needs lossless compression, while a casual photo can tolerate lossy compression for a smaller file.
Key terms
- Data compression
- The process of reducing the size of data to save storage space or transmission time.
- Lossless compression
- Compression that allows the original data to be perfectly reconstructed with no loss of information.
- Lossy compression
- Compression that permanently removes some data, reducing fidelity in exchange for a smaller file size.
- Fidelity
- The degree to which compressed data retains the quality/precision of the original data.
- Compression trade-off
- Balancing smaller file size against fidelity and processing/transmission time when choosing a compression method.
Try an AP-style question
Using run-length encoding, how might "AAAABBBCC" be compressed?
- ABC
- 9ABC
- A4B3C2A
- 4A3B2C
Show the answer
D. Count, then character.
Practice 8 AP-style questions with instant explanations, flashcards and spaced review.
Study 2.2 free in APrep