9 Algorithm design and problem-solving
Decompose a problem, abstract irrelevant detail and express a verifiable algorithm with precise logic.
Section 9 · Algorithm design and problem-solving
Mapped to Cambridge International AS & A Level Computer Science 9618, 2027–2029 Version 2. These original lessons and self-checks are independent study support; they are not Cambridge papers, official marks or grades. The course does not yet provide a timed four-paper simulation or a locked-down Paper 4 programming environment.
Before you begin
- Use the 2027–2029 syllabus for your exam year. AS candidates study Sections 1–12; A Level candidates study Sections 1–20. Paper 4 uses a programming language chosen from Python, Java or Visual Basic in console mode.
Work on paper. Try each question before revealing help, and explain why your method works.
Quick readiness check
Which task is an example of abstraction?
What you will learn
- Explain the key representations, structures or processes in this syllabus section
- Apply the method to a new computer-science example
- Justify a design choice and check its limits
Computational thinking turns a problem into manageable steps
Decomposition separates a complex task into smaller parts. Abstraction keeps details relevant to the problem and hides irrelevant complexity. Pattern recognition finds similarities that permit reuse.
A specification states inputs, outputs, constraints and success conditions. Stepwise refinement moves from a high-level solution toward enough detail to implement. A solution should be checked against the original requirements.
Algorithms need clear control and data flow
An algorithm can be expressed as pseudocode or a flowchart. Sequence executes steps in order; selection chooses a branch; iteration repeats steps. A trace table records variable values and conditions as the algorithm runs.
Boolean expressions combine comparisons with NOT, AND and OR. Parentheses and evaluation order matter. A test should cover normal, boundary and invalid inputs, based on the specification.
Pause and explain
Why use a trace table?
Worked example
A program must report the highest of three non-equal scores. Name useful inputs, output and one decomposition step.
Show the worked solution
- Inputs are the three scores.
- The output is the maximum score.
- A subtask can compare the first two, keep the larger, then compare that value with the third.
Answer Read three scores; update a current maximum twice; output the maximum.
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.
An online shop must reject an order if stock is insufficient, otherwise reduce stock and confirm the order. State the decision and the two branches.
Give me a hint
Identify the comparison that separates the outcomes.
Compare my reasoning
- Compare requested quantity with available stock.
- If requested quantity exceeds stock, report unavailable and make no stock reduction.
- Otherwise subtract quantity and confirm the order.
IF quantity > stock, reject; ELSE reduce stock by quantity and confirm.
Look for these in your work
- Condition stated
- Reject branch protects stock
- Success branch updates stock
Trace total ← 2, then repeat three times: total ← total × 2. Give the value after each iteration.
Give me a hint
Update using the current value at the start of each iteration.
Compare my reasoning
- Initial value is 2.
- After iteration 1 it is 4; after 2 it is 8.
- After iteration 3 it is 16.
4, 8, 16.
Look for these in your work
- Initial value respected
- Three iterations
- Updated value used
A temperature input must be from −20 through 50 inclusive. Give one normal, one boundary and one invalid test, with expected handling.
Give me a hint
Choose a middle value, a limit value and a value beyond the permitted range.
Compare my reasoning
- Normal: 18 should be accepted.
- Boundary: 50 should be accepted because the limit is inclusive.
- Invalid: 51 should be rejected or reprompted.
18 accepted; 50 accepted; 51 rejected or reprompted.
Look for these in your work
- Three test classes
- Inclusive boundary applied
- Invalid outcome described
Common mistakes
- Starting to code before clarifying inputs and expected outputs.
- Using an abstraction that removes a condition required by the problem.
- Tracing an assignment as though it were an algebraic equation.
What can you explain now?
What does decomposition do?
Compare with the explanation
Breaks a complex problem into smaller parts
Smaller subtasks can be designed and checked separately.
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 decomposition, abstraction, stepwise refinement and trace tables help turn a problem into a checkable 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.