Skip to main content
EnglandComputer ScienceSyllabus dot point

How do you use a trace table to work through an algorithm and find its output or its purpose?

Using trace tables to determine the output of an algorithm and to follow how the values of variables change, and determining the purpose of a simple algorithm.

An OCR J277 2.1.2 answer on using trace tables to follow an algorithm step by step, record how variable values change, find the output, and determine the purpose of a simple algorithm.

Generated by Claude Opus 4.810 min answer

Reviewed by: AI editorial process; not yet individually human-reviewed

Have a quick question? Jump to the Q&A page

Jump to a section
  1. What this dot point is asking
  2. What a trace table is
  3. How to build a trace table
  4. Determining the purpose of an algorithm
  5. Try this

What this dot point is asking

OCR wants you to use a trace table to follow an algorithm by hand, recording how each variable changes step by step, so you can find the output. You must also be able to look at a short algorithm and determine its purpose, that is say what it calculates overall. Tracing is a frequent Paper 2 skill and is also how you debug an algorithm.

What a trace table is

How to build a trace table

A neat way to lay the trace out:

i numbers[i] max output
4
1 9 9
2 2 9
3 7 9 9

Determining the purpose of an algorithm

To work out what an algorithm is for, step back and look at the overall effect rather than each line. Ask what goes in, what comes out, and what the loop or calculation achieves. A loop that adds each value to a running total is summing; if it then divides by the count it is averaging; a loop that compares each value to a stored best is finding a maximum or minimum; a loop that swaps out-of-order pairs is sorting. Naming the overall job (the average of the numbers, the largest value, a count of how many pass a test) is what the question rewards.

Try this

Q1. State what a trace table is used for. [1 mark]

  • Cue. To record how the variables in an algorithm change as it runs, so you can find its output and spot errors (a dry run).

Q2. After the loop total = 0; for i = 1 to 3; total = total + i; next i, what value does total hold? [1 mark]

  • Cue. 6 (1 + 2 + 3).

Q3. An algorithm reads ten numbers, counts how many are greater than 100, and prints the count. State its purpose in one sentence. [1 mark]

  • Cue. It counts (and outputs) how many of the ten numbers entered are greater than 100.

Exam-style practice questions

Practice questions written in the style of OCR exam questions on this dot point, with worked answer explainers. The year tag is the paper they imitate, not the source.

OCR 20214 marksComplete a trace table for the algorithm below and state the value that is output. x = 5 y = 0 while x > 0 y = y + x x = x - 1 endwhile print(y)
Show worked answer →

Trace the loop, writing each new value of x and y on its own row. Starting x = 5, y = 0:

Pass 1: y = 0 + 5 = 5, x = 4. Pass 2: y = 5 + 4 = 9, x = 3. Pass 3: y = 9 + 3 = 12, x = 2. Pass 4: y = 12 + 2 = 14, x = 1. Pass 5: y = 14 + 1 = 15, x = 0. The condition x > 0 is now false, so the loop stops.

The value output is 15 (this is 5 + 4 + 3 + 2 + 1, the sum of 1 to 5).

Markers reward a correct row for each pass showing both variables changing, and the correct final output of 15. A common slip is updating x before adding it, or stopping one pass too early.

OCR 20222 marksLook at the algorithm below and state its purpose (what it calculates). total = 0 for i = 1 to 5 num = int(input("Enter a number: ")) total = total + num next i average = total / 5 print(average)
Show worked answer →

Work out what the algorithm does overall, not line by line. It reads in five numbers (the loop runs five times, each time reading a number into num), adds each to a running total, then divides the total by 5 and prints the result.

Purpose: it calculates and outputs the average (mean) of five numbers entered by the user.

Markers reward identifying the overall purpose (the average or mean of five numbers), not just describing each line. Saying "it adds numbers up" only is not enough, because it misses the division that makes it an average.

Related dot points

Sources & how we know this