Short on time? This page is the recap. For explanations and worked examples, use the full study guide.
Recap
- Programs process data to acquire information; the work is iterative and interactive.
- Transform: apply the same operation to every element (same number of elements).
- Filter: keep only elements that meet a condition (usually fewer elements).
- Combine or compare: reduce many elements to one result, such as a total or a maximum.
- Visualise: show data as a chart, graph or table.
- Combining data sources, clustering (grouping similar items) and classifying (assigning categories) help gain insight.
- Search tools, filtering systems and spreadsheets help find information and trends.
- Patterns can emerge when data are transformed; insight depends on clean, representative data.
Key relationships
| Process | Length of result | Typical code shape |
|---|---|---|
| Transform | same as input | APPEND(result, f(item)) for every item |
| Filter | same or shorter | IF (condition) { APPEND(result, item) } |
| Combine | a single value | running total or running maximum |
| Visualise | a picture | chart of totals or counts |
Assumptions and conventions
- Lists in the pseudocode are written
[a, b, c]and are visited in order byFOR EACH; this is Marlbridge’s rendering of the reference notation. - In a trace table, record the loop variable and every variable that changes, after each pass.
- When data come from two tables, state the shared field used to combine them.
Mistakes to avoid
- Mixing up filter and transform.
- Updating a running total outside the IF when only some elements should count.
- Forgetting the starting value of a total or count.
- Reading a chart as proof of cause.
- Skipping cleaning before counting.
- Giving only totals when the groups differ in size.
Two quick worked examples
1. For [3, 8, 5, 10], the code total ← 0 then FOR EACH n IN list { IF (n > 4) { total ← total + n } } adds 8, 5 and 10, so it displays 23. It filters and then combines.
2. To double every price in a list of 5 prices, apply the same operation to each element: a transform with a result list of length 5. To keep only prices above 20, use a filter; the result list may be shorter.
A revision routine
Take a list of six numbers and write three short pieces of code: one that filters, one that transforms every element and one that combines. Trace each on paper and give the output. Then write the sequence of steps you would use to answer a question about two linked tables, and say what each step shows.
Quick self-check
- Trace
FOR EACH n IN [3, 8, 5] { IF (n > 4) { DISPLAY(n) } }. (Displays 8 then 5.) - A program doubles every number in a list of 6. How long is the result? (6; it is a transform.)
- Why compare averages per runner rather than totals for clubs of different size? (Totals favour the larger club.)
Next: practice questions.