Testing Algorithms with Trace Tables (Desk Checks and Dry Runs)

How do you know your algorithm works before you type it into a computer? You do a desk check (also called a dry run): you pretend to be the computer and follow each step with pencil and paper, using a trace table to record the values.

Build on what you learned in Forms 1–3

These Lower School ICT posts cover the basics of this topic:

In this post:

  • What is a desk check / dry run?
  • How to build a trace table
  • Worked example with a loop
  • Using a trace table to find an error
  • Choosing test data

Desk checks and trace tables

A trace table has a column for each variable (identifier) and, if needed, a column for the output. You fill in one row for each pass (each time the loop runs or a value changes). At the end, compare the output with what you expected – if they match, the algorithm is correct for that test data.

Steps to complete a trace table

  1. Draw a column for each variable, plus Output.
  2. Go through the algorithm one line at a time.
  3. Every time a variable is given a new value, write it in its column (on a new row for each pass of a loop).
  4. When something is printed, write it in the Output column.
  5. Keep going until the algorithm ends.

Worked example

Pseudocode

1  total ← 0
2  count ← 1
3  WHILE count <= 4 DO
4      total ← total + count * 2
5      count ← count + 1
6  ENDWHILE
7  PRINT total
PasscounttotalOutput
Start10
122
236
3412
4520
End (count <= 4 is FALSE)52020

Notice that total goes 0 → 2 → 6 → 12 → 20, because each time we add count × 2 (2, 4, 6, 8). When count becomes 5, the condition count <= 4 is FALSE, so the loop stops and 20 is printed.

Using a trace table to find an error

Kerry-Ann wants to find the average of 3 numbers but her algorithm says average ← num1 + num2 + num3 / 3. Trace it with 60, 70 and 80:

num1num2num3averageExpected
607080156.6770

The trace table shows the answer is wrong. Only num3 was divided by 3! The fix is average ← (num1 + num2 + num3) / 3. This is a logic error – more on that in Section 8.

Choosing test data

Test with normal data (typical values), boundary data (values right at the edge, e.g. a mark of exactly 50 when the pass mark is 50) and erroneous data (values that should be rejected, like a mark of −5).

Try it: Trace table filler

Complete the trace table for this algorithm. Each row shows the values at the end of that pass.

x ← 3
y ← 1
FOR i ← 1 TO 3 DO
    y ← y * x
    x ← x − 1
ENDFOR
PRINT y
iyx
(start)13
1
2
3

What is printed at the end? (Answer: 6.)

Related

Related class recordings:
• How to Approach a Dry run using test data and trace tables to uncover errors in your algorithm
• Trace Table Exercise – Form 5 Opt D – 2025-10-08_08-55-28
• Reinforcement of Control Structures, Trace table test – Live class 5 OptD (2026-10-07_09-56-46)

Paper 1 practice (multiple choice)

Choose the best answer for each question. Try them all before you check.

1. A trace table is used to
(A) translate a program
(B) test an algorithm by recording the values of variables
(C) draw a flowchart
(D) store a program

2. In a trace table, the column headings are usually
(A) the line numbers only
(B) the variable names (identifiers)
(C) the flowchart symbols
(D) the programmer’s name

3. Working through an algorithm by hand to check it is called a
(A) compile
(B) dry run
(C) syntax check
(D) link

4. Given x ← 5, then x ← x + 3, then x ← x * 2, the final value of x is
(A) 10
(B) 16
(C) 13
(D) 8

5. Testing a pass-mark program with a mark of exactly 50 uses
(A) erroneous data
(B) boundary (extreme) data
(C) random data
(D) no data

Show answers

1. B
2. B
3. B
4. B
5. B

Paper 2 practice (structured question)

Study the following algorithm:

sum ← 0
FOR n ← 1 TO 4 DO
    READ value
    sum ← sum + value
ENDFOR
average ← sum / 4
PRINT sum, average

(a) Explain what is meant by a “dry run”. (2 marks)

(b) Copy and complete a trace table for the algorithm using the data 6, 3, 9, 2. (4 marks)

(c) State the output of the algorithm for this data:

(i) the sum (1 mark)

(ii) the average (1 mark)

(d) Identify the type of loop used in the algorithm. (1 mark)

Total: 9 marks

Show answers

(a) Working through the algorithm by hand, step by step (1 mark), recording the values of variables to check that the results are correct (1 mark).

(b)
• n = 1, value = 6, sum = 6 (1 mark)
• n = 2, value = 3, sum = 9 (1 mark)
• n = 3, value = 9, sum = 18 (1 mark)
• n = 4, value = 2, sum = 20 and average = 5 (1 mark)

(c)

(i) 20 (1 mark)

(ii) 5 (1 mark)

(d) FOR loop / counter-controlled loop (1 mark).

Next: Low-Level vs High-Level Languages and the Steps in Implementing a Program

Syllabus link: This post is relevant to the CSEC® Information Technology Syllabus (CXC 30/G/SYLL 17), Section 7: Problem-Solving and Program Design, Specific Objective 7 (“test algorithms for correctness”).

Attributions to media used in this post:

No third-party images are used in this post. Embedded videos are credited on YouTube to their channels.

© 2026 Vedesh Kungebeharry. All rights reserved.