AP Computer Science Principles · Study guide

Big Idea 2: Compression, Data & Visualization

Big Idea 2 · Data · Part 2 of 2

Compression, Data
& Visualization

Lossless vs. lossy compression, what metadata reveals, how to extract information from data, and reading charts without being fooled.

Exam-day recap
  • Compression reduces the number of bits needed to store or transmit data.
  • Lossless: the decompressed file is bit-for-bit identical to the original; nothing was lost (PNG, ZIP, FLAC).
  • Lossy: the decompressed file is close to but not exactly the original; some information was permanently discarded (JPEG, MP3, MP4).
  • Once data has been lost via lossy compression it is lost permanently; converting to a lossless format does not restore it.
  • Metadata is data about data; for a photo the pixels are the data and the timestamp, location, and camera model are metadata.
  • You can only determine something from metadata if every piece of information needed is actually present in the metadata described.
  • Correlation means two things tend to move together; the chart alone can never prove causation.
  • Always check whether a chart's y-axis starts at zero; a truncated axis exaggerates small differences, making them look large.
  • Filter before sorting with multiple criteria: filtering narrows the data, then sorting puts the right answer on top.

§1 Data Compression

Compression reduces the number of bits needed to store or transmit data.

1.1 What "Original" Actually Means

Students often get confused about what happens to the "original" file. Here is the precise picture:

  1. You start with a file (the original).
  2. A compression algorithm reads that file and writes a new, smaller file containing an encoded version of the data.
  3. To use the file later, a decompression algorithm reads the smaller file and reconstructs the data.

The question the exam cares about: when you decompress and open the file, do you get back exactly the original, or an approximation?

Definition · Lossless vs. Lossy

Lossless: decompressed file is bit-for-bit identical to the original. Nothing was lost. (PNG, ZIP, FLAC)

Lossy: decompressed file is close to but not exactly the original. Some information was permanently discarded. (JPEG, MP3, MP4)

1.2 A Concrete Example

You take a photo (the original) and save it two ways:

  • Save as PNG (lossless). File is smaller than raw data, but when you open it, every pixel is exactly what the camera captured.
  • Save as JPEG (lossy). File is much smaller, but fine details are blurred or altered. Those details are gone forever — re-saving the JPEG as PNG does not bring them back.
Common pitfall

Once data has been lost via lossy compression, it is lost permanently. Converting a lossy file to a lossless format does not restore the lost information — it just stores the approximation losslessly going forward.

1.3 Comparison Table

LosslessLossy
What you get backExactly the originalAn approximation
File-size reductionSmallerMuch smaller
Typical formatsPNG, ZIP, FLAC, GIFJPEG, MP3, MP4
When to useText, code, medical imaging, legal documentsPhotos, music, video streaming

§2 Data, Information, and Metadata

Data is raw facts — numbers, text, measurements. Information is what you get when you process data to answer a question.

Metadata is data about data. For a photo file, the pixels are the data; the timestamp, location, and camera model are metadata.

Exam tip

The exam often asks "which of the following can be determined from the available metadata?" Answer carefully: you can only determine something if every piece of information needed is actually present in the metadata described.

2.1 Cleaning Data

Real data is messy. Cleaning fixes issues before analysis:

  • Inconsistent formatting ("NY" vs. "New York" vs. "N.Y.")
  • Missing values (empty cells, "N/A")
  • Invalid entries (age = 200, date = Feb 30)
  • Duplicates (the same record appearing multiple times)

Designing data collection carefully (dropdowns instead of free text, separate fields, validated date pickers) reduces cleaning effort later.

§3 Extracting Information from Data

Raw data becomes useful when you filter, sort, count, or visualize it. The exam tests whether you can reason about what is possible to extract from a given data set.

3.1 Scatter Plot — Correlation ≠ Causation

A scatter plot of hours studied vs. test score for a class of 30 students shows a positive trend: more hours tend to come with higher scores.

