AP · Computer Science Principles · Extracting Information From Data

Processing Data With Programs

13 min readUpdated December 1, 2026FreeAP Computer Science Principles, Data

Programs turn raw data into information by filtering it, cleaning it, transforming it, combining data sets and visualizing the results. The results are only as good as the data: missing, impossible or inconsistent values give wrong answers, and biased collection gives biased results. A data set too large for one computer can be split across many computers that work on it at the same time.

Quick check

  1. Is a photo's file size data or metadata?Show answerHide answer

    Metadata. It describes the photo; the pixels are the data.

  2. What does FOR EACH item IN aList do in the exam's pseudocode?Show answerHide answer

    It assigns each element of aList to item in turn, from the first element to the last, and runs the block once for each.

Know these already? Jump to the practice questions

What you'll be able to do

  • Predict the output of code that filters or totals a list.
  • Identify incomplete, invalid and inconsistent data, and how cleaning fixes each.
  • Explain how the way data is collected can introduce bias.
  • Explain why large data sets can need more than one computer.

Key terms

Filtering

Keeping only the data values that meet a condition.

In plain English
Picking out the rows you need.
Don't write
"Filtering changes the values in a data set."

Data cleaning

Fixing or removing incomplete, invalid or inconsistent values so the data is uniform and usable, without changing what it means.

In plain English
Tidying the data before you trust it.
Don't write
"Cleaning means deleting values that don't fit the expected result."

Bias

A systematic tilt in data, often caused by how or from whom it was collected, so it misrepresents the group it is meant to describe.

In plain English
The data leans one way because of how it was gathered.
Don't write
"Collecting more data removes bias."

What can a program do to a data set?

OperationWhat it doesExample
FilterKeeps values that meet a conditionDays above 30 °C
TransformChanges every value in the same wayAdding a fee to every price
CombineJoins data sets into oneMatching test scores to attendance by student ID
VisualizeShows data as a chart or graphA line graph that makes a trend visible

Filtering in the exam's pseudocode follows one pattern: start an empty list, visit each element, and APPEND the ones that pass the test.

hot ← []
FOR EACH t IN temps
{
   IF(t > 30)
   {
      APPEND(hot, t)
   }
}

FOR EACH, APPEND and [] are on the exam reference sheet. The ideas about data quality, bias and many computers are Learn this.

Check yourself

If temps is [28, 31, 35, 30], what does hot hold after the loop?
Show answerHide answer

[31, 35]. Only 31 and 35 are greater than 30; 30 itself fails t > 30.

What makes data hard to use?

Three problems spoil results:

  • Incomplete: a value is missing, such as a blank age on a form.
  • Invalid: a value is impossible or the wrong type, such as an age of 170 or the word "ten" where a number belongs.
  • Inconsistent: the same thing is recorded in different ways, such as "TX", "Texas" and "texas", or heights in both inches and centimeters.

A program that counts entries matching "Texas" misses the other two spellings. Cleaning fixes this: it puts every entry in one form, converts units, and removes or flags impossible values. Cleaning must not change what the data means, so a real but unusual value stays in.

Check yourself

A weather log records a city's noon temperature as 999 °C. Which problem is this?
Show answerHide answer

Invalid data. No city's air temperature can be 999 °C, so the value is impossible.

How does bias get into data?

Bias usually comes from how the data was collected. If the collection method leaves out a group, or over-represents one, every result computed from it leans the same way.

Suppose a hypothetical town surveys residents about internet use with an online-only form. People without internet access cannot answer, so the results overstate how connected the town is.

More responses through the same online form do not help: the same people are still missing. To reduce the bias, change the collection method, for example by adding paper and phone surveys.

Check yourself

A school asks about lunch quality only students who buy lunch. Who is left out?
Show answerHide answer

Students who bring their own lunch, possibly because they dislike the school lunch, so the results are likely to overstate how much students like it.

Why can big data sets need more than one computer?

Some data sets are too large for one computer to store, or to process in a reasonable time. The usual answer is distributed computing: the data is split into parts, several computers process their parts at the same time, and the partial results are combined.

This saves time because the parts are processed in parallel. But splitting the data and combining the results take time too, so four computers rarely finish exactly four times as fast.

