What is Trace table?

A table that records how the values of variables change as a program is executed line by line by hand. It is used to check the number of iterations and the final values and to locate mistakes. Because it is done on paper, it is also called desk checking.

Japanese name: トレース表

Trace table appears in 1 practice question across 1 topic, including Programming Basics (Pseudocode Tracing).

Field: Programming Basics (Pseudocode Tracing)

Making a trace table

List the variables and the truth values of conditions as columns, and fill in their values one row at a time in execution order. For a program that starts with x ← 1 and repeats x ← x × 3 while x < 100, the x column changes 1, 3, 9, 27, 81, 243, and the condition becomes false on the sixth test. Writing only the variables whose values change keeps the table easy to read.

Where mistakes happen

The first and last iterations are the easiest to get wrong in a trace. Check whether the final value of a for loop is included, when the while condition is tested, and whether array indices start at 1 or 0. Assignments run in order from the top, so remember that after x ← y, the original value of x is gone when y ← x runs.

Tracing recursive calls

Each recursive call gets its own set of arguments and local variables. Drawing the calls as a tree and writing each call's arguments and return value at its node makes the number of calls and the return values easy to count. The tree also shows how the output order changes depending on whether a value is output before or after the recursive calls.

FAQ

How does tracing differ from stepping through a program in a debugger?

Both follow the behavior line by line, but a trace table is done by a person on paper, while a debugger actually runs the program, pausing it as it goes. In an exam there is no environment to run programs, so the ability to check with a trace table is essential.

Must a long loop be traced in full?

Tracing the first few iterations to find the pattern in how the values change often lets you calculate the rest. Always check the last iteration and the exit condition, however, to avoid off-by-one errors.

Trace table in the explanations

Questions that mention Trace table (1)

  1. The following program repeatedly multiplies x by 3. What is the value of n after it runs?

Books on Programming Basics (Pseudocode Tracing) Ad

As an Amazon Associate I earn from qualifying purchases.

Related terms

Argument Array Bitwise operation Control structure Integer division Modulo operation Object-oriented programming Off-by-one error Pseudocode Return value

Back to the glossary