2029–2031 edition · for exams from June 2029. Students sitting exams up to November 2028 follow the current course.
9. Algorithm design
Abstraction and decomposition, designing algorithms as flowcharts or Python, trace tables, finding and fixing errors, and linear/binary search with bubble, insertion and merge sort.
What you need to know317 learning objectives, as printed in the syllabus
- 9.1AbstractionNew2026–2028 syllabus: Topic 7
Abstraction gets its own sub-section.
Learning objectives (3)
- 9.1.1Describe abstraction as the process of creating a simplified model that represents the essential features of a problem
- 9.1.2Explain the purpose of abstraction for a given context
- 9.1.3Demonstrate how to use abstraction
- 9.2DecompositionSame as now2026–2028 syllabus: Topic 7
Decomposition into inputs, processes, outputs and storage.
Learning objectives (4)
- 9.2.1Describe decomposition as the process of breaking down problems into smaller, more manageable sub problems
- 9.2.2Describe how a problem can be decomposed into its component parts, limited to: (a) inputs; (b) processes; (c) outputs; (d) storage
- 9.2.3Explain the purpose of decomposition for a given context
- 9.2.4Demonstrate how to use decomposition
- 9.3Algorithm design and evaluationChanged2026–2028 syllabus: Topic 7
Flowcharts or Python only (no pseudocode, no structure diagrams); adds binary search, insertion sort and merge sort and comparing them (no Big-O).
Learning objectives (10)
- 9.3.1Design, complete and amend algorithms for a given context using: (a) a flowchart; (b) Python code
- 9.3.2Explain the purpose of a given algorithm and the purpose of the component parts, limited to: (a) inputs; (b) outputs; (c) processes; (d) storage
- 9.3.3Complete a trace table for a given algorithm including inputs, outputs and variables for a given set of data
- 9.3.4Identify and correct errors in a given algorithm
- 9.3.5Amend an algorithm
- 9.3.6Show how searching algorithms are performed on a given set of data, limited to: (a) linear search; (b) binary search
- 9.3.7Show how sorting algorithms are performed on a given set of data, limited to: (a) bubble sort; (b) insertion sort; (c) merge sort
- 9.3.8Construct the algorithms using a flowchart or Python for a: (a) linear search; (b) bubble sort
- 9.3.9Describe the steps involved in a: (a) linear search; (b) binary search; (c) bubble sort; (d) merge sort
- 9.3.10Compare and contrast the features and efficiency of algorithms, limited to: (a) linear search; (b) binary search; (c) bubble sort; (d) merge sort
Candidates will not be expected to use Big-O notation when comparing algorithms
Flowcharts may contain multiple statements in one box
A decision box may combine a process and a decision
Objectives quoted from the 2029–2031 syllabus, Version 1, September 2026; © Cambridge University Press & Assessment.
Notes3every learning objective explained, with worked examples
9.1Abstraction
Abstraction is the first tool of computational thinking: keep what matters to the problem, leave out what does not, and you get a simpler model you can actually program.
What abstraction is
Abstraction is the process of creating a simplified model that represents the essential features of a problem, by removing unnecessary detail.
Everyday example: a metro map shows stations, lines and the order of stops, but not real distances, streets or buildings — the details a traveller does not need.
Purpose of abstraction
- Makes the problem simpler to understand and solve.
- Lets the programmer focus on what matters.
- Less data to store and process, so the program is smaller and faster to write and run.
- Reduces the chance of errors and makes the solution easier to design and test.
- The model can often be reused for similar problems.
Using abstraction: a worked scenario
Scenario: a school library wants a program to lend books to students.
| Kept (essential) | Removed (not needed) |
|---|---|
| Book ID, title, author | Cover colour, number of pages, weight |
| Student ID, name, class | Student's height, favourite sport, home address |
| Date borrowed, due date, returned or not | The shelf's wood type, the librarian's name |
The model becomes: a book record, a student record and a loan linking them with dates. Everything else is left out. For a different purpose (e.g. a bookshop selling books) the essential features would change — price and stock become essential — so always decide relative to the given context.
Exam tips
- Define abstraction with the three key ideas: simplified model, essential features, removing unnecessary detail.
- In a scenario, list specific things to KEEP and to REMOVE, and justify each by the program's purpose.
- Explaining the purpose? Link it to the context: e.g. 'the program only needs the due date to calculate fines'.
Mistakes that lose marks
- Confusing abstraction (removing detail) with decomposition (splitting into parts).
- Giving generic answers like 'it makes it easier' without saying how or for what.
- Removing details that the given scenario actually needs.
9.2Decomposition
Decomposition breaks a big problem into smaller sub-problems that are each easy to understand, write and test. At O Level you describe every system by its inputs, processes, outputs and storage.
What decomposition is
Decomposition is the process of breaking down a problem into smaller, more manageable sub-problems. Each sub-problem can be broken down again until each part is simple enough to solve directly — often as its own procedure or function.
The component parts: inputs, processes, outputs, storage
| Part | Question to ask | Example (cinema ticket machine) |
|---|---|---|
| Inputs | What data goes in? | Film choice, number of tickets, ticket type, payment |
| Processes | What is done to the data? | Check seats free, calculate total cost, apply discount, take payment |
| Outputs | What comes out? | Total to pay, printed ticket, error messages |
| Storage | What must be kept? | Films and show times, seats booked, ticket prices |
Purpose of decomposition
- Each sub-problem is easier to understand and solve.
- Different programmers can work on different parts at the same time, so the project is finished sooner.
- Each part can be tested on its own, so errors are found and fixed more easily.
- Parts can be reused in other programs (e.g. a "validate date" function).
- The program is easier to maintain: a change affects one part only.
Using decomposition: a worked scenario
Scenario: a program records a class's test marks and reports the average and the highest mark.
- Input marks — ask for each student's name and mark; validate the mark (0–100).
- Store marks — keep names and marks in two lists.
- Process — total the marks, count them, calculate the average, find the highest.
- Output — display the average to 1 decimal place and the top student's name.
Each numbered step can become a function:
def get_mark():
mark = int(input("Mark: "))
while mark < 0 or mark > 100:
mark = int(input("0 to 100 only: "))
return mark
def average(marks):
return round(sum(marks) / len(marks), 1)Exam tips
- Define decomposition as breaking a problem into smaller, more manageable sub-problems.
- When decomposing a scenario, use the four headings inputs, processes, outputs, storage and give items from the scenario under each.
- Purpose answers score best when tied to the context (e.g. 'the payment part can be tested separately').
Mistakes that lose marks
- Listing outputs as processes (e.g. 'display total' is an output; 'calculate total' is a process).
- Forgetting storage — what must be remembered between runs.
- Describing abstraction instead.
9.3Algorithm design and evaluation
The biggest § of Paper 2: designing algorithms as flowcharts or Python, explaining them, tracing them, fixing and amending them, and knowing the standard searching and sorting algorithms well enough to perform, write, describe and compare them.
Flowchart symbols
| Symbol | Shape | Used for |
|---|---|---|
| Terminator | Rounded rectangle (oval) | START and STOP |
| Input/Output | Parallelogram | INPUT mark, OUTPUT total |
| Process | Rectangle | Assignments and calculations, e.g. total ← total + mark |
| Decision | Diamond | A Yes/No question, e.g. mark > 100? — two labelled exits |
| Subroutine | Rectangle with double side lines | Calling a procedure/function |
| Flow line | Arrow | Order of steps; loops are drawn as arrows going back |
A box may contain several statements, and a decision box may combine a process and a decision (e.g. "count ← count + 1, count = 10?"). Every decision exit must be labelled Yes/No.
Designing, completing and amending algorithms
To design an algorithm for a context: decompose it (inputs, processes, outputs, storage), choose the constructs (selection? which loop?), then write it as a flowchart or Python.
Amending means changing a working algorithm to do something extra — e.g. change a fixed loop of 10 to ask how many, add validation, or also output the lowest value.
# Original: total of 5 numbers
total = 0
for count in range(5):
total = total + int(input())
print(total)
# Amended: user chooses how many, and the average is also output
how_many = int(input("How many? "))
total = 0
for count in range(how_many):
total = total + int(input())
print(total, total / how_many)Explaining the purpose of an algorithm
Read the code, trace it with sample data, then state what it does in terms of the problem, broken into its parts:
- Inputs — what it asks for.
- Processes — what it calculates or decides.
- Outputs — what it displays.
- Storage — what it keeps (variables, lists, files).
e.g. "It inputs numbers until −1 is entered, totals and counts them, and outputs the total and how many were entered." Avoid line-by-line translation ("it sets total to 0…").
Trace tables
A trace table records the value of every variable, and every input and output, each time it changes, as you dry-run the algorithm line by line.
count = 0
total = 0
number = int(input())
while number != -1:
total = total + number
count = count + 1
number = int(input())
print(total, count)Input data: 4, 7, 2, −1
| number | total | count | OUTPUT |
|---|---|---|---|
| 0 | 0 | ||
| 4 | 4 | 1 | |
| 7 | 11 | 2 | |
| 2 | 13 | 3 | |
| −1 | 13 3 |
Rules: a new row when a value changes; leave a cell blank if nothing changes; outputs exactly as printed.
Identifying and correcting errors
Typical faults planted in exam algorithms: wrong operator (< instead of <=), wrong starting value (highest = 0 when values may be negative), counter not incremented, total reset inside the loop, wrong loop range, wrong variable output.
# Should output the sum of 1 to 5 (15) but prints 10
total = 0
for count in range(1, 5): # error: stops at 4
total = total + count
print(total)Correction: for count in range(1, 6):. In the exam, give the line with the error and the corrected line in full.
Linear search
Checks each item in turn from the start until the target is found or the end of the list is reached. Works on unsorted data.
numbers = [14, 3, 27, 8, 19]
target = 8
found = False
position = -1
index = 0
while index < len(numbers) and not found:
if numbers[index] == target:
found = True
position = index
index = index + 1
if found:
print(target, "found at index", position)
else:
print(target, "not found")Output: 8 found at index 3 (after 4 comparisons).
Steps: start at the first item → compare with the target → if equal, stop (found) → otherwise move to the next item → if the end is reached, report not found.
Binary search
Works only on sorted data. Repeatedly checks the middle item and discards the half that cannot contain the target.
Steps: set low = first index, high = last index → mid = (low + high) // 2 → if the middle item is the target, stop → if the target is larger, low = mid + 1; if smaller, high = mid − 1 → repeat until found or low > high (not found).
numbers = [3, 8, 15, 21, 30, 42, 57]
target = 42
low = 0
high = len(numbers) - 1
found = False
while low <= high and not found:
mid = (low + high) // 2
print("low", low, "high", high, "mid", mid, "value", numbers[mid])
if numbers[mid] == target:
found = True
elif numbers[mid] < target:
low = mid + 1
else:
high = mid - 1
print("Found" if found else "Not found")Output: low 0 high 6 mid 3 value 21, low 4 high 6 mid 5 value 42, Found — two comparisons, where a linear search would need six.
Bubble sort
Goes through the list comparing adjacent pairs and swapping them if they are in the wrong order. After each pass the largest remaining value has "bubbled" to its place at the end. Stops when a pass makes no swaps.
numbers = [5, 1, 4, 2, 8]
n = len(numbers)
swapped = True
passes = 0
while swapped:
swapped = False
for i in range(n - 1 - passes):
if numbers[i] > numbers[i + 1]:
temp = numbers[i]
numbers[i] = numbers[i + 1]
numbers[i + 1] = temp
swapped = True
passes = passes + 1
print("After pass", passes, numbers)| List | |
|---|---|
| Start | 5, 1, 4, 2, 8 |
| After pass 1 | 1, 4, 2, 5, 8 |
| After pass 2 | 1, 2, 4, 5, 8 |
| After pass 3 | 1, 2, 4, 5, 8 (no swaps → stop) |
A temporary variable is needed for the swap so a value is not overwritten.
Insertion sort
Builds a sorted part at the front. Takes the next item and inserts it into the correct place in the sorted part, shifting larger items one place right.
items = [23, 4, 42, 8, 15, 16]
for i in range(1, len(items)):
current = items[i]
j = i - 1
while j >= 0 and items[j] > current:
items[j + 1] = items[j]
j = j - 1
items[j + 1] = current
print("After inserting", current, items)| Inserted | List |
|---|---|
| Start | 23, 4, 42, 8, 15, 16 |
| 4 | 4, 23, 42, 8, 15, 16 |
| 42 | 4, 23, 42, 8, 15, 16 |
| 8 | 4, 8, 23, 42, 15, 16 |
| 15 | 4, 8, 15, 23, 42, 16 |
| 16 | 4, 8, 15, 16, 23, 42 |
Merge sort
A divide and conquer sort:
- Split the list in half, and keep splitting until every sub-list has one item (a list of one is already sorted).
- Merge pairs of sub-lists: compare the front items of both, move the smaller into the new list, repeat until both are empty.
- Keep merging until there is one sorted list.
Example: 38, 27, 43, 3, 9, 82, 10, 5
| Stage | Lists |
|---|---|
| Split | [38, 27, 43, 3] [9, 82, 10, 5] |
| Split | [38, 27] [43, 3] [9, 82] [10, 5] |
| Split | [38] [27] [43] [3] [9] [82] [10] [5] |
| Merge | [27, 38] [3, 43] [9, 82] [5, 10] |
| Merge | [3, 27, 38, 43] [5, 9, 10, 82] |
| Merge | [3, 5, 9, 10, 27, 38, 43, 82] |
You must be able to show and describe merge sort; you are not asked to write it in Python.
Comparing searching and sorting algorithms
| Linear search | Binary search | |
|---|---|---|
| Data | Sorted or unsorted | Must be sorted |
| Method | Each item in turn | Halves the search each time |
| Efficiency | Slow on large lists (may check every item) | Much faster on large lists — far fewer comparisons |
| Simplicity | Very simple | More complex |
| Best for | Small or unsorted lists | Large sorted lists |
| Bubble sort | Merge sort | |
|---|---|---|
| Method | Swap adjacent pairs, repeated passes | Split into single items, merge back in order |
| Efficiency | Slow on large lists (many comparisons and passes) | Much faster on large lists |
| Memory | Sorts in place — little extra memory | Needs extra memory for the sub-lists |
| Simplicity | Simple to write and understand | More complex |
| Already-sorted data | Stops after one pass with no swaps | Still does all the splitting and merging |
Insertion sort, like bubble sort, is simple and sorts in place; it is quick on small or nearly sorted lists.
Exam tips
- Show every pass of a sort (or every comparison of a search) — marks are given per correct stage, not just for the final list.
- When writing a linear search or bubble sort, include initialisation, the loop, the comparison, the found flag / swap with a temporary variable, and the output.
- Trace tables: one column per variable plus OUTPUT; fill a new row only when something changes; outputs exactly as printed.
- For 'identify and correct', quote the faulty line number and write the whole corrected line.
- Comparisons are in words (faster/slower on large data, sorted data needed, memory, simplicity) — Big-O is not expected.
- Remember binary search needs the list to be sorted first — say so whenever you suggest it.
Mistakes that lose marks
- Using binary search on unsorted data.
- Swapping two values without a temporary variable, overwriting one of them.
- Stopping a bubble sort after one pass, or not knowing it stops when a pass makes no swaps.
- Unlabelled Yes/No exits on flowchart decisions, or using a rectangle for input/output.
- Describing merge sort as 'splitting into halves and sorting each half' without the single-item split and the merge step.
- Explaining an algorithm line by line instead of saying what it achieves.
Infographics3download any diagram as PNG or SVG
Abstraction and decomposition
Flowchart symbols
Searching and sorting compared
Python for this topic7Python 3.10+, the only language on Paper 2 — runs in your browser
- Linear searchWalk the list until you find the target — the exam wants the loop, not list.index().
- Binary search — iterative and recursiveHalve the search space each time; the list must be sorted. Both versions, with the number of comparisons.
- Bubble sort with a swapped flagThe classic Paper 2 / Paper 4 sort. Open the Trace tab to watch the swaps.
- Insertion sortTake each item and slide it left into the sorted part. Compare with sorted() and .sort() at the end.
- Merge sort — watch the splits and merges2029 styleMerge sort splits the list in half until each part holds one item, then merges the parts back in order. You need to show and describe it in the exam, not write it — run it to see every step.
- Linear vs binary search — counting comparisons2029 styleThe same item found both ways in a sorted list of 100 values: linear search checks one by one, binary search halves the list each time (which is why the list must be in order).
- Spot the logic error — an average that is too low2029 styleThe first loop runs without crashing but gives the wrong answer (a logic error): range(1, …) skips index 0. Run it, find the error with the trace table, then compare with the corrected loop.
Key terms10use these exact words in the exam
Test yourself
Check you know the 2029–2031 content
Written for the new syllabus only: every card and question traces to a learning objective above. Rounds are random, and marks earn XP on your dashboard.
5 decks · 39 cards · 17 quiz questions.
From the current course
Most of this topic is taught in the 2026–2028 course today. Its notes and past-paper questions still help — skip anything the 2029–2031 syllabus removed (see the notes above), and remember those past papers answer in pseudocode: write Python instead.
- 7. Algorithm Design and Problem-Solving2026–2028 topic · 304 past-paper questions

