What is a Trace Table – Test Your Algorithm for Correctness

Last updated on October 7th, 2023 at 09:44 am

Grammarly Writing Support

This article on introduction to trace tables is written to help information technology students learn what a trace table is and how to prepare one to test an algorithm for correctness.

What is meant by a trace table?

In computer science and ICT, a trace table is a tool used to test an algorithm’s correctness to see the result at each step. It is a table of variables and results at each stage of the algorithm’s execution.

It is used by programmers before actually writing the program to check the values for each variable as each line of the algorithm is tested.

Are you interested in learning more about the Pascal variables? Visit our second lesson in Pascal programming. Variables are used with operators. Visit Pascal programming operators to learn more about the types of operators used in Pascal.

What is the function of a trace table?

A trace table is part of the problem solving process. It allows programmers to see how the values in an algorithm change at every step. It is used to compare the expected results with what will actually happen. In this way, programmers are able to use it to identify the places where a logic error occurs so as to correct them before proceeding to write the actual program.

Who uses a trace table?

Trace tables are typically used by programmers to test their proposed solutions to problems. It is also used to teach novice programmers to write accurate codes.

Example of a trace table

Now that you know what a trace table is, we will explore how to prepare one. For this, we will use the algorithm below:

Picture of the algorithm that is used to prepare the trace table. This crucial in helping you to understand what an algorithm is.

With a trace table, we basically focus on the changing values associated with our variables.

Test Data

Grade1: 77

Grade2: 98

Grade3: 52

StepsGrade1Grade2Grade3averageGradegrade1
>grade2
highestGradehighestGrade
<grade3
Output
10
20
30
4Please enter the first grade.
577
6Please enter the second grade.
798
8Please enter the third grade.
952
1075.67
11false
12 (a)98
13false
1498
1575.67

How do you fill a trace table?

Filling a trace table is not very difficult. You need first to set up a list of test data. The test data needs to be of different quantities, not just what the programmer expects the user to enter. This is because when a program is created, there is no predicting what a user will enter.

You need to test the algorithm to show what would happen when different values are entered.

This requires you to go through the pseudocode algorithm and check how the values change compared to expectations.

So now that you understand this, you must name the first column Steps or something similar that refers to the numbered process. Next, you need to go through the algorithm line by line. When a new variable is encountered, the programmer needs to enter the variable name in the column heading, check the assigned value of that variable, and enter that in the column that matches the step in column 1.

If a process is encountered, such as averageGrade = (grade1 + grade2 + grade3)/3 the programmer needs to perform the calculation and enter the actual answer in the column that has the assigned column name, in this case, the averageGrade column.

This step-by-step itemization can be a little more difficult when dealing with conditions and loops. However, it simply requires you to follow the steps the data leads you to. For instance, if the condition in the if statement is true, go to the next logical statement. If the condition is false, then go to the step that is next in this instance.

If you are interested in learning how to prepare a computer program using the problem-defining diagram, the algorithm, the trace table, and finish up with the Pascal program, we have a series of lessons for you. You may begin with lesson one – What is Pascal.

Before you Go

We do our best to be as thorough and clear as possible in the information we provide. However, if you have any questions or comments, be sure to leave them in the section provided below.