Trace table - a technique used to test algorithms to make sure that no logical errors occur
Hand tracing or 'dry running' allows you to use a trace table to
- see what code will do before you have to run it
- find where errors in your code are
Taking a program like the one below we need to keep track (trace) all the variables and outputs.
Dim y as integer = 3 For x = 1 to 4 y = y + x Loop Console.writeline(y)
To do this we create a trace table:
x | y | output |
---|---|---|
1 | 3 | |
2 | 4 | |
3 | 6 | |
4 | 9 | |
4 | 13 | 13 |
The exam will normally ask you to create a trace table of some sort so you need to be very confident with them. The exam will usually give you the headings but just in case, there are several steps in making a trace table, the first one is to note the table headings, this involves the following:
- VARIABLES: note all the variables in the piece of code you are looking at (this includes arrays). Note each variable as a heading
- OUTPUTS: note if there is an output and put this as a heading
- INPUTS: if there are inputs specified, put an inputs column and be prepared to fill it in.
It is very easy to jump right in when filling in trace tables, but you must be careful. The exam will try and trick you, so trying to predict what a trace table will do it not a good idea. In fact, the best idea is to switch your brain off and tackle the problem line by line, exactly as a computer would. Take a look at the following example:
No comments:
Post a Comment