Algorithm Detective
Crack open algorithms. Read them, trace them, and say exactly what they do.
Get the method right under pressure
Free interactive practice on the steps that lose marks under exam pressure.
Start revising freeWhat you'll cover
Algorithm Detective
Give a computer a problem and it needs a plan. An **algorithm**. Your job in this case: read the plan, work out what it does, and prove it. By the end you'll trace an algorithm line by line and name its purpose in one sentence. Exactly what the exam rewards.
Three big ideas
Three words the exam uses constantly, and swaps around to catch you out.
Which is which?
- Algorithm
- Decomposition
- Abstraction
- A recipe: follow the steps in order and you always reach the same result
- Splitting "build a game" into movement, scoring and graphics, then solving each
- A tube map showing lines and stops, but not real distances or street layout
Inputs → process → outputs
Almost every algorithm has the same three-part shape. Take a cash machine as the worked example.
Label the parts
To find the average of some marks: the marks are the _____, adding them up and dividing is the _____, and the average is the _____.
How we write algorithms
Two common ways: **pseudo-code** (plain, code-like steps) and **flowcharts** (boxes and arrows). You need to read *and* complete both. Here's pseudo-code that reports the larger of two numbers: `INPUT a` · `INPUT b` · `IF a > b THEN OUTPUT a ELSE OUTPUT b`
Read it
Using that algorithm, what is output when `a = 4` and `b = 7`?
- 4
- 7
- 11
- 3
Assemble the algorithm
These pseudo-code lines find the largest of three numbers, but they have been shuffled. Put them into a working order.
- `INPUT a, b, c`
- `largest ← a`
- `IF b > largest THEN largest ← b`
- `IF c > largest THEN largest ← c`
- `OUTPUT largest`
Trace it yourself
Go line by line, updating each column in order, left to right. `total` builds up as the loop runs, and `OUTPUT` is the final value.
Name its purpose
A grade-9 answer states the **overall purpose** in one sentence, not a line-by-line retelling. So: what does the algorithm you just traced actually do?
- It adds up the whole numbers from 1 to 3
- It counts up to 3
- It outputs 6 three times
- It finds the largest number between 1 and 3
Change one line
Here is the algorithm you traced. Tap the ONE line you would change to make it add up the numbers from 1 to 10 instead.
- total ← 0
- ·
- FOR i ← 1 TO 3
- ·
- total ← total + i
- ·
- END FOR
- ·
Good tracing habits
Pick the TWO things a good trace does.
- Update each column in order, left to right
- Write down every change to a variable
- Describe what each line does, separately
- Guess the final output
In the exam
Case closed. Grade-9 habits for algorithms: • Trace **accurately under time**: one column at a time, in order (the classic slip is updating out of order). • State the **overall purpose** in one sentence, not a line-by-line retelling. • Know your trio: **algorithm**, **decomposition**, **abstraction**.