Learn in your language
Skip to content
IGCSE · Cambridge (CIE) · 0265

Algorithm design, tracing and debugging

Design or amend a flowchart or Python algorithm, trace its variables and distinguish syntax, logic and run-time errors.

Cambridge IGCSE Computer Science 0265 · 2029 syllabus · Version 1 · 9

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?

Put the idea to work

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
  1. Initial total is 0.
  2. After x=2, total is 2.
  3. 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.

1 · Guided

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
  1. Start n=1.
  2. After iteration 1: 2; after iteration 2: 4.
  3. After iteration 3: 8.

n = 8

Look for these in your work

  • Initial value
  • Each iteration
  • Final value
2 · Independent

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
  1. Python requires a colon after the if condition.
  2. Without it the statement violates syntax rules.
  3. 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
3 · Transfer

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
  1. Trace with the first value largest, then with the second value largest, then with the third largest.
  2. Track the current maximum and each comparison to find the first incorrect update.
  3. 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.
Recall without your notes

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.

Keep learning Computer Science

Course scope and assessment

All 11 syllabus topics link to 33 original lessons. Each lesson includes worked teaching, a check with explanation and guided, independent and application practice. This is mapped teaching, not evidence of exam readiness, teacher approval or a Cambridge grade. Cambridge specifies two externally assessed digital exams; StudyForA does not yet provide full timed digital-paper simulations or an executable Python 3.10+ workspace for practical programming. The currently published syllabus is for 2029; later-year coverage is not claimed.

StudyForA · Learn with understanding

Original teaching content and links to official sources. Check your exam year and qualification before using a resource.