Algorithm design, tracing and debugging
Design or amend a flowchart or Python algorithm, trace its variables and distinguish syntax, logic and run-time errors.
Mapped to the Cambridge IGCSE Computer Science 0265 syllabus for exams in 2029. These original explanations and self-checks are independent study support, not Cambridge papers, official marks or grades. Practical programming is taught with worked code and trace tasks; an executable Python workspace and timed digital-exam simulation are not yet available.
Before you begin
- Use the 2029 syllabus for this course. Cambridge specifies Python 3.10 or higher for programming and digital exams for both components. The syllabus currently identifies this route for 2029 only; confirm later-year availability with Cambridge and your school.
Work on paper. Try each question before revealing help, and explain why your method works.
Quick readiness check
Before algorithm design, tracing and debugging, which statement is the safest starting point?
What you will learn
- Design, complete and amend an algorithm
- Trace inputs, outputs and variables
- Identify and correct errors using clear steps
An algorithm turns a context into steps
A problem can be represented with a flowchart or Python. Identify inputs, outputs, processing and storage, then arrange steps using sequence, selection and iteration. A flowchart may place multiple statements in one process box, and a decision box can include a process and a decision where appropriate.
A trace table records variable values as an algorithm runs for specified inputs. Create a column for each relevant variable and output, then update values in execution order. A trace helps reveal whether a condition, loop boundary or update behaves as intended.
Errors need different fixes
A syntax error violates language rules, such as a missing colon in Python. A run-time error occurs while a program is executing, such as converting unsuitable text to a number. A logic error lets a program run but produces an incorrect result.
Debug by selecting test data, following the code, locating the first point where actual behaviour differs from the intended result, then correcting the cause and retesting. Amendments should preserve cases that already worked and handle the new requirement.
Pause and explain
Which habit best checks your understanding of algorithm design, tracing and debugging?
Worked example
Trace total after x=2 and x=5 for: total=0; for x in [2,5]: total=total+x; print(total).
Show the worked solution
- Initial total is 0.
- After x=2, total is 2.
- After x=5, total is 7; print outputs 7.
Answer 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 n after starting at 1 and repeating n = n * 2 three times.
Give me a hint
Write the value after each loop iteration.
Compare my reasoning
- Start n=1.
- After iteration 1: 2; after iteration 2: 4.
- After iteration 3: 8.
n = 8
Look for these in your work
- Initial value
- Each iteration
- Final value
A Python if statement has no colon at the end of its condition. Identify the error type and give the correction.
Give me a hint
Check whether the code can be parsed before runtime.
Compare my reasoning
- Python requires a colon after the if condition.
- Without it the statement violates syntax rules.
- Add the colon and rerun the program.
Syntax error; add ':' after the if condition.
Look for these in your work
- Error type
- Rule stated
- Correction
An algorithm should print the largest of three entered values but prints the last value whenever it is not the first. Describe a trace-based debugging approach.
Give me a hint
Use test inputs that make each position contain the largest value.
Compare my reasoning
- Trace with the first value largest, then with the second value largest, then with the third largest.
- Track the current maximum and each comparison to find the first incorrect update.
- Correct the comparison or assignment and rerun all three tests plus an equal-value boundary case.
Use discriminating traces to find the faulty branch, fix it and rerun normal and boundary cases.
Look for these in your work
- Tests distinguish branches
- Variable trace used
- Regression tests included
Common mistakes
- Changing a variable in the trace before its assignment executes.
- Calling every incorrect result a syntax error.
- Fixing one test case without retesting others.
What can you explain now?
A program runs but calculates 15% as 15 times the price instead of 0.15 times the price. What kind of error is this?
Compare with the explanation
Logic error
The statements are syntactically valid and execute, but the algorithm is wrong.
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
How do flowcharts, trace tables and test cases help you design and debug an algorithm?
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.