To explain an algorithm without a language, describe each step in plain words that name the data and the decision, then show the same steps in pseudocode. The explanation must still be correct if someone later implements it in Python, Java or a spreadsheet.
This lesson pulls together decomposition, specifications, traces and boundary tests into one habit.
How do you explain it well?
- Say what the algorithm is for in one sentence: input and output.
- List the steps in order, each starting with a verb and naming the variable.
- State each decision with its condition, for example “if the new number is smaller than Smallest”.
- Say how it stops.
- Support it with a trace on small data.
Avoid phrases that depend on one language, such as “call the min function”. That hides the logic you are being asked to show.
Worked example
Find the smallest of four numbers entered one at a time.
Plain steps:
- Input the first number and store it as Smallest.
- Repeat three more times: input a number; if it is smaller than Smallest, store it as Smallest.
- Output Smallest.
Pseudocode:
INPUT Number
Smallest ← Number
FOR Count ← 2 TO 4
INPUT Number
IF Number < Smallest THEN
Smallest ← Number
ENDIF
NEXT Count
OUTPUT Smallest
The same logic in Python:
smallest = int(input())
for count in range(2, 5):
number = int(input())
if number < smallest:
smallest = number
print(smallest)
Trace with 14, 9, 21, 9:
| Count | Number | Number < Smallest | Smallest |
|---|---|---|---|
| start | 14 | 14 | |
| 2 | 9 | true | 9 |
| 3 | 21 | false | 9 |
| 4 | 9 | false | 9 |
The output is 9. The last 9 is not smaller than 9, so Smallest stays the same. The smallest number in the list is 9, so the answer is correct.
The mistake to watch for
A common slip is to start Smallest at a fixed number.
Mistaken start:
Smallest ← 0, with the numbers 14, 9, 21, 9.No number is smaller than 0, so the output is 0, a value that was never entered.
The correction is to start from the first real value, as above. The plain-step explanation shows this clearly: “store the first number as Smallest”. An explanation that skips this step gives no way to see the fault.
Check yourself
1. Explain in plain steps an algorithm that counts how many of five numbers are negative.
Show answer
Set Count to 0. Repeat five times: input a number; if it is less than 0, add 1 to Count. After the five numbers, output Count.
2. Trace the following for the inputs −3, 4, 0, −1, 7 and say what the algorithm does.
Count ← 0
FOR I ← 1 TO 5
INPUT N
IF N < 0 THEN
Count ← Count + 1
ENDIF
NEXT I
OUTPUT Count
Show answer
Count is 0, then 1 after −3, still 1 after 4 and 0, then 2 after −1, still 2 after 7. Output 2. It counts the negative numbers.
3. Rewrite “use the len function to find how many items there are” as a language-independent step.
Show answer
“Count the items by starting a counter at 0 and adding 1 for each item.” This describes the logic without naming a built-in function.
Where this leads next
With design habits in place, move on to repetition and arrays, then try the mixed practice set. The safe Python sandbox lets you run a short version of the example above and compare it with your trace.
A teacher who hears your explanation can pinpoint missing steps quickly, and that is part of our online one-to-one Computer Science tuition.