Skip to content
SPM Tuition
Computer Science chapter guide

Advanced programming practice for SPM Computer Science

Your program runs but the output is wrong, and your trace table does not show why.

Advanced programming practice has four skills: storing data in arrays, tracing searching and sorting, debugging, and testing with a table of expected outputs. Learn them in that order, because each one builds on the one before.

It is part of the SPM Computer Science guide. Confirm the current syllabus scope with your school and the Lembaga Peperiksaan website.

What does this area cover?

Each page trains one habit: work out what the program does step by step, instead of guessing.

Order Skill What you will be able to do
1 Working with arrays and structured data Store, read and update a list of values or records
2 Tracing searching and sorting algorithms Follow linear search, binary search and a simple sort by hand
3 Debugging syntax, logic and runtime errors Name the kind of error and fix the right line
4 Creating a test table with expected outputs Choose test data and predict results before running

Test all four together in the practice set.

One small example

An array holds five quiz marks: 6, 9, 4, 9, 7. A program is meant to print the highest mark, but it starts with the variable high set to 0 and only updates it when a mark is greater than high.

The sample run prints 9, which looks right. A test table asks a harder question: what if every mark is negative, say −3, −1, −8? The program would print 0, a value that is not in the array at all.

The sample run hides the bug and the table shows it. That is why arrays, tracing and testing go together.

Who should start where?

If you are unsure how to read an array, begin with the first lesson. If you can follow an algorithm but lose the values halfway, begin with tracing and use a trace table.

If your code gives an error message, begin with debugging. If it runs but gives the wrong output, read my code runs but gives the wrong result first.

What should I do next?

Work through the lessons in order, then try the practice set. To trace a new algorithm with a teacher, see online one-to-one Computer Science tuition.

Common questions

Is this page about the SPM Computer Science syllabus or general coding?

It follows the Sains Komputer topics on programming and algorithms, with small worked examples. Confirm the current syllabus scope and programming language expectations with your school teacher and the Lembaga Peperiksaan website.

Which programming language do the examples use?

Examples use short pseudocode that you can rewrite in any language your school teaches. The skill is reasoning about what the program does, and that does not depend on the language.

Where should I start if my program gives wrong answers?

Start with debugging, then go to tracing. Knowing whether the error is in syntax, logic or at run time tells you where to look, and a trace table shows the line where the values go wrong.

If you can read code but your own programs keep failing, one-to-one Computer Science lessons let a teacher trace your actual code with you and find the line where your thinking and the computer's diverge.

  • 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.