Skip to content
Marlbridge

AP® Computer Science A · Unit 4 · Topic 4.2

Introduction to Using Data Sets: Revision Notes (Computer Science A 4.2)

One-page recap of data sets, processing values one at a time, and planning algorithms with tables, flowcharts and written language, with traces of count, total and maximum plans.

These notes recap Topic 4.2. For worked examples, read the study guide.

Recap

  • A data set is a collection of specific pieces of information.
  • Data sets can be manipulated and analysed to solve a problem or answer a question.
  • Values are accessed and used one at a time and then processed to give the desired outcome.
  • Data can be represented in a chart or table, which can be used to plan the algorithm.
  • Patterns and algorithms can be described in written language or diagrams (such as a flowchart).

Key relationships

Plan step What it does Example (rainfall data)
Set up Create what must be remembered wetDays = 0, or best = first position
Repeat for each value Examine one value, update what is remembered If reading >= 10, add 1
Report Give the answer after all values Report wetDays

Standard plans in outline

Task Remember Update rule
Count with a property A count (0 at start) Add 1 when the property holds
Total A running total (0 at start) Add each value
Largest Best so far (start from the first value) Replace it when a value is larger
Average Total and number of values Total divided by number of values at the end

Worked reminder

Rainfall on seven days is 0, 12, 5, 20, 0, 8, 15 mm. The count of days with at least 10 mm is 3 (Tue, Thu, Sun). The largest is 20 mm on Thursday. The total is 60 mm and the mean is 60 ÷ 7, about 8.57 mm. A plan that resets the count to 0 inside the loop reports only whether the last reading qualifies, so it gives 1 instead of 3.

Checking a plan

  1. Choose a data set small enough to trace by hand, with an answer you can see by eye.
  2. Write one table row per value and one column per remembered quantity.
  3. Compare the final row with the answer you expected.
  4. If they differ, look first at where each remembered quantity is set up and where it is updated.

Mistakes to avoid

  • Putting a set-up step (a count or total starting at 0) inside the repeated part.
  • Starting a maximum at 0 for data that can be negative.
  • Forgetting to say what is reported at the end.
  • Treating the data set and the Java array as the same thing.
  • Skipping the trace table.

Quick self-check

  1. What are the three parts of most plans for a data set? Answer: set up, repeat for each value, report.
  2. For the data 3, 8, 2, 9, 4, how many values are below 5? Answer: 3 (the values 3, 2 and 4).
  3. Why should a maximum start from the first value? Answer: starting from 0 fails if all values are negative; the first value is always a valid starting candidate.
  4. Name a way to represent an algorithm other than code. Answer: a flowchart, a table or written steps.

AP® and Advanced Placement® are trademarks registered by the College Board, which is not affiliated with, and does not endorse, this website. Marlbridge is an independent tuition provider. It is not an authorized AP course provider, an AP school or an exam centre, and these resources are not official College Board materials. Reading them or doing simulations does not meet the laboratory requirement of an AP science course.