Inputs, Processing and Outputs
Every algorithm has three components:
Input
Data supplied to the algorithm (from user, file, sensor, etc.)
Processing
Operations performed on the data (calculations, comparisons, assignments)
Output
Results produced by the algorithm (displayed, stored, returned)
When analysing an algorithm, identify what its inputs, processing steps, and outputs are, then determine its purpose from its structure.
What is a Trace Table?
A trace table (also called a dry run) is a method of manually tracking how variables change as an algorithm executes, line by line. Use it to:
- Check an algorithm produces the correct output for a given input
- Find bugs (logic errors) in an algorithm
- Understand what an algorithm does without running it on a computer
Each column = a variable or an output. Each row = the state after executing one step.
How to Complete a Trace Table
- Create a column for each variable and a column labelled OUTPUT
- Read the algorithm line by line
- When a variable changes, record its new value in the correct column
- When OUTPUT is called, record the value in the OUTPUT column
- Repeat until the algorithm finishes
Worked Example 1 — Simple Counter (WHILE loop)
x ← 1
WHILE x <= 4
OUTPUT x
x ← x + 1
ENDWHILE
| x | x ≤ 4? | OUTPUT |
| 1 | True | 1 |
| 2 | True | 2 |
| 3 | True | 3 |
| 4 | True | 4 |
| 5 | False — STOP | — |
Purpose: Outputs integers 1 to 4.
Worked Example 2 — Finding the Maximum (FOR loop)
nums ← [4, 9, 2, 7]
maxVal ← nums[0] // start at first element
FOR i ← 1 TO 3
IF nums[i] > maxVal THEN
maxVal ← nums[i]
ENDIF
ENDFOR
OUTPUT maxVal
| i | nums[i] | maxVal | nums[i] > maxVal? |
| — | — | 4 | — |
| 1 | 9 | 9 | True → update |
| 2 | 2 | 9 | False |
| 3 | 7 | 9 | False |
Output: 9 Purpose: Finds and outputs the largest value in the list.
Determining the Purpose of an Algorithm
AQA questions often ask: "State the purpose of this algorithm." Strategy:
- Trace the algorithm with the given inputs
- Look at the output — what value(s) does it produce?
- Look for patterns: counting, summing, finding max/min, searching?
- Write one clear sentence: "The algorithm finds the largest value in a list and outputs it."
Exam tip: Show every change — even if a variable stays the same, write its current value in each row. Examiners want to see you tracking it, not just the step where it changes.
⚠️ Common Mistakes
- Forgetting to check the WHILE condition before entering — the body may never run
- Off-by-one errors in FOR loops: FOR i ← 1 TO 4 runs 4 times (not 3)
- Not including a condition column in the trace table — you need it to show why a loop stops
- Describing the purpose too vaguely — "it does something with numbers" is not enough