Check yourself

A job takes one computer 12 hours. Split evenly across 4 computers working at once, how long does the processing take, before combining?
Show answerHide answer

3 hours. Each computer handles a quarter of the work, and 12 ÷ 4 = 3.

Worked example 1: Trace a cleaning loop

Question: In a survey, -1 marks a missing age. What is displayed as a result of running the code segment?

ages ← [16, -1, 17, 15, -1, 18]
total ← 0
valid ← 0
FOR EACH a IN ages
{
   IF(a ≥ 0)
   {
      total ← total + a
      valid ← valid + 1
   }
}
DISPLAY(total)
DISPLAY(valid)

What tells you the method

A loop with a condition that skips some values: trace each element.

  1. Step 1: Trace the loop.

    aa ≥ 0?totalvalid
    16yes161
    -1no161
    17yes332
    15yes483
    -1no483
    18yes664
    Why

    The IF filters out the -1 markers, so missing answers do not change either variable.

  2. Step 2: Read off the display.

    total is 66 and valid is 4, shown on one line.

    Why

    Each DISPLAY shows its value followed by a space.

Check it

16 + 17 + 15 + 18 = 66 from the four real ages. Without the filter, the result would be 64 and 6.

Answer

66 4

Worked example 2: Classify data problems

Question: A club's sign-up table is shown.

RowNameAgeState
1Ana16TX
2BenTX
3Cal170TX
4Dee15Texas
5Eli17NM

Which row has (a) incomplete data, (b) invalid data, (c) inconsistent data?

What tells you the method

A table and named data problems: test each row against each definition.

  1. Step 1: Look for gaps.

    Row 2 has no age.

    Why

    A missing value makes the data incomplete.

  2. Step 2: Look for impossible values.

    Row 3 gives an age of 170.

    Why

    No club member can be 170, so the value is invalid.

  3. Step 3: Look for mixed formats.

    Row 4 writes "Texas" where the others use "TX".

    Why

    Two forms of one state break a count by state.

Check it

Rows 1 and 5 are complete, possible and use two-letter codes.

Answer

(a) 2; (b) 3; (c) 4

Worked example 3: Spot bias in a survey

Question: To learn how residents travel to work, a city surveys people at a train station at 8 a.m., then repeats the survey there with ten times as many people. Which statement is true?

  • A) The larger survey removes the bias, because it has more data.
  • B) Both surveys over-represent train riders, because both used the same method.
  • C) The survey is unbiased, because it was taken during the commute.
  • D) The larger survey is biased, but the first one is not.

What tells you the method

A claim about bias: ask who the collection method reaches and who it misses.

  1. Step 1: Find who is missed.

    People who drive, cycle or work from home are rarely at a train station.

    Why

    The place of collection decides who can answer.

  2. Step 2: Compare the two surveys.

    Both use the same place and time, so both miss the same people.

    Why

    More data collected the same way repeats the same bias.

Check it

A and D treat sample size as the cure or the cause; C ignores who is at the station.

Answer

B

Your turn

Question: A hypothetical analysis takes one computer 60 minutes. It is split evenly across 4 computers working at the same time, and combining their results takes 5 more minutes. How many minutes does the whole job take?

  1. Step 1: Find each computer's share.

    Each computer does a quarter of the work: 60 ÷ 4 = 15 minutes.

  2. Step 2: Your go: add the time to combine the results.

Show the full solutionHide the solution

Step 2. The 4 computers work at the same time, so processing takes 15 minutes; combining adds 5, giving 15 + 5 = 20 minutes.

Answer: 20

Traps

Trap

Collecting more data removes bias.

It seems right because bigger samples are more reliable against random error. But bias comes from how the data was collected, so more data gathered the same way keeps the same tilt; you have to change the collection method.

An online poll has a biased sample. Does doubling the number of online responses fix it?

No. The same people are still left out; the method has to change.

Trap

Cleaning data means removing any value that looks unusual.

It seems right because cleaning removes bad values. But cleaning fixes errors and makes formats match; a real value that is simply surprising carries information and must stay.

A student truly read 120 books this year. Should cleaning remove this value?

No. It is unusual but real, so removing it would change what the data says.

What's examined

