Trace tables and finding errors Cambridge IGCSE Computer Science revision

Not started

Learn it

In plain words

To check an algorithm without a computer, you become the computer. You work through it one line at a time, writing down every change to every variable. The record you make is a trace table, and the process is called a dry run.

5 things to know

  1. A trace table has a column for each variable and a column for the output.
  2. Work through the algorithm one line at a time. Each time a variable changes, write its new value in the next row of its column.
  3. Write outputs in the output column exactly as they would appear.
  4. A trace table shows what an algorithm really does, which is how errors are found.
  5. Common errors to look for: a variable starting at the wrong value, a loop that runs one time too many or too few, and the wrong comparison, such as > where >= is needed.

Worked example

An algorithm sets Total ← 0. A loop FOR Count ← 1 TO 3 inputs Number and does Total ← Total + Number. After the loop it outputs Total. Trace it for the inputs 4, 7 and 2.

  1. Before the loop: Total is 0.
  2. Count 1: Number is 4, so Total becomes 4.
  3. Count 2: Number is 7, so Total becomes 11.
  4. Count 3: Number is 2, so Total becomes 13.
  5. The loop ends, and the output is 13.

Tips and tricks

  • Never skip a line or do two steps in your head. The marks are for each column being right at every step.
  • When correcting an error, give the line and what it should say. "Line 4 should be Count ← Count + 1."
6 questions, about 2 minutes.

It lands in your notebook with its questions as flashcards.

Trace tables and finding errors: 6 questions and answers

These are the quiz’s questions. Do the quiz first, then come back here for the ones that got you.

  1. What is a dry run?
    • running a program with no output
    • working through an algorithm by hand (the answer)
    • deleting a program
    • running a program very fast

    Each step is followed on paper, usually with a trace table.

  2. What does each column of a trace table usually stand for?
    • a line of the program
    • a variable or the output (the answer)
    • a type of error
    • a test

    A new value is written whenever a variable changes.

  3. X ← 5. X ← X * 2. X ← X − 3. What is the final value of X?
    • 4
    • 7 (the answer)
    • 10
    • 13

    5 × 2 = 10, then 10 − 3 = 7.

  4. Count ← 0. A loop runs FOR Index ← 1 TO 4 and does Count ← Count + 2. What is Count at the end?
    • 2
    • 4
    • 6
    • 8 (the answer)

    The loop runs four times, adding 2 each time.

  5. A loop should process 10 numbers but is written FOR Count ← 1 TO 9. What kind of error is this?
    • The variable has the wrong name.
    • The loop runs one time too few. (the answer)
    • The total starts at the wrong value.
    • The output is in the wrong place.

    It runs nine times. It should end at 10.

  6. An algorithm should accept marks of 50 or more as a pass, but uses IF Mark > 50. Which mark shows the error?Stretch
    • 49
    • 50 (the answer)
    • 51
    • 100

    50 should pass, but 50 > 50 is false. The test should be Mark >= 50.

Still stuck on this one?Ask in the Papermunch Discord, or help someone else who is. Discord is for ages 13 and up.Join the server

Things you can type

Or go straight to

Or browse a shelf