Skip to content

2029–2031 edition · for exams from June 2029. Students sitting exams up to November 2028 follow the current course.

2210 · 04782029–2031 editionPaper 2 · Algorithms and Programming§9.1, §9.2, §9.3

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

  1. 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
  2. 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
  3. 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, authorCover colour, number of pages, weight
Student ID, name, classStudent's height, favourite sport, home address
Date borrowed, due date, returned or notThe 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

PartQuestion to askExample (cinema ticket machine)
InputsWhat data goes in?Film choice, number of tickets, ticket type, payment
ProcessesWhat is done to the data?Check seats free, calculate total cost, apply discount, take payment
OutputsWhat comes out?Total to pay, printed ticket, error messages
StorageWhat 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.

  1. Input marks — ask for each student's name and mark; validate the mark (0–100).
  2. Store marks — keep names and marks in two lists.
  3. Process — total the marks, count them, calculate the average, find the highest.
  4. 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

SymbolShapeUsed for
TerminatorRounded rectangle (oval)START and STOP
Input/OutputParallelogramINPUT mark, OUTPUT total
ProcessRectangleAssignments and calculations, e.g. total ← total + mark
DecisionDiamondA Yes/No question, e.g. mark > 100? — two labelled exits
SubroutineRectangle with double side linesCalling a procedure/function
Flow lineArrowOrder 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

numbertotalcountOUTPUT
00
441
7112
2133
−113 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
Start5, 1, 4, 2, 8
After pass 11, 4, 2, 5, 8
After pass 21, 2, 4, 5, 8
After pass 31, 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)
InsertedList
Start23, 4, 42, 8, 15, 16
44, 23, 42, 8, 15, 16
424, 23, 42, 8, 15, 16
84, 8, 23, 42, 15, 16
154, 8, 15, 23, 42, 16
164, 8, 15, 16, 23, 42

Merge sort

A divide and conquer sort:

  1. Split the list in half, and keep splitting until every sub-list has one item (a list of one is already sorted).
  2. Merge pairs of sub-lists: compare the front items of both, move the smaller into the new list, repeat until both are empty.
  3. Keep merging until there is one sorted list.

Example: 38, 27, 43, 3, 9, 82, 10, 5

StageLists
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 searchBinary search
DataSorted or unsortedMust be sorted
MethodEach item in turnHalves the search each time
EfficiencySlow on large lists (may check every item)Much faster on large lists — far fewer comparisons
SimplicityVery simpleMore complex
Best forSmall or unsorted listsLarge sorted lists
Bubble sortMerge sort
MethodSwap adjacent pairs, repeated passesSplit into single items, merge back in order
EfficiencySlow on large lists (many comparisons and passes)Much faster on large lists
MemorySorts in place — little extra memoryNeeds extra memory for the sub-lists
SimplicitySimple to write and understandMore complex
Already-sorted dataStops after one pass with no swapsStill 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 decompositionAbstraction removes detail that does not matter to the problem; decomposition breaks the problem intosmaller parts you can solve one at a time.AbstractionA metro map keeps stations, lines and the order of stops;it drops real distances, streets and buildings.Quiz app: keep each question, its answer and the score;ignore the colour of the screen or the student's age.Decomposition: a quiz programInputsanswers typedProcessesmark, scoreOutputsresultsStoragesave to a fileEvery system: input → process → output, plus storageInputdata inProcesscalculate, decideOutputresults shownStoragefiles, databaseEach sub-problembecomes a functionor a block of codeyou can test alone.In an exam: list the inputs, processes, outputs and storage the scenario needs before writing any code.cswithzak.com

Abstraction and decomposition

O Level
Flowchart symbolsAlgorithms in this edition are designed as flowcharts or written in Python. Draw the right shape foreach step and label every decision's exits.Start / Stopterminatortotal = 0processInput markinput / outputx > 0?decision (Yes / No)show()subroutineflow lineStarttotal = 0Input markmark = 0?Nototal = total + markYesOutput totalStopA loop in a flowchart is a flow line going back up to an earlier step; a decision has exactly two labelled exits.cswithzak.com

Flowchart symbols

O Level
Searching and sorting algorithms comparedKnow how each one works on a small list, what it needs, and why one is quicker than another — no Big Ois needed at this level.AlgorithmHow it worksNeeds sorted data?Speed on a big listLinear searchcheck each item in turn from the startnoslow: may check every itemBinary searchcheck the middle, discard the half it can't be inyesfast: halves the list each timeBubble sortswap neighbours in the wrong order, pass after pass—slow; simple to codeInsertion sorttake the next item, insert it into the sorted part—good for small / nearly sortedMerge sortsplit into single items, merge pairs in order—fast on big lists; more memoryMerge sort on 6 3 8 1start6381split6 38 1split6381merge3 61 8merge1 3 6 8Binary search for 233812172331401 middle = 17: 23 > 17, keep the right half2 middle of 23 31 40 = 31: 23 < 31, keep the left3 23 found after 3 checks (linear search: 5)cswithzak.com

Searching and sorting compared

O Level

Python for this topic7Python 3.10+, the only language on Paper 2 — runs in your browser

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.

Enroll nowOnline classes