KwickAcademy Course Topics · 6 min · free
Trace tables and identifying/correcting errors
A trace table records a dry run: one column per variable plus output, with a new value each time it changes. Syntax errors stop a program running, logic errors give wrong answers, runtime errors crash while running.
Follows the syllabus of: Cambridge IGCSE Grade 9 Computer Science (0478)
On screen in this lesson
What is a trace table?
| Dry run: follow the steps by hand |
| Trace table: records the dry run |
| One column per variable, plus Output |
| Write a new value each time it changes |
The trace table
| Count | Num | Total / Output |
|---|---|---|
| 0 | ||
| 1 | 4 | 4 |
| 2 | 7 | 11 |
| 3 | 2 | 13 |
| Loop ends | - | 13 |
Tips for trace tables
| Follow each line in order |
| New row when a value changes |
| Test conditions with current values |
| Record output exactly as shown |
Trace: largest mark
| Count | Mark | Max |
|---|---|---|
| 55 | ||
| 2 | 80 | 80 |
| 3 | 70 | 80 |
Types of error
| Error | What happens | Example |
|---|---|---|
| Syntax | will not run | missing ENDIF |
| Logic | wrong answer | + instead of * |
| Runtime | stops while running | divide by zero |
Errors and corrections
| Line | Error | Correction |
|---|---|---|
| 4 | Total ← Mark | Total ← Total+Mark |
| 6 | Total / 4 | Total / 5 |
Quick answers
Max starts at 0 and inputs are -5, -2, -9. What goes wrong?
Output is 0, but the largest is -2. Start Max with the first input.
How do you answer an error question?
Give the line number, describe the error, write the corrected line.
KwickClips from this lesson
Short clips, one idea each. Good for revision the night before.
The full lesson, in text
Hello students, welcome to Kwickprep. In the exam, you get an algorithm on paper and no computer. How do you find what it outputs, or where it goes wrong? Today we will learn trace tables, and how to spot and correct errors in an algorithm.
Let us start with two new terms. A dry run means working through an algorithm by hand, one step at a time, without a computer. A trace table is the table you fill in during a dry run. It has one column for each variable, and a column for the output. Each new row shows a value when it changes.
Here is an algorithm that adds three numbers. Total is set to zero. The For loop runs with Count from one to three. Each time, a number is input and added to Total. After the loop, Total is output. We will trace it with the inputs four, seven and two.
Now we fill in the trace table row by row. At the start, Total is zero. When Count is one, Num is four, so Total becomes four. When Count is two, Num is seven, so Total becomes eleven. When Count is three, Num is two, so Total becomes thirteen. The loop ends, and thirteen is output.
Examiners give marks for each correct column, so work carefully. Follow the lines in order and never skip a line. Write a value only when it changes, in a new row. Check every condition using the current values. Put the output in the Output column, exactly as it is shown.
Now an algorithm with a decision inside a loop. Max stores the largest mark seen so far. It starts with the first mark input. The loop reads two more marks. If a mark is greater than Max, Max is replaced. We will trace it with the marks fifty five, eighty and seventy.
Here is the trace for the largest mark. First, Max is fifty five. When Count is two, Mark is eighty, which is greater than fifty five, so Max becomes eighty. When Count is three, Mark is seventy, which is not greater than eighty, so Max stays eighty. At the end, Max holds eighty.
Errors in programs come in three main types. A syntax error breaks the grammar rules of the language, such as a missing Endif, so the program will not run. A logic error lets the program run, but it gives the wrong result, such as adding instead of multiplying. A runtime error happens while the program runs, such as dividing by zero.
Now an exam style task. This algorithm should find the average of five marks. It runs, but the answer is wrong, so these are logic errors. Look at line four and line six. Pause the video and find the two errors before I explain.
Here are the errors and their corrections. On line four, Total becomes only the latest mark, so the earlier marks are lost. The correction is Total gets Total plus Mark. On line six, the total is divided by four, but there are five marks. The correction is to divide by five.
Here is the corrected algorithm. Let us check it with a quick dry run. If every mark is sixty, Total becomes three hundred after five inputs. Three hundred divided by five is sixty. The output is sixty, which is correct.
Pause and predict with an edge case. In the largest mark algorithm, suppose someone changes the start to Max gets zero, and loops over all the marks. The marks are temperatures, minus five, minus two and minus nine. What is output? Zero, which is wrong, because no temperature is greater than zero. The fix is to start Max with the first input instead.
Error questions usually give line numbers, so answer in a clear pattern. First, give the line number of the error. Second, quote or describe the error. Third, write the corrected line in full. Finally, run a quick dry run to check your correction works.
Let us revise today's lesson. A dry run follows an algorithm by hand. A trace table records every variable and the output as values change. Syntax errors stop the program from running. Logic errors give wrong results, and runtime errors happen while running. For error questions, give the line, the error and the full correction.
Courses that teach this
| Course | Unit |
|---|---|
| Cambridge IGCSE Grade 9 Computer Science (0478) | 7. Algorithm Design and Problem-Solving |
Voice-over in this lesson is AI-generated. The script is written and checked by Kajal Ma'am. Boards can revise a syllabus mid-year, so confirm anything you plan around against the official board circular. Keep your passwords, OTPs and ID numbers to yourself — we never ask for them. To reach Kajal Ma'am, use the WhatsApp button; sharing your number there is how we call you back.
Free to watch, no sign-up. Live classes with Kajal Ma'am are the paid course; these lessons stay free either way.