On the AP® Computer Science Principles exam, this topic belongs to Big Idea 2: Data. Expect multiple-choice questions that trace code which filters or totals a list, name the data problem in a table, or judge whether a collection method is biased. For metadata and correlation, see the note on data, metadata and information.

Practice questions

  1. Recall Which describes filtering a data set?
  • A) Changing every value in the same way
  • B) Joining two data sets into one
  • C) Showing the data as a chart
  • D) Keeping only the values that meet a condition
Show answer

Answer: D. Filtering selects the values that pass a test and leaves the rest out.

Why the others are wrong:

  • A describes transforming.
  • B describes combining.
  • C describes visualizing.
  1. Recall A data set stores one state as "CA", "Calif." and "California". Name this kind of data problem.
Show answer

Answer: Inconsistent data

Marking points:

  • One thing is recorded in several forms, so a program matching one form misses the others.
  1. Apply What is displayed as a result of running the code segment?
temps ← [28, 33, 30, 35, 29, 31]
hot ← []
FOR EACH t IN temps
{
   IF(t > 30)
   {
      APPEND(hot, t)
   }
}
DISPLAY(LENGTH(hot))
DISPLAY(hot[1])
Show answer

Answer: 3 33

Marking points:

  • 33, 35 and 31 pass t > 30; 30 does not, so hot is [33, 35, 31].
  • LENGTH(hot) is 3 and hot[1], the first element, is 33.
  1. Apply This code should display the total of the valid ages, where -1 marks a missing answer. Which line number contains the error?
1: ages ← [14, -1, 16, -1, 15]
2: total ← 0
3: FOR EACH a IN ages
4: {
5:    IF(a ≠ 0)
6:    {
7:       total ← total + a
8:    }
9: }
10: DISPLAY(total)
Show answer

Answer: 5

Marking points:

  • a ≠ 0 lets the -1 markers through, so the code displays 43 instead of 45.
  • Changing line 5 to IF(a ≥ 0) skips the markers and gives 14 + 16 + 15 = 45.
  1. Exam-style A fitness app estimates how much the average adult in a country exercises, using data only from its own users. What is the most likely problem?
  • A) The app's users may exercise more than adults in general, so the results are likely biased.
  • B) The data set is too large to process on any computer.
  • C) The data includes metadata, so the results are invalid.
  • D) Collecting more data from the same users would remove the problem.
Show answer

Answer: A. People who use a fitness app are not a fair picture of all adults, so the sample leans one way.

Why the others are wrong:

  • B: nothing in the question says the data is too large.
  • C: metadata does not make data invalid.
  • D: more data from the same users keeps the same bias.
  1. Exam-style A research team's data set is too large for one computer to process in a reasonable time. Which approach best addresses this?
  • A) Compress it with lossy compression to fit one computer.
  • B) Delete half of the data at random.
  • C) Split it across several computers that process their parts at once, then combine the results.
  • D) Run the same program twice on one computer.
Show answer

Answer: C. Distributed processing shares the work, so the parts are handled in parallel.

Why the others are wrong:

  • A loses information the analysis may need.
  • B throws away data and can change the results.
  • D does the same work twice, so it is slower, not faster.
  1. Apply A hypothetical job takes one computer 90 minutes. It is split evenly across 3 computers working at the same time, and combining their results takes 6 minutes. How many minutes does the whole job take?
Show answer

Answer: 36

Marking points:

  • Each computer does a third of the work: 90 ÷ 3 = 30 minutes, all at the same time.
  • Combining adds 6: 30 + 6 = 36 minutes.

Key points

Recall, then reveal

Say the main points from memory first, then check them.

Show key pointsHide key points
  • Filter, transform, combine and visualize are the main ways programs process data.
  • Missing, impossible and mixed-format values must be cleaned before the results can be trusted.
  • Cleaning fixes errors and formats; it never removes real values just because they are unusual.
  • Bias comes from how data is collected, and only a better collection method reduces it.
  • Very large data sets are split across computers that work in parallel, plus time to combine.

Keep learning

Explore AP Computer Science Principles tutoring →

View the full Computer Science Principles syllabus →

More in this unit

Data

All Extracting Information From Data notes

Part of Novark's AP Computer Science Principles notes