What the chart supports
  • Positive correlation
  • Most students who studied 8+ hours scored above 80%
  • A few students scored well despite studying little
What it does NOT show
  • Causation — correlation alone can't prove studying caused the higher scores
  • Individual student details (names, prior grades)
  • Whether this pattern holds for other classes
Common pitfall

Correlation means two things tend to move together. Causation means one actually causes the other. The chart alone can never prove causation — other factors (sleep, tutoring, prior knowledge) might explain both.

3.2 Misleading Scales

A bar chart of Q3 sales by region shows bars that look dramatically different — West appears to tower over North. But look at the y-axis: it starts at $98K, not $0. The actual values are $100K, $101K, $102.5K, and $103K — all within 3% of each other.

Key rule

Always check whether a chart's y-axis starts at zero. A truncated axis exaggerates small differences, making them look large. If the axis doesn't start at zero, the visual proportions of the bars do not reflect actual ratios.

3.3 Filtering and Sorting a Table

Given a spreadsheet with columns like Name, Department, Years, and Salary:

  • "Which engineer has been there longest?" → Filter to Department = Engineering, then sort by Years descending. Top row is the answer.
  • "Highest-paid with fewer than 5 years?" → Filter to Years < 5, then sort by Salary descending. Top row is the answer.
Key idea

Filter before sorting when you have multiple criteria. Filtering narrows the data; sorting then puts the right answer on top. The order of operations matters.

§4 Exam Patterns

4.1 Lossless vs. Lossy

If the scenario requires exact recovery (legal documents, source code, medical records): lossless. If some quality loss is acceptable for smaller files (photos, music): lossy.

4.2 "Which can be determined from this metadata?"

Walk through each choice. If even one required piece of information is missing from the metadata, that choice cannot be determined.

4.3 Correlation vs. Causation

If the question shows a trend or correlation and asks what you can conclude, the answer that claims causation is almost always wrong.

§5 Key Terms

TermDefinition
Cleaning dataFixing inconsistent, incomplete, or invalid entries before analysis
CompressionReducing the number of bits needed to store or transmit data
CorrelationTwo variables tend to move together; does not imply causation
DataRaw facts, numbers, or measurements
FilterSelect a subset of data matching a condition
InformationMeaning extracted from data through processing and analysis
LosslessCompression where original data can be exactly recovered
LossyCompression where some data is permanently lost to save more space
MetadataData about data (e.g., timestamp, author, location)
SortArrange data in a specific order

§6 Self-Check

  1. A student saves a research paper as a ZIP file and later unzips it. Is every word in the document exactly the same as before? Why?
  2. A photographer saves their photo as a JPEG, then converts the JPEG to PNG. Did the PNG recover the details the JPEG lost? Why or why not?
  3. Which is more appropriate for archiving legal documents: lossless or lossy? Why?
  4. A bar chart shows revenue for 4 months with the y-axis starting at $95,000. The bars appear to double from January to April. Can you conclude revenue doubled?
  5. A spreadsheet has columns: Name, Age, City, Purchase Date, Purchase Amount. Can you determine (a) total spent by customers in a given city last month? (b) the favorite product category of a given customer? (c) average age of customers who purchased in March?
Show Answers
  1. Yes. ZIP is lossless compression — the decompressed file is bit-for-bit identical to the original. Every word, space, and character is exactly the same.
  2. No. The JPEG already discarded detail during lossy compression. Converting to PNG only stores the already-degraded version losslessly. The lost detail is gone permanently.
  3. Lossless. Legal documents must be recovered exactly — no character can be lost or changed. Lossy compression permanently discards data, which is unacceptable here.
  4. No. The y-axis doesn't start at zero, so the visual heights don't reflect actual ratios. Revenue from $100K to $105K would look like a doubling under a truncated axis, even though it only grew 5%.
  5. (a) Can be determined — filter to city and date range, sum Purchase Amount. (b) Cannot — no product category column exists. (c) Can be determined — filter to March purchases, average the Age column.