Fiveable

โŒจ๏ธAP Computer Science Principles Unit 2 Review

QR code for AP Computer Science Principles practice questions

2.2 Data Compression

2.2 Data Compression

Written by the Fiveable Content Team โ€ข Last updated June 2026
Verified for the 2027 exam
Verified for the 2027 examโ€ขWritten by the Fiveable Content Team โ€ข Last updated June 2026
โŒจ๏ธAP Computer Science Principles
Unit & Topic Study Guides

AP Computer Science Principles Exam

Pep mascot

TLDR

Data compression shrinks the number of bits needed to store or send a file. Lossless compression lets you rebuild the original file exactly, while lossy compression throws out some data to save more space but only gives back an approximation. On the AP Computer Science Principles exam, you mainly compare the two and pick the better one for a given situation.

Why This Matters for the AP Computer Science Principles Exam

This topic falls under the Data big idea, and your main job is to compare compression algorithms and decide which fits a specific context. Multiple-choice questions often give you a scenario (sending a photo, storing a medical scan, streaming audio) and ask whether lossless or lossy makes more sense, or why a smaller file might still hold all the original information. You should be ready to reason about trade-offs between file size and the ability to reconstruct the original data.

Key Takeaways

  • Data compression reduces the number of bits used to store or transmit data.
  • Fewer bits does not always mean less information, and how much you save depends on both redundancy in the data and the algorithm you use.
  • Lossless compression usually shrinks the file while guaranteeing a complete, exact rebuild of the original.
  • Lossy compression can shrink files more than lossless, but you only get back an approximation.
  • Choose lossless when exact reconstruction or quality matters most; choose lossy when minimizing size or transfer time matters most.

What Data Compression Is

Digital files can get large fast, and big files are slow to send and expensive to store. Data compression is the process of reducing the size, meaning the number of bits, of stored or transmitted data.

How much you can shrink a file depends on two things:

  1. the amount of redundancy, or repeated information, in the original data
  2. the compression algorithm you apply

Many compression methods work by spotting patterns or repeated data and representing them in a shorter way. An important idea to remember: fewer bits does not automatically mean you lost information. A well-designed method can store the same information using less space.

How Compression Reduces Size (Example)

A simple way to see compression in action is run-length encoding, where repeated values get replaced with a count and the value. For example, the string "FFFFFIIIIIIVVVVVVVEEEE" could be stored as something like 5F6I7V4E, which uses far fewer characters while keeping all the original information.

This is an example of a compression approach, not required AP content. It is just a helpful way to picture how redundancy gets removed. The exam focus is on comparing categories of compression, not memorizing specific named algorithms.

Lossless vs. Lossy Data Compression

Lossless Data Compression

Lossless compression reduces file size without throwing away any of the original data. Because nothing is lost, you can usually rebuild the original file exactly.

Pick lossless when quality or exact reconstruction matters most. As applications of this idea, lossless methods fit situations like:

  • files where a tiny change could alter the meaning of the data
  • medical or satellite images, where small differences can matter a lot
  • software downloads, since a program has to be recreated exactly to run correctly

Lossy Data Compression

Lossy compression sacrifices some data to achieve more size reduction than lossless can. It often does this by dropping details, such as replacing similar colors in a photo with a single color. When you decompress, you get an approximation of the original, not an exact copy.

Pick lossy when minimizing size or transmission time matters most. Many lossy changes are hard for a typical viewer or listener to notice, which is why lossy methods are common for photos, audio, and video, especially when fast transfer matters.

Quick Comparison

FeatureLosslessLossy
Original data keptAll of itSome is removed
ReconstructionExact copyApproximation only
Typical size reductionSmaller savingsUsually larger savings
Best whenQuality or exact rebuild mattersSmall size or fast transfer matters

Keep in mind you do not always have to choose only one. Many real compression systems combine approaches.

How to Use This on the AP Computer Science Principles Exam

MCQ

  • Read the scenario and find the priority. Is the question stressing exact quality and reconstruction, or small size and fast transfer?
  • If exact reconstruction matters, lean lossless. If minimizing size or transmission time matters, lean lossy.
  • Expect questions that test whether you know fewer bits does not mean less information. A smaller file can still hold everything.
  • Watch for trade-off language. Lossy usually wins on size, lossless wins on guaranteed exact rebuilding.

Common Trap

  • Do not assume compression always loses quality. Lossless keeps everything.
  • Do not assume the most compressed file is always best. The right choice depends on the context in the question.

Common Misconceptions

  • "Compression always loses data." Only lossy compression loses data. Lossless rebuilds the original exactly.
  • "Fewer bits means less information." Not true. Removing redundancy can shrink the file while keeping all the information.
  • "Lossy compression ruins quality." Often the loss is hard to notice, which is why lossy is fine for most everyday photos, audio, and video.
  • "One algorithm is always best." The best choice depends on whether the situation values exact reconstruction or smaller size and faster transfer.
  • "Compression amount depends only on the algorithm." It also depends on how much redundancy exists in the original data.

Vocabulary

The following words are mentioned explicitly in the College Board Course and Exam Description for this topic.

Term

Definition

bit

Shorthand for binary digit; the smallest unit of data in computing, represented as either 0 or 1.

data compression algorithms

Methods or procedures used to reduce the number of bits needed to represent data while maintaining or approximating the original information.

lossless data compression

A compression algorithm that reduces the number of bits stored or transmitted while guaranteeing complete reconstruction of the original data.

lossy data compression

A compression algorithm that significantly reduces the number of bits stored or transmitted but only allows reconstruction of an approximation of the original data.

redundancy

Repetition or unnecessary duplication in data representation that can be reduced through compression.

Frequently Asked Questions

What is data compression in AP Computer Science Principles?

Data compression reduces the number of bits needed to store or transmit data. AP CSP focuses on why compression is useful and how lossy and lossless methods differ.

What is lossless compression?

Lossless compression reduces file size while allowing the original data to be reconstructed exactly. It is best when accuracy or exact recovery matters.

What is lossy compression?

Lossy compression reduces file size by removing some data. It usually saves more space than lossless compression but only reconstructs an approximation of the original.

When should I use lossless instead of lossy compression?

Use lossless compression when the original must be recovered exactly, such as with software, text, medical images, or data where small changes could matter.

When should I use lossy compression?

Use lossy compression when smaller file size or faster transmission matters more than perfect reconstruction, such as with many photos, videos, and audio files.

How is data compression tested on AP CSP?

AP CSP questions often ask you to compare lossy and lossless compression, choose the better method for a scenario, or explain how compression reduces bits without always losing information.

Pep mascot
Upgrade your Fiveable account to print any study guide

Download study guides as beautiful PDFs โ†’ See example

Print or share PDFs with your students

Always prints our latest, updated content

Mark up and annotate as you study

Click below to go to billing portal โ†’ update your plan โ†’ choose Yearlyโ†’ and select "Fiveable Share Plan". Only pay the difference

Plan is open to all students, teachers, parents, etc
Pep mascot
Upgrade your Fiveable account to export vocabulary

Download study guides as beautiful PDFs โ†’ See example

Print or share PDFs with your students

Always prints our latest, updated content

Mark up and annotate as you study

Plan is open to all students, teachers, parents, etc
report an error
description

screenshots help us find and fix the issue faster (optional)

add screenshot