2 - Practical Problem Solving and Programming / Trace Tables
|
|
Trace Tables
Once a you have finished coding your program and have started the testing process you will need to think about the structure of your testing. Trace tables are an ideal method for testing the efficiency and outcome of an algorithm.
Trace Tables
As an algorithm runs, the variables / arrays will be called upon, changed, put through loops and selection all on the way to the programs main goal. A trace table provides a structured method of recording and studying the results and data for each step of the algorithm.
In order for this to work you will first need to devise your test data. You will then need to draw a table, each column of the table should be labeled with the variable, array, output etc that you are trying to keep track of. At IGCSE level you will be provided with the table and test data for a given algorithm, you will just need to demonstrate the ability to logically follow through the algorithm.
Example Scenario.
You are given the following algorithm (flow chart):
In order for this to work you will first need to devise your test data. You will then need to draw a table, each column of the table should be labeled with the variable, array, output etc that you are trying to keep track of. At IGCSE level you will be provided with the table and test data for a given algorithm, you will just need to demonstrate the ability to logically follow through the algorithm.
Example Scenario.
You are given the following algorithm (flow chart):
To test this algorithm you are given the following test data:
1.8, 2.0, 1.0, 1.3, 1.0, 2.5, 2.0, 1.3, 1.8, 1.3, -1
These values are to be entered as the engine size 1 at a time.
Next we are given a table to fill in and record the results of entering these values. The table will look like this:
1.8, 2.0, 1.0, 1.3, 1.0, 2.5, 2.0, 1.3, 1.8, 1.3, -1
These values are to be entered as the engine size 1 at a time.
Next we are given a table to fill in and record the results of entering these values. The table will look like this:
Engine |
Count |
Number |
Size |
Average |
Output |
Now that we have the algorithm, test data and Trace table it is time to start working through the algorithm.
Initial steps
To start the process of we will need to work through the flow chart step by step.
1. The first step of the flow chart is to set the engine, count and number variables to the value of 0
2. The next step is to accept the first user input and use it to set the value of the Size variable. This input will be the first item of the test data which is 1.8.
This will leave our table looking like this:
Initial steps
To start the process of we will need to work through the flow chart step by step.
1. The first step of the flow chart is to set the engine, count and number variables to the value of 0
2. The next step is to accept the first user input and use it to set the value of the Size variable. This input will be the first item of the test data which is 1.8.
This will leave our table looking like this:
Engine |
Count |
Number |
Size |
Average |
Output |
O |
O |
O |
1.8 |
||
Now we must follow through the flow chart to determine and document how the values will change.
Looking at the flow chart below you can see that we have already completed steps 1 and 2.
We then take the value of Size (1.8) and we are asked "Is Size = -1?"
The answer to this is no and therefor we progress to the next question "is Size > 1.5?"
The answer to this is yes which takes us to step 3.
3. We must add 1 to the value of Count - at this stage count is 0, add 1 to this = 1. You should now write "1" in the Count column of the trace table.
4. Step 4 requires us to add 1 to Number - at this stage Number is 0, add 1 to this = 1. You should now write "1" in the Number column of the trace table.
5. Step 5 requires you to add the Size variable to the Engine variable. The engine variable is currently 0, 0 + 1.8 = 1.8. You should write "1.8" into the Engine column of the trace table.
Looking at the flow chart below you can see that we have already completed steps 1 and 2.
We then take the value of Size (1.8) and we are asked "Is Size = -1?"
The answer to this is no and therefor we progress to the next question "is Size > 1.5?"
The answer to this is yes which takes us to step 3.
3. We must add 1 to the value of Count - at this stage count is 0, add 1 to this = 1. You should now write "1" in the Count column of the trace table.
4. Step 4 requires us to add 1 to Number - at this stage Number is 0, add 1 to this = 1. You should now write "1" in the Number column of the trace table.
5. Step 5 requires you to add the Size variable to the Engine variable. The engine variable is currently 0, 0 + 1.8 = 1.8. You should write "1.8" into the Engine column of the trace table.
At this stage your Trace table should look like this:
Engine |
Count |
Number |
Size |
Average |
Output |
O |
O |
O |
1.8 |
||
1.8 |
1 |
1 |
|||
Looking at the flow chart you will see that after step 5, you are looped back up to input the next test value for the Size variable. You should enter the next value which is 2.0 and then once again follow through the algorithm whilst recording the changes.
You ill continue to follow through until the algorithm ends.
The final table for this algorithm and test data will look like this:
You ill continue to follow through until the algorithm ends.
The final table for this algorithm and test data will look like this:
Engine |
Count |
Number |
Size |
Average |
Output |
O |
O |
O |
1.8 |
||
1.8 |
1 |
1 |
2.0 |
||
3.8 |
2 |
2 |
1.0 |
||
4.8 |
3 |
1.3 |
|||
6.1 |
4 |
1.0 |
|||
7.1 |
5 |
2.5 |
|||
9.6 |
3 |
6 |
2.0 |
||
11.6 |
4 |
7 |
1.3 |
||
12.9 |
8 |
1.8 |
|||
14.7 |
5 |
9 |
1.3 |
||
16.0 |
10 |
-1 |
|||
1.6 |
|||||
1.6, 5 |
Empty Cells
Looking at the table above you will notice that the Count column has a number of blank / empty cells. This does not mean that the Variable is empty, in-fact it just signifies that the value is un changed. from the last run through. If a value does not change then you should leave it blank as the purpose of a trace table is to record changes.
For the purpose of the IGCSE it is also acceptable to fill in the empty cells with the data that they contain. In this case the completed table would look like this:
For the purpose of the IGCSE it is also acceptable to fill in the empty cells with the data that they contain. In this case the completed table would look like this:
Engine |
Count |
Number |
Size |
Average |
Output |
O |
O |
O |
1.8 |
||
1.8 |
1 |
1 |
2.0 |
||
3.8 |
2 |
2 |
1.0 |
||
4.8 |
2 |
3 |
1.3 |
||
6.1 |
2 |
4 |
1.0 |
||
7.1 |
2 |
5 |
2.5 |
||
9.6 |
3 |
6 |
2.0 |
||
11.6 |
4 |
7 |
1.3 |
Value |
|
12.9 |
4 |
8 |
1.8 |
||
14.7 |
5 |
9 |
1.3 |
||
16.0 |
5 |
10 |
-1 |
||
1.6 |
|||||
1.6, 5 |
Vertical Divider