To explain an algorithm, say what it is for, what it works on, what it does at each step and why. The code is one way to write it. The explanation is about the idea, and it should make sense to someone who cannot see the code.
This is a reasoning skill that runs through problem-solving explanations and algorithm design. The lesson explain an algorithm independently of a programming language works on this idea directly.
Why does this feel so hard?
When you write code, each line has a fixed meaning and the computer does the rest. When you explain, you must choose the words yourself, and two traps appear. One is to repeat the code in plain English, line for line. The other is to say something vague like “it checks everything”.
Both happen because the explanation has no frame. A simple frame fixes it.
A four-part frame
- Purpose: one sentence on what the algorithm finds or does.
- Input and output: what goes in, what comes out.
- Steps in words: two to four sentences, in order, each saying what happens to the data.
- Reason or check: why it works, or a trace with sample values.
Worked example
The algorithm finds the highest mark in a list of marks. Sample list: 14, 9, 21, 17.
Purpose. It finds the largest mark in a list.
Input and output. The input is a list of whole numbers with at least one item. The output is the largest value in the list.
Steps in words. The algorithm starts by treating the first mark as the largest seen so far. It then looks at each remaining mark in turn. Whenever a mark is larger than the largest so far, that mark becomes the new largest. After the last mark, the stored value is the answer.
Trace with the sample list.
| Mark looked at | Largest so far after this mark |
|---|---|
| 14 (first) | 14 |
| 9 | 14 (9 is not larger) |
| 21 | 21 (21 is larger) |
| 17 | 21 (17 is not larger) |
The output is 21.
Reason. The stored value is always the largest among the marks looked at so far, so at the end it is the largest of the whole list.
Weak versus strong
Weak explanation: “It has a loop. It uses an if statement to compare. Then it prints the variable.”
This names code features but says nothing about the marks, and gives no reason why the answer is the largest. A reader still does not know what the algorithm achieves.
Strong explanation: “It starts with the first mark as the largest so far, then checks each other mark in turn. If a mark is larger, it replaces the stored largest. At the end the stored value is the largest mark, because it was updated every time a bigger mark appeared.”
It says what happens to the data, in order, and gives the reason.
The mistake to watch for
Mistake: describing code features instead of behaviour. Words like loop, variable and if statement belong in a code answer. An explanation question wants what happens to the data.
Correction: for each sentence, ask “what happens to the marks here?” If the sentence could be about any program, it is too vague. Add the data and the action.
How to practise
- Take an algorithm you have already written.
- Close the code and write the four-part frame from memory.
- Trace it with a small list to confirm your words are true.
- Swap in a different sample list and check the explanation still holds.
The pseudocode trace trainer shows the stepping on small original algorithms, and the Python reasoning sandbox lets you test an idea quickly so the explanation describes something that really works.
Self-check
1. Write a one-sentence purpose for an algorithm that counts how many marks in a list are at least 50.
Show answer
"It counts how many marks in a list are 50 or more." A good answer names the data (marks), the condition (at least 50) and the result (a count).2. Which is a stronger step: “it goes round a loop” or “it looks at each mark in turn and compares it with the largest so far”?
Show answer
The second. It says what happens to the data at each step. "Goes round a loop" names a code feature without saying what it does.3. Using the sample list 14, 9, 21, 17, what is the stored largest after the third mark is looked at?
Show answer
21. The first mark sets it to 14, the second (9) leaves it at 14, and the third (21) is larger, so the stored value becomes 21.Where to go next
Work on describing a correction rather than merely showing code and connecting a trace with the final output. For the algorithm-design side, read trace a sequence with a state table.
When you are ready to have someone listen to your explanations and tighten the wording, online one-to-one Computer Science tuition starts with a paid trial lesson from RM80.