How to Answer Trace Table Questions (OCR A Level Computer Science): Revision Note

Exam code: H446

Robert Hampton

Written by: Robert Hampton

Reviewed by: James Woodhouse

Updated on

How do I answer an OCR A Level Computer Science trace table question?

What is a trace table?

  • Trace tables are used to follow the values of variables as a program runs

  • These questions test your ability to simulate code line by line and accurately record outputs

Examiner Tips and Tricks

  • You must read the code carefully and simulate it exactly as a computer would

  • Use a pencil and annotate each step

  • The most common mistake is skipping or misreading a line

What you need to know

  • You may be asked to complete a trace table, explain a trace table, or spot errors in output

  • These questions are normally worth 3–6 marks

  • Most commonly appear in questions involving iteration, selection, and arrays/lists

  • In most cases, the structure of the table is provided, your task is to complete the missing values

Command words to look out for

Command word

What it means

Complete

Fill in the table with correct values

State

Give the value/output/result (usually a single word or number)

Explain

Say why something happens or changes in the program

Identify

Spot where something goes wrong or doesn't match expectations

How to tackle a trace table question

Follow these steps to answer trace table questions accurately:

  1. Read the code carefully

    Understand what each line does

    Look out for loops, IF statements, and variable changes

  2. Use the trace table provided
    Use the headings and row count to guide how many iterations or steps are needed

  3. Work line by line
    Simulate the program in your head or on paper

    Update each variable after every change

  4. Watch out for variable resets
    Variables declared inside loops often reset every time, don’t carry the wrong value across iterations

  5. Show the final output clearly
    If you're asked for the output, make sure it’s written exactly as it would appear on screen

Worked example

Question

This algorithm checks whether a list of numbers contains a duplicate:

01 numList ← [4, 7, 2, 7]
02 foundDuplicate ← False
03 FOR i ← 0 TO LENGTH(numList) - 2
04     FOR j ← i + 1 TO LENGTH(numList) - 1
05         IF numList[i] = numList[j] THEN
06             foundDuplicate ← True
07         ENDIF
08     NEXT j
09 NEXT i
10 OUTPUT foundDuplicate

Complete the trace table below when the algorithm is run

You may not need to use all the rows in the table

Line number

i

j

numList[i]

numList[j]

foundDuplicate

Output

  1. Read the code carefully

  • Line 1: Sets up a list of numbers: [4, 7, 2, 7]

  • Line 2: A flag called foundDuplicate starts as False

  • Lines 3–9: Nested loops compare every pair of numbers in the list

    • If a match is found, foundDuplicate becomes True

  • Line 10: The final result is printed True if a duplicate was found, otherwise False

  1. Use the trace table provided

  • The trace table has six rows, showing all the important iterations of the loop and when foundDuplicate changes

  • Some rows may have repeated values if no changes happen

  • If you reach the end and only used 2 or 3 rows, go back, you’ve likely missed a loop iteration

  1. Work line by line

05         IF numList[i] = numList[j] THEN

4 ≠ 7, so no change

05         IF numList[i] = numList[j] THEN

4 ≠ 2, so no change

05         IF numList[i] = numList[j] THEN

4 ≠ 7, so no change

05         IF numList[i] = numList[j] THEN

4 ≠ 7, so no change

05         IF numList[i] = numList[j] THEN

7 = 7 → set foundDuplicate = True

10 OUTPUT foundDuplicate

End of loops → output result

  1. Watch out for variable resets

  • Each loop changes both i and j

    • i increases from 0 to 2

    • j starts at i + 1 and goes up to 3

  1. Show the final output clearly

10 OUTPUT foundDuplicate

True

Final answer

A table with 7 rows and 7 columns showing line number, indices, list values, a duplicate check, and output for algorithm testing.

Examiner Tips and Tricks

  • You don’t need to fill in Line 06 (where the assignment happens), just show the change in foundDuplicate

  • Use a dash (–) when a column isn’t relevant (like i, j after the loops finish)

  • Add a comment column in the margin if you're writing by hand, it helps show your thought process if you make a mistake

Unlock more, it's free!

Join the 100,000+ Students that ❤️ Save My Exams

the (exam) results speak for themselves:

Robert Hampton

Author: Robert Hampton

Expertise: Computer Science Content Creator

Rob has over 16 years' experience teaching Computer Science and ICT at KS3 & GCSE levels. Rob has demonstrated strong leadership as Head of Department since 2012 and previously supported teacher development as a Specialist Leader of Education, empowering departments to excel in Computer Science. Beyond his tech expertise, Robert embraces the virtual world as an avid gamer, conquering digital battlefields when he's not coding.

James Woodhouse

Reviewer: James Woodhouse

Expertise: Computer Science & English Subject Lead

James graduated from the University of Sunderland with a degree in ICT and Computing education. He has over 14 years of experience both teaching and leading in Computer Science, specialising in teaching GCSE and A-level. James has held various leadership roles, including Head of Computer Science and coordinator positions for Key Stage 3 and Key Stage 4. James has a keen interest in networking security and technologies aimed at preventing security breaches.