Tracing an Algorithm
What You Will Learn:
What is a trace table
How to construct a trace table
A trace table is a technique used to test algorithms in order to verify that no logical errors occur while an algorithm is being processed. The table usually takes the form of a multi-column, multi-row table with each column showing a variable, and each row showing each number input into the algorithm and the subsequent values of the variables.
Trace tables are typically done on paper.
Trace tables are used to test the logic of pseudocode before it is implemented in a high-level language. They are also used to debug code in a program that is not working.
Below is an example of a trace table.
The trace table shows the contents of each variable at each stage of the loop. The table also shows that when the loop is finished the variable A will contain the value 120.
Resources:
Trace Table classwork - example (hard copy)
Homework assignment
Trace tables - Exam questions (hard copy)