Skip to content
2210 · 0478Paper 2 · Algorithms, Programming and Logic

7. Algorithm Design and Problem-Solving

Program development life cycle, decomposition, flowcharts and pseudocode, standard algorithms (searching, sorting, totalling, counting, max/min), validation and testing with trace tables.

In the 2029–31 syllabus this becomes Topic 9 (Algorithm design) and 10.5 (Testing). The PDLC and pseudocode go; algorithms are written as flowcharts or Python, with binary search and merge sort added. What changes in 2029 → · Study the new topics: 9. Algorithm design, 10. Further programming and testing

Statometer92BankerNext Paper 294%
Marks a paper22.8 · 30%Rank#4 of 10 · #2 on P2Trend · last 12→Oct/Nov 24 · 23: 21 · Feb/Mar 25 · 22: 27 · May/Jun 25 · 21: 23 · May/Jun 25 · 22: 15 · May/Jun 25 · 23: 21 · Oct/Nov 25 · 21: 17 · Oct/Nov 25 · 22: 19 · Oct/Nov 25 · 23: 23 · Feb/Mar 26 · 22: 29 · May/Jun 26 · 21: 22 · May/Jun 26 · 22: 24 · May/Jun 26 · 23: 19 marks
9 in 10 chance in the next paper

Everything for this topic — study hub

O Level / IGCSE · 2210 · 0478 · Paper 2

This topic is rows 21–26 of the study route.Open it on your study route

Statometer — what 25 real papers say about this topic and each of its 6 syllabus bullets

Banker · #4 of 10 in O Level / IGCSE · recomputed with every new session

92BANKER
Banker#4 of 10 in O Level / IGCSE#2 on Paper 2→ Steady

Set in nearly every paper and worth a big slice of it — revise first, expect it.

Next Paper 2
94%
9 in 10 chance it is set
Marks a paper
22.8 / 75
30% of Paper 2 · fair share 25%
Appeared in
25 / 25
Paper 2 sittings 2023–2026
Last set
May/Jun 2026
0478/23 · Q5 · 7 marks · 11-series streak
Marks in each of the last 12 Paper 2 sittingsOct/Nov 24 → May/Jun 26
Oct/Nov 24 · 23: 21 marksFeb/Mar 25 · 22: 27 marksMay/Jun 25 · 21: 23 marksMay/Jun 25 · 22: 15 marksMay/Jun 25 · 23: 21 marksOct/Nov 25 · 21: 17 marksOct/Nov 25 · 22: 19 marksOct/Nov 25 · 23: 23 marksFeb/Mar 26 · 22: 29 marksMay/Jun 26 · 21: 22 marksMay/Jun 26 · 22: 24 marksMay/Jun 26 · 23: 19 marks

What the papers say

  • Set in 25 of 25 Paper 2 sittings on the current syllabus — treat it as certain.
  • Worth about 22.8 marks a paper (30% of Paper 2).
  • Last set May/Jun 2026 · 0478/23 · Q5 for 7 marks — in the most recent series.
  • Set in each of the last 11 series without a miss.
  • Steady at around 22.1 marks a paper year on year.
  • Lives on “Complete” and “Write” — 53% of its questions: you must produce something — code, a diagram, a table — practise doing it, not reading it.
  • 60% of its questions involve a diagram, table or figure — practise with pen and paper.
  • 54% of its questions are set out as code, pseudocode or a table to complete.
  • Most of its marks (82%) come in extended questions of 6+ marks — plan the answer before writing.
  • Its biggest question so far: 16 marks (Oct/Nov 2023 · 0478/21 · Q8).
  • Inside the topic, Test data (normal, abnormal, extreme, boundary); trace tables for dry runs; identifying and correcting errors in algorithms carries the most marks (22%) and The program development life cycle the least (3%).
  • It is examined mostly as AO2 (Apply to a context, 66%), the rest AO1 (28%) — you must apply it to the scenario or the given data — a definition alone will not score.
  • The examiner has commented on 173 of its questions — read “What the examiner said” before you practise.

Command words

Share of questions using the word (a question can use several). What each wants →

Question shapes

  • 1–2 mk25
  • 3–4 mk58
  • 5–6 mk87
  • 7–9 mk82
  • 10+ mk52

Average 7.1 marks a question · 60% with a figure or table · 54% with code · biggest 16 marks

Assessment objectives — how it is examined

