Skip to content

TRACE TABLES

It’s common for you to be asked to complete a trace table in an exam.

An example of a question is shown below with the trace table complete.

Stephen wants to search for an item of data held in an array.

He writes the following algorithm.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
SET list to [27, 16, 86, 47, 87, 99]
SET target to 47
SET found to false

FOR counter FROM 0 to 5 DO
    IF list [counter] =target THEN
        SET found to true
    ELSE
        SET found to false
    END IF
END FOR

IF found =true THEN
    SEND “Item found” TO DISPLAY
ELSE
    SEND “Not found” TO DISPLAY
END IF

A trace table is shown below which shows the line numbers where a variable has changed.

Work your way through the table below to see if you get the same answers.

Line List Target Counter Found
1 [27,16,86,47,87,99]
2 47
3 FALSE
4 0
6 TRUE
4 1
8 FALSE