Skip to content
SPM Tuition
Computer Science chapter guide

Algorithm reasoning and test design

Your algorithm looks right on paper, yet one input always breaks it and you cannot say why.

Algorithm reasoning means deciding whether a set of steps really does the job, using evidence and not a feeling. This section teaches four habits for that: tracing, comparing, choosing test data and telling two kinds of checking apart.

It sits inside problem solving and algorithms, and it assumes you can already read basic pseudocode.

What does this section cover?

Each lesson takes one skill and applies it to a small, original algorithm.

How do the four skills connect?

Tracing is the base. A trace table tells you what the algorithm actually does, and that is the only fair starting point for testing or comparing it.

Test data comes next, because a trace is only as good as the input you feed it. Comparing two algorithms then means tracing both on the same inputs, and validation versus verification tells you what each check can and cannot prove.

A small example to orient you

This algorithm should count how many of four marks are 50 or above.

SET count = 0
FOR i = 1 TO 4
  INPUT mark
  IF mark > 50 THEN
    SET count = count + 1
  END IF
NEXT i
OUTPUT count

Try the marks 62, 50, 49 and 80. The algorithm outputs 2, but the correct answer is 3, because 50 counts as a pass.

A normal input such as 62 would never reveal the fault. The boundary value 50 does, and the trace shows the comparison 50 > 50 is false. The repair is to write >=, which is one character and a whole mark.

Who should start where?

Pick the lesson that matches the mistake you keep making.

If this happens to you Start with
Your final value is wrong and you cannot see why Trace table lesson
You are told to “test your algorithm” and freeze Test data lesson
Two answers look right and you cannot choose Comparing two algorithms
You mix up validation and verification Validation versus verification

The restricted pseudocode trace trainer lets you practise tracing on your own device, and the mistake log and paper-error review helps you record which kind of slip you repeat.

When you are ready to test the whole set, use the section practice questions. If you would like a teacher to go through your own pseudocode, see online one-to-one Computer Science tuition.

Common questions

Is this the SPM Computer Science syllabus or a general coding course?

It follows the SPM Computer Science (Sains Komputer) subject, which works with pseudocode, flowcharts and trace tables rather than one programming language. The examples here are original and use plain pseudocode so the reasoning transfers to whatever language your school teaches.

Where should I start in this section?

Start with the trace table lesson if you lose track of variable values, or the test data lesson if you are unsure which inputs to try. If you already trace well, go straight to comparing two algorithms.

Do I need to be good at programming to use these pages?

No. Every page reads the algorithm line by line and keeps the code short. If you can follow an IF statement and a loop, you can follow the lessons, and the trace method itself teaches the rest.

Are the practice questions copied from past papers?

No. Every example and question here is original, written for this site and checked by hand. They practise the same reasoning skills without reproducing any examination paper.

If your algorithms pass the sample input but fail on the paper, one-to-one Computer Science lessons let a teacher trace your own pseudocode with you and find the exact line that misbehaves.

  • Online one-to-one lessons for your child with an experienced teacher.
  • Your first class is a one-hour trial, from RM50. The fee is agreed before you book.
  • Happy with the teacher? Continue with lessons of about 1.5 hours. If not, ask for another teacher.