Skip to content
IGCSE·Tuition
Computer Science · Lessons

Explain an algorithm independently of a programming language

You can often write the code, but a question asks you to explain what it does, and the words will not come.

On this page
  1. How do you explain it well?
  2. Worked example
  3. The mistake to watch for
  4. Check yourself
  5. Where this leads next

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?

  1. Say what the algorithm is for in one sentence: input and output.
  2. List the steps in order, each starting with a verb and naming the variable.
  3. State each decision with its condition, for example “if the new number is smaller than Smallest”.
  4. Say how it stops.
  5. 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:

  1. Input the first number and store it as Smallest.
  2. Repeat three more times: input a number; if it is smaller than Smallest, store it as Smallest.
  3. 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:

CountNumberNumber < SmallestSmallest
start1414
29true9
321false9
49false9

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.

Questions people ask

Why explain an algorithm without code?

The same algorithm can be written in many languages. An explanation in plain steps or pseudocode shows that you understand the logic, not just the syntax of one language. Exam questions often ask for exactly this.

What is the difference between an algorithm and a program?

An algorithm is the set of steps that solves a problem, independent of any language. A program is one implementation of an algorithm in a specific language that a computer can run.

Do I need Python for this lesson?

No. The pseudocode is the main form. Python is shown beside it so you can see that the logic is identical, which is useful if your course or classwork uses Python. Check which notation your exam year uses.

Updated:

Your next step

If you can code an idea but struggle to explain it in words, a one-to-one teacher can listen to your explanation and help you tighten it into clear steps.

Paid one-hour trial at your assigned teacher’s confirmed rate, starting from RM80. Other fees, schedules and ongoing arrangements are confirmed directly with your teacher after the trial class.

Tuition is arranged with a parent or guardian. Send them this page on WhatsApp and they can enquire for you.

Parent or guardian? Enquire here

9,000+ students helped through our service