Complete a trace table for an algorithm
Dry-run instructions in order and record variable values, prompts and outputs at each step.
Section 7 · Algorithm design and problem-solving
This sequence follows Cambridge IGCSE Computer Science 0478, 2026–2028 syllabus Version 6. It covers subject content Topic 7 only. The separately published 2029–2031 syllabus is not mapped here. Practice is original, self-checked and does not award an official Cambridge grade. Full timed papers and human subject-teacher review remain outstanding.
Before you begin
- No programming language is required. Be comfortable with place value and multiplication; each lesson introduces the computer-science notation it uses.
Work on paper. Try each question before revealing help, and explain why your method works.
Quick readiness check
If Count starts at 0 and Count ← Count + 1 runs, what is Count?
What you will learn
- Record variable values after assignments
- Track conditions and loop iterations
- Document outputs and prompts in execution order
A trace table records changing state
A trace table documents a dry-run: start with the supplied inputs, follow each statement in order and record variable values whenever they change. Use one column per variable and label the point at which each row is recorded.
Apply and check the rule
Also record user prompts and outputs at the step where they occur. For a loop, make a new row for each iteration and evaluate the condition using the current values. A trace table is a simulation of the algorithm, not a rewritten explanation of what it should do.
Pause and explain
A loop body runs three times and displays a prompt each time. How many prompt outputs should be recorded?
Worked example
Trace Total ← 0; for each of 2, 5: Total ← Total + value; then output Total.
Show the worked solution
- Start Total=0.
- After value 2, Total=2.
- After value 5, Total=7; output 7.
Answer Total trace: 0 → 2 → 7; output 7.
Try a topic test
Choose Easy, Normal or Difficult. Save your answers and open worked review after finishing.
Test this topic →From guided practice to a new situation
Write your answer and reasoning first. Use a hint only if you are stuck. The model solution is for self-checking; your written work is not automatically marked.
Trace X ← 4; repeat twice: X ← X + 3; output X. Give each value and final output.
Give me a hint
Record the initial value and after each iteration.
Compare my reasoning
- Initial X=4.
- Iteration 1: X=7.
- Iteration 2: X=10; output 10.
X trace: 4 → 7 → 10; output 10.
Look for these in your work
- Initial
- Two updates
- Output
Trace a loop that starts Count=0 and repeats while Count<3, outputting Count before incrementing it. What values appear?
Give me a hint
Check the condition before each iteration.
Compare my reasoning
- At Count=0, output 0, then increment to 1.
- At Count=1, output 1; then 2.
- At Count=2, output 2; then Count becomes 3 and the loop stops.
Outputs: 0, 1, 2. Final Count=3.
Look for these in your work
- Condition checks
- Output timing
- Stop condition
A trace table shows Total=12 after processing 3 and 4 from an initial Total=0. Identify a likely tracing or coding error.
Give me a hint
Add the two inputs independently.
Compare my reasoning
- Correct total is 0+3+4=7.
- 12 suggests a value was duplicated or the wrong variable was used.
- Recheck the assignment and one row at a time.
The total should be 7. Recheck whether an input was added twice or a stale variable was used.
Look for these in your work
- Independent calculation
- Discrepancy
- Debug step
Common mistakes
- Using an old variable value on the right side of an assignment
- Omitting output until after a later statement changes the variable
What can you explain now?
What should a trace table show during an algorithm?
Compare with the explanation
The values and outputs as statements execute
It records the sequence of state changes in a dry-run.
After trying it yourself, choose your next review. This is your self-assessment.
Your review choice appears on Today. Sign in to sync it across devices.
Make it stick
What belongs in a trace table when a loop changes variables and displays results?
If you needed the solution, close it and solve the problem again from a blank page. A correct answer is stronger when you can explain the reason for each step.