Every part of every current-syllabus question filed under Cambridge's AO1 / AO2 / AO3 (from its command word and what it asks you to do), so you know whether this topic pays for definitions, for applying, or for judging and building.

  • AO1 Knowledge & understanding
  • AO2 Apply to a context
  • AO3 Evaluate & judge

Paper 2 as a whole

Paper 2SyllabusMeasured
AO1 Knowledge & understanding20%27%
AO2 Apply to a context60%51%
AO3 Evaluate & judge20%22%

Syllabus = Cambridge's grid; measured = the bank's current-syllabus papers.

Inside the topic — every syllabus bullet, measured

Each part of each question is filed under the bullet it examines; the numbers are per Paper 2 sitting, exactly like the topic's. Open a bullet for its own Statometer.

  • The program development life cycle#16 of 19 on Paper 2Occasional · 3346% next paper1.7 marks12/25 sittings→ May/Jun 2026

    Rotated in occasionally — the bullet students skip and then meet.Syllabus: analysis, design, coding and testing, and what happens at each stage

    Next Paper 2
    46%
    2 in 4
    Marks a paper
    1.7
    2% of the paper · 3% of the topic
    Asked in
    12 / 25
    Paper 2 sittings · 21 questions
    Last asked
    May/Jun 2026
    2210/22 · Q4 · 3 marks
    • Asked in 12 of 25 Paper 2 sittings — roughly one paper in 2.
    • About 1.7 marks a paper (2% of Paper 2; 3% of the topic's marks across its 6 bullets).
    • Last asked May/Jun 2026 · 2210/22 · Q4 (3 marks) — in the most recent series.
    • Usually “Describe”: full sentences with a reason, not one-word answers.
    • Biggest chunk of marks so far: 6 in Feb/Mar 2026 · 0478/22 · Q3.
    • It is examined almost entirely as AO1 (Knowledge & understanding, 98%) — definitions and descriptions in syllabus words score.
    Last 12 sittings→ Steady
    Oct/Nov 24 · 23: 6 marksFeb/Mar 25 · 22: 4 marksMay/Jun 25 · 21: 0 marksMay/Jun 25 · 22: 1 marksMay/Jun 25 · 23: 0 marksOct/Nov 25 · 21: 0 marksOct/Nov 25 · 22: 0 marksOct/Nov 25 · 23: 0 marksFeb/Mar 26 · 22: 6 marksMay/Jun 26 · 21: 0 marksMay/Jun 26 · 22: 3 marksMay/Jun 26 · 23: 0 marks

    Assessment objectives

    • AO1 Knowledge & understanding
    • AO2 Apply to a context
    • AO3 Evaluate & judge
    • Describe33%
    • Identify29%
    • State24%
    • Write24%
  • Sub-systems and decomposition (inputs, processes, outputs, storage); designing solutions with structure diagrams, flowcharts and pseudocode#9 of 19 on Paper 2Core · 6079% next paper3.3 marks20/25 sittings↘ May/Jun 2026

    A regular earner inside the topic — most papers touch it.

    Next Paper 2
    79%
    8 in 10
    Marks a paper
    3.3
    4% of the paper · 16% of the topic
    Asked in
    20 / 25
    Paper 2 sittings · 104 questions
    Last asked
    May/Jun 2026
    0478/23 · Q5 · 2 marks · 4-series streak
    • Asked in 20 of 25 Paper 2 sittings — about 8 papers in 10.
    • About 3.3 marks a paper (4% of Paper 2; 16% of the topic's marks across its 6 bullets).
    • Last asked May/Jun 2026 · 0478/23 · Q5 (2 marks) — in the most recent series.
    • Asked in each of the last 4 series.
    • Easing: 3.9 → 2.8 marks a paper.
    • Usually “Complete”: you must produce something — code, a diagram, a table — practise doing it, not reading it.
    • Biggest chunk of marks so far: 8 in May/Jun 2025 · 0478/23 · Q1.
    • It is examined mostly as AO2 (Apply to a context, 64%), the rest AO1 (36%) — you must apply it to the scenario or the given data — a definition alone will not score.
    Last 12 sittings↘ Easing
    Oct/Nov 24 · 23: 4.5 marksFeb/Mar 25 · 22: 0 marksMay/Jun 25 · 21: 4 marksMay/Jun 25 · 22: 4 marksMay/Jun 25 · 23: 8 marksOct/Nov 25 · 21: 8 marksOct/Nov 25 · 22: 0 marksOct/Nov 25 · 23: 2 marksFeb/Mar 26 · 22: 1.5 marksMay/Jun 26 · 21: 3 marksMay/Jun 26 · 22: 0.5 marksMay/Jun 26 · 23: 2 marks

    Assessment objectives

    • AO1 Knowledge & understanding
    • AO2 Apply to a context
    • AO3 Evaluate & judge
    • Complete53%
    • Write20%
    • Describe17%
    • Explain16%
  • Explaining the purpose of a given algorithm; standard methods of solution#12 of 19 on Paper 2Regular · 5368% next paper2.9 marks17/25 sittings↘ May/Jun 2026

    Set most sessions for a few marks; know the definition and one example.Syllabus: linear search, bubble sort, totalling, counting, maximum/minimum/average

    Next Paper 2
    68%
    7 in 10
    Marks a paper
    2.9
    4% of the paper · 20% of the topic
    Asked in
    17 / 25
    Paper 2 sittings · 90 questions
    Last asked
    May/Jun 2026
    0478/23 · Q3 · 0.5 marks · 11-series streak
    • Asked in 17 of 25 Paper 2 sittings — about 7 papers in 10.
    • About 2.9 marks a paper (4% of Paper 2; 20% of the topic's marks across its 6 bullets).
    • Last asked May/Jun 2026 · 0478/23 · Q3 (0.5 marks) — in the most recent series.
    • Asked in each of the last 11 series.
    • Easing: 4.3 → 1.8 marks a paper.
    • Usually “Complete” or “Explain”: you must produce something — code, a diagram, a table — practise doing it, not reading it.
    • Biggest chunk of marks so far: 8 in Oct/Nov 2024 · 2210/22 · Q4.
    • It is examined almost entirely as AO2 (Apply to a context, 80%) — you must apply it to the scenario or the given data — a definition alone will not score.
    Last 12 sittings↘ Easing
    Oct/Nov 24 · 23: 0 marksFeb/Mar 25 · 22: 1 marksMay/Jun 25 · 21: 0 marksMay/Jun 25 · 22: 6 marksMay/Jun 25 · 23: 2 marksOct/Nov 25 · 21: 1 marksOct/Nov 25 · 22: 3 marksOct/Nov 25 · 23: 6 marksFeb/Mar 26 · 22: 1.5 marksMay/Jun 26 · 21: 0 marksMay/Jun 26 · 22: 0.5 marksMay/Jun 26 · 23: 1.5 marks

    Assessment objectives

    • AO1 Knowledge & understanding
    • AO2 Apply to a context
    • AO3 Evaluate & judge
    • Complete47%
    • Explain37%
    • Describe33%
    • Write28%
  • Validation checks (range, length, type, presence, format, check digit) and verification checks (visual, double entry)#7 of 19 on Paper 2Core · 6876% next paper4.3 marks20/25 sittings↗ May/Jun 2026

    A regular earner inside the topic — most papers touch it.

    Next Paper 2
    76%
    8 in 10
    Marks a paper
    4.3
    6% of the paper · 18% of the topic
    Asked in
    20 / 25
    Paper 2 sittings · 87 questions
    Last asked
    May/Jun 2026
    0478/23 · Q3 · 10 marks · 10-series streak
    • Asked in 20 of 25 Paper 2 sittings — about 8 papers in 10.
    • About 4.3 marks a paper (6% of Paper 2; 18% of the topic's marks across its 6 bullets).
    • Last asked May/Jun 2026 · 0478/23 · Q3 (10 marks) — in the most recent series.
    • Asked in each of the last 10 series.
    • Rising: 4.3 → 5.1 marks a paper.
    • Usually “Explain” or “Give”: full sentences with a reason, not one-word answers.
    • Biggest chunk of marks so far: 11 in May/Jun 2026 · 2210/22 · Q3.
    • It is examined mostly as AO1 (Knowledge & understanding, 56%), the rest AO2 (34%) — definitions and descriptions in syllabus words score.
    Last 12 sittings↗ Rising
    Oct/Nov 24 · 23: 1 marksFeb/Mar 25 · 22: 2 marksMay/Jun 25 · 21: 7 marksMay/Jun 25 · 22: 0 marksMay/Jun 25 · 23: 2 marksOct/Nov 25 · 21: 0 marksOct/Nov 25 · 22: 0 marksOct/Nov 25 · 23: 1 marksFeb/Mar 26 · 22: 8 marksMay/Jun 26 · 21: 5 marksMay/Jun 26 · 22: 11 marksMay/Jun 26 · 23: 10 marks

    Assessment objectives

    • AO1 Knowledge & understanding
    • AO2 Apply to a context
    • AO3 Evaluate & judge
    • Explain35%
    • Give33%
    • Describe32%
    • Write31%
  • Test data (normal, abnormal, extreme, boundary); trace tables for dry runs; identifying and correcting errors in algorithms#3 of 19 on Paper 2Banker · 8387% next paper5.6 marks23/25 sittings→ May/Jun 2026

    Asked in nearly every paper — the bullet to know cold.

    Next Paper 2
    87%
    9 in 10
    Marks a paper
    5.6
    7% of the paper · 22% of the topic
    Asked in
    23 / 25
    Paper 2 sittings · 102 questions
    Last asked
    May/Jun 2026
    0478/23 · Q5 · 5 marks · 11-series streak
    • Asked in 23 of 25 Paper 2 sittings — nearly every paper.
    • About 5.6 marks a paper (7% of Paper 2; 22% of the topic's marks across its 6 bullets).
    • Last asked May/Jun 2026 · 0478/23 · Q5 (5 marks) — in the most recent series.
    • Asked in each of the last 11 series.
    • Usually “Complete” or “Describe”: you must produce something — code, a diagram, a table — practise doing it, not reading it.
    • Biggest chunk of marks so far: 9 in Oct/Nov 2024 · 2210/23 · Q7.
    • It is examined almost entirely as AO2 (Apply to a context, 78%) — you must apply it to the scenario or the given data — a definition alone will not score.
    Last 12 sittings→ Steady
    Oct/Nov 24 · 23: 9.5 marksFeb/Mar 25 · 22: 14 marksMay/Jun 25 · 21: 4 marksMay/Jun 25 · 22: 4 marksMay/Jun 25 · 23: 4 marksOct/Nov 25 · 21: 3 marksOct/Nov 25 · 22: 12 marksOct/Nov 25 · 23: 1 marksFeb/Mar 26 · 22: 5 marksMay/Jun 26 · 21: 0 marksMay/Jun 26 · 22: 9 marksMay/Jun 26 · 23: 5.5 marks

    Assessment objectives

    • AO1 Knowledge & understanding
    • AO2 Apply to a context
    • AO3 Evaluate & judge
    • Complete51%
    • Describe31%
    • State24%
    • Give24%
  • Writing and amending algorithms for a scenario in pseudocode, program code and flowcharts#10 of 19 on Paper 2Core · 5865% next paper3.7 marks17/25 sittings↗ May/Jun 2026

    A regular earner inside the topic — most papers touch it.

    Next Paper 2
    65%
    7 in 10
    Marks a paper
    3.7
    5% of the paper · 21% of the topic
    Asked in
    17 / 25
    Paper 2 sittings · 93 questions
    Last asked
    May/Jun 2026
    2210/21 · Q10 · 6 marks · 11-series streak
    • Asked in 17 of 25 Paper 2 sittings — about 7 papers in 10.
    • About 3.7 marks a paper (5% of Paper 2; 21% of the topic's marks across its 6 bullets).
    • Last asked May/Jun 2026 · 2210/21 · Q10 (6 marks) — in the most recent series.
    • Asked in each of the last 11 series.
    • Rising: 2.7 → 4.4 marks a paper.
    • Usually “Write” or “Explain”: you must produce something — code, a diagram, a table — practise doing it, not reading it.
    • Biggest chunk of marks so far: 8 in May/Jun 2026 · 2210/21 · Q5.
    • It is examined almost entirely as AO2 (Apply to a context, 100%) — you must apply it to the scenario or the given data — a definition alone will not score.
    Last 12 sittings↗ Rising
    Oct/Nov 24 · 23: 0 marksFeb/Mar 25 · 22: 5 marksMay/Jun 25 · 21: 5 marksMay/Jun 25 · 22: 0 marksMay/Jun 25 · 23: 5 marksOct/Nov 25 · 21: 4 marksOct/Nov 25 · 22: 4 marksOct/Nov 25 · 23: 9 marksFeb/Mar 26 · 22: 3 marksMay/Jun 26 · 21: 14 marksMay/Jun 26 · 22: 0 marksMay/Jun 26 · 23: 0 marks

    Assessment objectives

    • AO1 Knowledge & understanding
    • AO2 Apply to a context
    • AO3 Evaluate & judge
    • Write71%
    • Explain30%
    • Describe26%
    • State20%

11% of the topic's marks sit in question parts that belong to another topic (scenario questions cross sections) or that no bullet claims; they count for the topic, not for a bullet.

Marks a paper, year by year

1011121314151617181920212223242526

Grey years are the previous syllabus (2010–2022, 212 questions) — history, not counted in the rates.

By exam series

  • Feb/Mar4/4 · 24.5 mk
  • May/Jun12/12 · 21.1 mk
  • Oct/Nov9/9 · 25.1 mk

What you need to know6syllabus section 7

  1. The program development life cycle — analysis, design, coding and testing, and what happens at each stage

    Quiz this sub-topic (12)Past-paper questions (21)

  2. Sub-systems and decomposition (inputs, processes, outputs, storage); designing solutions with structure diagrams, flowcharts and pseudocode

    Quiz this sub-topic (8)Past-paper questions (104)

  3. Explaining the purpose of a given algorithm; standard methods of solution — linear search, bubble sort, totalling, counting, maximum/minimum/average

    Quiz this sub-topic (10)Past-paper questions (90)

  4. Validation checks (range, length, type, presence, format, check digit) and verification checks (visual, double entry)

    Quiz this sub-topic (9)Past-paper questions (87)

  5. Test data (normal, abnormal, extreme, boundary); trace tables for dry runs; identifying and correcting errors in algorithms

    Quiz this sub-topic (14)Past-paper questions (102)

  6. Writing and amending algorithms for a scenario in pseudocode, program code and flowcharts

    Quiz this sub-topic (8)Past-paper questions (93)

Video lectures13ZAK's YouTube channel · play here

0 of 13 watched
  • O LevelAS2023119 views

  • O LevelAS2021529 views

  • O LevelUrdu2021376 views

  • O Level2021610 views

  • O Level2020849 views

  • O Level2020734 views

Infographics6draw these the way the examiner expects · download as PNG

Flowchart symbolsUse exactly these shapes. Every decision has two labelled exits; flow lines carry arrows; one START, oneSTOP.TerminatorSTART / STOPProcessTotal ← Total + NInput / OutputINPUT N · OUTPUT TotalDecisionN > 0 ? → Yes / NoSubroutinepredefined process / callflow line (arrow)STARTINPUT NumNum > 0 ?YesOUTPUT "Positive"NoOUTPUT "Not +"STOPProgram development life cycleAnalysisDesignCodingTestingAnalysis (abstraction, decomposition → requirements) · Design (structure diagram, flowchart, pseudocode) · Coding · Testingcswithzak.com

Flowchart symbols & the PDLC

O LevelAS
Bubble sort — one pass, step by stepCompare each pair of neighbours; swap if out of order. After pass 1 the biggest is last; after pass n−1everything is sorted.5381compare 5 and 3 → 5 > 3, swap3581compare 5 and 8 → in order, no swap3581compare 8 and 1 → 8 > 1, swap3518end of pass 1: the largest value is now lastPass 2 → 3 1 5 8 · Pass 3 → 1 3 5 8. Each pass needs one fewer comparison. Stop early if a pass makes no swaps.FOR i ← 1 TO N - 1 FOR j ← 1 TO N - i IF A[j] > A[j+1] THEN Temp ← A[j] A[j] ← A[j+1] A[j+1] ← Temp ENDIF NEXT jNEXT iFlag version: REPEAT … Swapped ← FALSE… set TRUE on any swap … UNTIL NOT SwappedLinear search (the other standard algorithm)Found ← FALSE : i ← 1 : WHILE i ≤ N AND NOT Found → IF A[i] = Target THEN Found ← TRUE ELSE i ← i + 1Works on unsorted data; checks every item in the worst case. Binary search (AS) needs sorted data and halves the list each time.Totalling: Total ← Total + Value · Counting: Count ← Count + 1 when true · Max/min: compare with the current bestcswithzak.com

Bubble sort & linear search

O LevelAS
Choosing test dataRule under test: “enter a mark from 0 to 100”. Each type of test data has a job — name the type AND saywhy it is chosen.-1050100101accepted range 0 … 100rejectedrejectedTypePurposeExamples hereNormaltypical valid data the program should accept and process23, 50, 87Extremevalid data at the very limits of the accepted range0 and 100Boundaryeither side of each limit: last accepted, first rejected-1 / 0 and 100 / 101Abnormalinvalid (erroneous) data the program must reject-5, 150, “abc”, 3.7Validation: is the data sensible? range · type · length · format · presence · check digit checks.Verification: was it entered correctly? double entry, visual check.Trace table / dry run: one column per variable and the output, one row per change — the way to find logic errors.9618 adds: walkthrough (people read the code), alpha (in-house), beta (real users before release), acceptance (the client signs off).cswithzak.com

Choosing test data

O LevelAS
Dry run with a trace table (animated)Follow the code one line at a time. Each time a variable changes, write its new value in its column;start a new row each time the loop goes round.1Total ← 02FOR Count ← 1 TO 33 INPUT Num4 Total ← Total + Num5NEXT Count6OUTPUT TotalInput data:472CountNumTotalOUTPUT01442711321313NOWLine 1: Total starts at 0Line 2: the loop starts: Count = 1Line 3: INPUT reads the first value: Num = 4Line 4: Total = 0 + 4 = 4Line 5: NEXT: Count = 2, so start a new rowLine 3: INPUT reads Num = 7Line 4: Total = 4 + 7 = 11Line 5: NEXT: Count = 3, new row againLine 3: INPUT reads Num = 2Line 4: Total = 11 + 2 = 13Line 5: Count was 3, the end value: loop stopsLine 6: OUTPUT Total prints 13Finished: the program outputs 13One line at a timehighlight it, do exactly what it saysWrite only what changesleave a cell blank if nothing changedNew row each time roundthe loop counter starts each new rowExam check: the last value in a column is the variable's final value, and OUTPUT shows exactly what is printed.cswithzak.com

Dry run with a trace table (animated)

O Level
Decomposing a system into sub-systems (animated)Top-down design: break the whole system into sub-systems, then break each sub-system again until everypart is small enough to solve.Library systemMemberswho can borrowBooksthe catalogueLoansborrowing and returnsAdd memberEdit detailsAdd bookSearch catalogueIssue bookReturn bookReturn book, one small task:Inputsbook ID, today's dateProcessesdays late × fine rateOutputsfine shown on screenStorageloan record updatedEach smallest part has its own inputs, processes, outputs and storageStart with the whole system: one box at the topLevel 1: split it into sub-systemsLevel 2: split each sub-system again until every part is one small taskA structure diagram shows this hierarchy: each box is a sub-system and the boxes under it are the parts it is made of.cswithzak.com

Decomposing a system into sub-systems (animated)

O Level
Linear search vs binary search (animated)The same sorted list, looking for 60. Linear search checks the items one by one from the start. Binarysearch checks the middle item and throws away the half that cannot hold 60.Linear search: check each item in turn381217233138455260711234567891011Item 1 = 3. Not 60, move on to the next item1Item 2 = 8. Not 60, move on to the next item2Item 3 = 12. Not 60, move on to the next item3Item 4 = 17. Not 60, move on to the next item4Item 5 = 23. Not 60, move on to the next item5Item 6 = 31. Not 60, move on to the next item6Item 7 = 38. Not 60, move on to the next item7Item 8 = 45. Not 60, move on to the next item8Item 9 = 52. Not 60, move on to the next item9Item 10 = 60. Found after 10 comparisons10comparisonsBinary search: check the middle, halve the rangeneeds sorted data · 9618 A Level, not on the 2210 / 0478 syllabus381217233138455260711234567891011Middle is item 6 = 31. 31 < 60, so throw away item 6 and everything left of it1Middle is item 9 = 52. 52 < 60, so throw away items 7 to 92Middle is item 10 = 60. Found after only 3 comparisons3comparisonsbar = range leftLinear searchany order · one item at a time · up to n comparisonsBinary searchsorted only · halves the range · about log₂ n comparisonsOn the 2210 / 0478 paper, write linear search: start at the first item and stop when it is found or the list ends.For 1000 items: linear search may need 1000 comparisons, binary search at most 10.cswithzak.com

Linear search vs binary search (animated)

O Level

Browse all infographics →

Key terms11use these exact words in the exam

Code help4referenced to the Cambridge pseudocode guide

Linear search

pseudocode 9618 §7.3 WHILE Run in Playground
DECLARE A : ARRAY[1:6] OF INTEGER
DECLARE i, Target : INTEGER
DECLARE Found : BOOLEAN
A[1] ← 8
A[2] ← 3
A[3] ← 9
A[4] ← 1
A[5] ← 7
A[6] ← 4
Target ← 7
Found ← FALSE
i ← 1
WHILE i <= 6 AND NOT Found DO
IF A[i] = Target THEN
Found ← TRUE
ELSE
i ← i + 1
ENDIF
ENDWHILE
IF Found THEN
OUTPUT "Found at position ", i
ELSE
OUTPUT "Not found"
ENDIF

Bubble sort with a swapped flag

pseudocode Run in Playground
DECLARE A : ARRAY[1:5] OF INTEGER
DECLARE i, Temp : INTEGER
DECLARE Swapped : BOOLEAN
A[1] ← 5
A[2] ← 1
A[3] ← 4
A[4] ← 2
A[5] ← 3
REPEAT
Swapped ← FALSE
FOR i ← 1 TO 4
IF A[i] > A[i + 1] THEN
Temp ← A[i]
A[i] ← A[i + 1]
A[i + 1] ← Temp
Swapped ← TRUE
ENDIF
NEXT i
UNTIL NOT Swapped
FOR i ← 1 TO 5
OUTPUT A[i]
NEXT i

💡 Open the Trace Table tab after running — this is the classic Paper 2 trace question.

Totalling, counting, max, min, average

pseudocode Run in Playground
DECLARE Marks : ARRAY[1:5] OF INTEGER
DECLARE i, Total, Count, Max, Min : INTEGER
Marks[1] ← 67
Marks[2] ← 91
Marks[3] ← 45
Marks[4] ← 78
Marks[5] ← 84
Total ← 0
Count ← 0
Max ← Marks[1]
Min ← Marks[1]
FOR i ← 1 TO 5
Total ← Total + Marks[i]
IF Marks[i] >= 50 THEN
Count ← Count + 1
ENDIF
IF Marks[i] > Max THEN
Max ← Marks[i]
ENDIF
IF Marks[i] < Min THEN
Min ← Marks[i]
ENDIF
NEXT i
OUTPUT "Total ", Total, " Passes ", Count, " Max ", Max, " Min ", Min, " Avg ", Total / 5

Validation: range + presence with re-prompt

pseudocode Run in Playground
DECLARE Age : INTEGER
REPEAT
OUTPUT "Enter age 5-120"
INPUT Age
IF Age < 5 OR Age > 120 THEN
OUTPUT "Out of range, try again"
ENDIF
UNTIL Age >= 5 AND Age <= 120
OUTPUT "Accepted ", Age

Playground examples24runnable programs for this topic

  • Swap two variables

    The three-line swap with a temporary variable — a favourite trace-table question.

    O LevelASPseudocodeBasics & data types §1.5
    Run
  • FOR loop & totalling

    A count-controlled loop that accumulates a running total.

    O LevelASPseudocodeIteration §7.1
    Run
  • WHILE with a sentinel — totalling & counting

    Read numbers until -1; INPUT once before the loop and again at the end of the body.

    O LevelASPseudocodeIteration §7.3 · 2210 WHILE … DO
    Run
  • Maximum, minimum & average

    The standard algorithm: start Highest very low and Lowest very high, then update as you go.

    O LevelASPseudocodeIteration 2210 §7.1 standard methods
    Run
  • Counting — how many passed?

    Two counters updated inside a loop, then a percentage.

    O LevelASPseudocodeIteration 2210 §7.1 standard methods
    Run
  • Total, average and position of the maximum

    Keep the index of the best value, not just the value, so you can say where it was.

    O LevelASPseudocodeArrays §3.2
    Run
  • Range check

    Keep asking until the value is between 0 and 100.

    O LevelASPseudocodeValidation, testing & exceptions 2210 §7.3 / 9618 §6.2
    Run
  • Presence & length checks

    Nothing entered? Too short or too long? Say which check failed.

    O LevelASPseudocodeValidation, testing & exceptions 2210 §7.3 / 9618 §6.2
    Run
  • Type check — digits only

    A function that tests every character before the string is converted to a number.

    O LevelASPseudocodeValidation, testing & exceptions 2210 §7.3 / 9618 §6.2
    Run
  • Format check — is this an email address?

    One @ that is not first, and a dot after it that is not last.

    O LevelASPseudocodeValidation, testing & exceptions 2210 §7.3 / 9618 §6.2
    Run
  • Check digit — ISBN-13

    Weights 1 and 3 alternate, total MOD 10, subtract from 10. The classic check-digit algorithm.

    O LevelASPseudocodeValidation, testing & exceptions 2210 §2.3, §7.3
    Run
  • Verification — double entry

    Validation checks the data is sensible; verification checks it was entered correctly.

    O LevelASPseudocodeValidation, testing & exceptions 2210 §7.3 / 9618 §6.2
    Run
  • Trace table practice

    A typical dry-run question. Run it, then open the Trace table tab and check it against your own table.

    O LevelASPseudocodeValidation, testing & exceptions 2210 §7.4 / 9618 §12.3
    Run
  • Normal, boundary and abnormal test data

    Drive a function with each kind of test data and check the results against what you expected.

    ASPseudocodeValidation, testing & exceptions 9618 §12.3
    Run
  • Linear search

    Check each element in turn and stop as soon as the target is found.

    O LevelASPseudocodeSearching 2210 §7.1 / 9618 §9.2
    Run
  • Linear search — every match

    Do not stop at the first hit: report every position and count them.

    O LevelASPseudocodeSearching 2210 §7.1
    Run
  • Bubble sort

    Compare neighbours and swap; after each pass the largest value has bubbled to the end.

    O LevelASPseudocodeSorting 2210 §7.1 / 9618 §9.2
    Run
  • Sort names alphabetically

    Bubble sort works on strings too: "Ali" < "Zara" compares character codes.

    O LevelASPseudocodeSorting 2210 §7.1
    Run
  • O Level Section B — a week of temperatures

    Validate seven readings into an array, then report the average and the hottest day. Everything Paper 2 Section B expects in one program.

    O LevelPseudocodeExam-style tasks 2210 §7–8
    Run
  • O Level Section B — cinema booking

    Ticket types with CASE, quantities, a running total and a group discount.

    O LevelPseudocodeExam-style tasks 2210 §7–8
    Run
  • Totalling, counting, max, min, average

    The standard loop pattern with a list — and then the built-ins sum(), max(), min(), len() that do it in one line.

    O LevelASPythonIteration §7.1 ↔ Python
    Run
  • Validation loop — range and type checks

    Keep asking until the input is a whole number between 1 and 100. try/except catches the ValueError from int().

    O LevelASPythonValidation, testing & exceptions §7.3 ↔ Python, A2 §20.3
    Run
  • Linear search

    Walk the list until you find the target — the exam wants the loop, not list.index().

    O LevelASPythonSearching §7 ↔ Python
    Run
  • Bubble sort with a swapped flag

    The classic Paper 2 / Paper 4 sort. Open the Trace tab to watch the swaps.

    O LevelASPythonSorting §7 ↔ Python
    Run

Also for this topic: 9 Java programs · 5 VB.NET programs in the browser compilers.

Flowchart Studio12draw-it-yourself tasks and worked flowcharts, run and checked box by box

  • Area of a rectangle

    Input two numbers, multiply, output — the simplest complete flowchart.

    O LevelASSequence & I/O 2210 §7
    Open
  • Celsius to Fahrenheit

    A formula in a process box; the exam's favourite two-line calculation.

    O LevelSequence & I/O 2210 §7
    Open
  • Pass or fail

    One decision, two output boxes, arrows that rejoin before Stop.

    O LevelSelection 2210 §7
    Open
  • Largest of three numbers

    Nested decisions: the chart shows why the second comparison depends on the first.

    O LevelASSelection 2210 §7
    Open
  • Total and average of N numbers

    Totalling and counting together, then a division after the loop — the classic 2210 Q.

    O LevelASTotalling, counting, max / min 2210 §7
    Open
  • Total until −1 (rogue value)

    A sentinel-controlled loop: read, test, add, read again.

    O LevelASTotalling, counting, max / min 2210 §7
    Open
  • Highest and lowest of 10 marks

    Set max low and min high, then one decision each inside the loop.

    O LevelASTotalling, counting, max / min 2210 §7
    Open
  • Count how many passed

    A counter that only increments inside a decision.

    O LevelTotalling, counting, max / min 2210 §7
    Open
  • Range check with a rejection loop

    Keep asking until the value is between 1 and 100 — the validation flowchart every paper wants.

    O LevelASValidation & rejection loops 2210 §7
    Open
  • Presence check

    A WHILE loop that rejects an empty string.

    O LevelValidation & rejection loops 2210 §7
    Open
  • Linear search

    Search an array for a value with a found flag — 2210 §7's standard method.

    O LevelASArrays 2210 §7
    Open
  • One pass of a bubble sort

    Compare neighbours and swap: the decision inside the loop with three process boxes.

    O LevelASArrays 2210 §7
    Open

Test yourself

Ready to check you know it?

Every round is a fresh random draw, weak cards come back until you get them right, and past-paper questions come with their mark schemes. Marks earn XP on your dashboard.

NewCS Games · 16 to play

Revise this topic by playing

Quiz battles, a daily CS word, SQL whodunnits, logic-gate puzzles and arcade — every game drills the syllabus. Solo against AskZ bots, with friends, or with your whole class. Free, no sign-up.

Play now
Enroll nowOnline classes