0984

Pseudocode and Flowcharts

Algorithm Design and Problem Solving · 4 question types

Exam Frequency Analysis

Past paper frequency (2018 to 2024)

This topic accounts for approximately 11% of your exam marks.

stable
Medium
Stable11%

The most marks-dense topic. Both papers test pseudocode writing and trace tables every sitting.

A trace table is a table used to record the value of each variable at every step of an algorithm, so that the algorithm can be hand-executed and checked for correctness.

Trace tables are essential for finding logic errors, where a program runs without crashing but produces the wrong output. By stepping through the algorithm with specific test data, the programmer can spot the exact step where the variables go wrong.

An algorithm like the "find the highest of ten numbers" flowchart below, with a counter and a decision inside a loop, is a typical candidate for a trace table:

Flowchart to find the highest of ten numbers: START, Count = 1, prompts to enter numbers, INPUT Highest then a loop that inputs each Number, increments Count, tests Number > Highest to update Highest, and tests Count < 10 to repeat before outputting the highest number and STOP
Source: Trace Table in Computer Science by Save My Exams

How to set up a trace table

  1. List the variables the algorithm uses as column headings. Include any output as the last column.
  2. Number the rows (optional, but useful for long algorithms).
  3. Walk through the line by line, updating the relevant column whenever a variable changes.
  4. Note any output in the OUTPUT column when an OUTPUT statement is reached.
  5. Continue until the algorithm finishes (the loop terminates or the program reaches END).

Why trace tables are useful

  • Finding logic errors: if Highest does not update when it should, the trace table reveals the exact step where the bug is.
  • Verifying loop termination: walking through the loop counter line by line shows that the loop ends when it is meant to.
  • Understanding unfamiliar algorithms: a trace table forces a careful, step-by-step reading and often makes the purpose of the algorithm obvious.
  • Picking suitable test data: tracing with boundary and abnormal data (topic 18) checks the program's edge cases.
Worked example

Complete the trace table for this algorithm

The algorithm below reads four numbers one at a time and accumulates a running total. Complete the trace table for the inputs 3, 7, 2, 8 in that order.

Total ← 0
FOR i ← 1 TO 4
    INPUT Num
    Total ← Total + Num
NEXT i
OUTPUT Total

Solution:

iNumTotalOUTPUT
0
133
2710
3212
4820
20

Key points when filling in a trace table:

  • Only update a column in the row where that variable actually changes — leave all other cells blank.
  • Record OUTPUT only when the OUTPUT statement is reached (after the loop ends here).
  • The loop counter i updates at the start of each iteration; Num and Total update in that same pass through the loop body.