Standard Algorithms (GCSE & IGCSE Computer Science): Revision Notes and Worksheets
GCSE and IGCSE Computer Science standard algorithms: linear and binary search, bubble, merge and insertion sort, totalling, counting, max, min and average.

Finding one record among thousands, or putting a list into order, are jobs computers do millions of times a day, and the exam expects you to know the standard ways of doing them. This guide covers GCSE and IGCSE standard algorithms: linear search, binary search, bubble sort, merge sort, insertion sort, how to compare and choose between them, and totalling, counting and finding the maximum, minimum and average. Each part has a worked example and a worksheet for your exam board.
Cambridge IGCSE 0478 students: you only need L1, L3 and L7, and only the points marked IGCSE or Both boards. Parts L2, L4, L5 and L6 are on the OCR J277 specification only. All the data and organisations in this post are made up.
What do standard algorithms cover for OCR and Cambridge?
A standard algorithm is a well-known method for a common task, such as searching a list or sorting it. OCR J277 has five searching and sorting algorithms in 2.1.3. Cambridge IGCSE 0478 limits its standard methods of solution (7.4) to linear search, bubble sort, totalling, counting, and finding the maximum, minimum and average. The table below is based on the OCR J277 specification (version 3.1) and the Cambridge IGCSE 0478 syllabus for 2026-2028, as checked in November 2026.
Part | Topic | OCR J277 | Cambridge 0478 |
|---|---|---|---|
L1 | Linear search (both boards) | 2.1.3 | 7.4 |
L2 | Binary search (GCSE only) | 2.1.3 | not on syllabus |
L3 | Bubble sort (both boards) | 2.1.3 | 7.4 |
L4 | Merge sort (GCSE only) | 2.1.3 | not on syllabus |
L5 | Insertion sort (GCSE only) | 2.1.3 | not on syllabus |
L6 | Comparing the search and sort algorithms (GCSE only) | 2.1.3 | not on syllabus |
L7 | Totalling, counting, maximum, minimum and average (both boards) | 2.2.1 (used in programs) | 7.4, 8.1.4(d) |
The two boards ask different things about the code.
GCSE only: OCR J277 asks you to understand the main steps and the segments of code, apply each algorithm to a data set, know any pre-requisites, and identify an algorithm from code, pseudocode or OCR Exam Reference Language. You do not need to remember the code.
IGCSE only: Cambridge 0478 expects you to write and amend linear search, bubble sort, totalling, counting, maximum, minimum and average in pseudocode (7.9), and they can appear in the 15-mark scenario question.
Code on this page is in OCR Exam Reference Language (arrays start at index 0) or Cambridge pseudocode (arrays here start at index 1), labelled each time.
L1: How does a linear search work?
Both boards. A linear search checks each item in a list in turn, starting from the first item, until it finds the item it is looking for (the target) or reaches the end of the list.
Step 1: start at the first item.
Step 2: compare the item with the target. If they are equal, the target is found: stop and give its position.
Step 3: if not, move on to the next item and repeat.
Step 4: if the end of the list is reached without a match, the target is not found.
A linear search has no pre-requisite: it works on unsorted data as well as sorted data. It is simple, but it is slow on large lists, because it may have to check every item: when the target is the last item, or when it is not in the list at all.
The code has three segments: a loop through the positions, an IF that compares each item with the target, and a found flag (or a stored position) so the loop can stop.
OCR Exam Reference Language:
Cambridge pseudocode, for an array Code[1:6]:
GCSE only: you need to identify a linear search from code like the first block, not memorise it. IGCSE only: you should be able to write a linear search like the second block, and amend it, for example to output a price stored in a second array at the same index.
Worked example: searching a list of locker numbers (both boards)
The list is 42, 17, 93, 8, 56, 71. It is not sorted.
Step 1: look for 56. Compare 42, then 17, then 93, then 8, then 56: found. That is 5 comparisons.
Step 2: give the position in your board's terms. 56 is at index 4 in OCR (counting from 0), or at position 5 in a Cambridge array that starts at 1.
Step 3: look for 30. All 6 items are compared, the end of the list is reached, and the output is "Not found".
Practise L1: OCR questions · OCR mark scheme · Cambridge questions · Cambridge mark scheme
L2: How does a binary search work?
GCSE only. A binary search repeatedly checks the middle item and discards the half of the list that cannot contain the target. Its pre-requisite is that the data must be sorted (in order).
Step 1: find the middle item of the items that remain.
Step 2: if it equals the target, the target is found: stop.
Step 3: if the target is smaller than the middle item, discard the middle item and every item after it (the upper half).
Step 4: if the target is larger, discard the middle item and every item before it (the lower half).
Step 5: repeat on the items that remain, until the target is found or no items are left (not found).
When there is an even number of items there are two middle items. The code below works out the middle position as (low + high) DIV 2, which takes the one to the left of the centre. In the exam, follow the rule the question gives.
OCR Exam Reference Language (you need to recognise it, not remember it):
The giveaways are the low, high and mid variables, and low or high moving past mid after each comparison.

Worked example: binary search on 11 sorted numbers (GCSE only)
The sorted list is 3, 9, 14, 20, 27, 31, 38, 45, 52, 60, 66 (indexes 0 to 10).
Step 1: look for 60. The middle item is index (0 + 10) DIV 2 = 5, which is 31. 60 is larger, so discard 3 to 31.
Step 2: 38, 45, 52, 60, 66 remain (indexes 6 to 10). The middle is index (6 + 10) DIV 2 = 8, which is 52. 60 is larger, so discard 38 to 52.
Step 3: 60, 66 remain (indexes 9 and 10). The middle is index (9 + 10) DIV 2 = 9, which is 60: found after 3 comparisons. A linear search would have needed 10.
Step 4: look for 40, which is not in the list. The items checked are 31, 52, 38, 45. After 45, no items are left, so 40 is not found.
Practise L2: OCR questions · OCR mark scheme
L3: How does a bubble sort work?
Both boards. A bubble sort works through the list comparing each pair of adjacent items (items next to each other), and swaps them if they are in the wrong order.
Step 1: compare the first and second items. If they are in the wrong order, swap them.
Step 2: move along one place and compare the next pair. Carry on to the end of the list. That is one pass.
Step 3: after the first pass into ascending order, the largest value is in its final place at the end of the list.
Step 4: repeat the passes. When a pass makes no swaps, the list is sorted and the algorithm stops.
To swap two items, the code uses a temporary variable, so the first value is not lost when it is overwritten: temp = a, then a = b, then b = temp.
A bubble sort is simple to code and uses little extra memory, because it sorts the list in place. But it is slow on large lists, because it can need many passes and many comparisons.
OCR Exam Reference Language:
Cambridge pseudocode, for an array Items[1:5]:
GCSE only: identify a bubble sort from its code: it compares item i with item i + 1, swaps them using a temporary variable, and repeats until a pass makes no swaps. IGCSE only: be able to write and amend it in pseudocode, for example changing > to < on the IF line to sort into descending order.
Worked example: bubble sort of 15, 4, 23, 8, 11 (both boards)
Sort into ascending order. Each pass makes 4 comparisons.
Pass 1: 15 and 4 swap; 15 and 23 stay; 23 and 8 swap; 23 and 11 swap. The list is 4, 15, 8, 11, 23, after 3 swaps. 23 is in its final place.
Pass 2: 4 and 15 stay; 15 and 8 swap; 15 and 11 swap; 15 and 23 stay. The list is 4, 8, 11, 15, 23, after 2 swaps.
Pass 3: no swaps, so the algorithm knows the list is sorted and stops. The list was already in order after pass 2, but the algorithm needs a pass with no swaps to know that.
Practise L3: OCR questions · OCR mark scheme · Cambridge questions · Cambridge mark scheme
L4: How does a merge sort work?
GCSE only. A merge sort is a divide and conquer algorithm with two main stages.
Step 1 (divide): split the list in half, then split each half again, until every sub-list holds one item. A list of one item is already sorted.
Step 2 (merge): merge pairs of sub-lists. Compare the first item of each sub-list, move the smaller one into the new list, and repeat until both sub-lists are used up. The new list is in order.
Step 3: keep merging pairs until one sorted list remains.
The code has two main segments: one that splits a list into a left half and a right half, and a merge loop that compares left[i] with right[j] and copies the smaller into the new list, then copies across whatever is left over.
A merge sort is much faster than a bubble sort or an insertion sort on large lists. But it uses more memory, because it creates new lists as it works, and it is more complex to code.

Worked example: merge sort of 8 numbers (GCSE only)
Sort 38, 12, 45, 7, 29, 16, 51, 3 into ascending order.
Step 1 (split): [38, 12, 45, 7] [29, 16, 51, 3], then [38, 12] [45, 7] [29, 16] [51, 3], then 8 single items.
Step 2 (merge pairs): [12, 38] [7, 45] [16, 29] [3, 51].
Step 3 (merge again): [7, 12, 38, 45] [3, 16, 29, 51].
Step 4 (final merge): compare 7 and 3: move 3. Compare 7 and 16: move 7. Compare 12 and 16: move 12. Carry on until the list is 3, 7, 12, 16, 29, 38, 45, 51. When one list runs out, the rest of the other list is copied across in order.
In the exam, show every split and every merge. Never merge two lists by joining them end to end and then sorting: merging itself keeps the items in order.
Practise L4: OCR questions · OCR mark scheme
L5: How does an insertion sort work?
GCSE only. An insertion sort builds a sorted part at the start of the list and inserts the remaining items into it one at a time. While it runs, the list has two parts: a sorted part and an unsorted part.
Step 1: treat the first item as the sorted part.
Step 2: take the next item from the unsorted part.
Step 3: compare it with the items in the sorted part, moving from right to left. Shift each larger item one place to the right.
Step 4: insert the item into the gap, in its correct position.
Step 5: repeat until every item has been inserted.
OCR Exam Reference Language (recognise it, do not memorise it):
The outer for loop takes each item in turn; the inner while loop shifts larger items to the right; the last line inserts the item into the gap.
An insertion sort is simple to code, uses little extra memory, and is quick for small lists or lists that are nearly in order. It is slow on large unsorted lists.
Worked example: insertion sort of 27, 9, 34, 15, 4 (GCSE only)
Sort into ascending order. 27 is the sorted part to start with.
Insertion 1: insert 9. It is smaller than 27, so 27 shifts right: 9, 27, 34, 15, 4.
Insertion 2: insert 34. It is larger than 27, so nothing moves: 9, 27, 34, 15, 4.
Insertion 3: insert 15. 34 and 27 shift right; 15 goes after 9: 9, 15, 27, 34, 4.
Insertion 4: insert 4. All four sorted items shift right; 4 goes at the start: 4, 9, 15, 27, 34. The list is sorted.
Practise L5: OCR questions · OCR mark scheme
L6: Which search or sort algorithm should you use?
GCSE only. OCR J277 can ask you to compare the algorithms, identify each one from its code, and recommend one for a scenario with reasons. (Cambridge 0478 has only linear search and bubble sort, so it has nothing to choose between.)
Algorithm | Pre-requisite | Strengths | Weaknesses |
|---|---|---|---|
Linear search | none: works on unsorted data | simple to code; fine for small or unsorted lists | slow on large lists: may check every item |
Binary search | data must be sorted | much faster on large sorted lists: each comparison halves the items left | the list must be sorted first; more complex to code |
Bubble sort | none | simple; little extra memory; stops early if a pass makes no swaps | slow on large lists |
Insertion sort | none | simple; little extra memory; quick on small or nearly sorted lists | slow on large unsorted lists |
Merge sort | none | fastest of the three sorts on large lists | uses more memory; more complex to code |
How to spot each one in code:
Linear search: one loop from the first item, comparing each item with the target.
Binary search: low, high and mid variables; mid = (low + high) DIV 2.
Bubble sort: compares item i with item i + 1, swaps with a temp variable, repeats until no swaps.
Insertion sort: a current item, an inner loop that shifts larger items right, then inserts the item.
Merge sort: splits into left and right halves, then merges by comparing left[i] with right[j].
Worked example: recommend an algorithm (GCSE only)
Step 1: a list of 1 000 000 sorted account numbers. A linear search might check all 1 000 000. A binary search halves the list each time, so it needs at most 20 comparisons (halving 20 times is enough, because 2²⁰ = 1 048 576, which is more than 1 000 000). Recommend binary search, because the data is sorted and the list is large.
Step 2: a list of 30 visitor badge numbers in the order people arrived. It is not sorted, so binary search cannot be used: recommend linear search.
Step 3: a small device with very little memory sorts 15 readings that are nearly always in order. Recommend insertion sort: it uses little extra memory and is quick on nearly sorted lists. Merge sort would need extra memory for new lists.
Practise L6: OCR questions · OCR mark scheme
L7: How do you total, count and find the maximum, minimum and average?
Both boards. These techniques all follow the same pattern: initialise a variable before the loop, update it inside the loop, and output it after the loop.
Totalling: set the total to 0 before the loop, then add each value to it inside the loop: total = total + value.
Counting: set the count to 0, then add 1 each time an item meets the condition (or each time round the loop): count = count + 1.
Maximum: start with the first value in the list, then replace it whenever a larger value is found.
Minimum: start with the first value, then replace it whenever a smaller value is found.
Average (mean): total ÷ number of values, worked out after the loop has finished.
You can also start the maximum with a value lower than any possible value (or the minimum with a value higher than any possible value), but starting with the first item always works.
IGCSE only: Cambridge 0478 names totalling, counting, and finding the maximum, minimum and average as standard methods of solution (7.4), and totalling and counting as programming concepts (8.1.4(d)); you should be able to write them in pseudocode. GCSE only: OCR J277 does not list them as standard algorithms, but they are part of the programming fundamentals in 2.2.1 (variables, operators, assignment and iteration), and they come up in Paper 2 programs and trace tables.
OCR Exam Reference Language:
Cambridge pseudocode, for an array Times[1:6]:
Worked example: queue times at a help desk (both boards)
A help desk records six waiting times, in minutes: 12, 7, 25, 18, 9, 21. The code above totals them, counts the times over 15 minutes, and finds the longest, the shortest and the average.
Time | Total | Count (over 15) | Highest | Lowest |
|---|---|---|---|---|
12 | 12 | 0 | 12 | 12 |
7 | 19 | 0 | 12 | 7 |
25 | 44 | 1 | 25 | 7 |
18 | 62 | 2 | 25 | 7 |
9 | 71 | 2 | 25 | 7 |
21 | 92 | 3 | 25 | 7 |
Step 1: the total is 92, and 3 times are over 15 minutes.
Step 2: the highest is 25 and the lowest is 7.
Step 3: the average is worked out after the loop: 92 ÷ 6 = 15.33 (to 2 decimal places).
Practise L7: OCR questions · OCR mark scheme · Cambridge questions · Cambridge mark scheme
Common exam mistakes in standard algorithms
Linear search: describing it without saying it starts at the first item and checks each item in turn.
(GCSE) Binary search: forgetting that the data must be sorted, or forgetting the step where the middle item equals the target and the search stops.
(GCSE) Binary search: discarding the wrong half, or keeping the middle item in the half that remains.
Bubble sort: writing "it sorts the list" instead of the steps: compare adjacent items, swap if in the wrong order, repeat passes until no swaps.
Bubble sort: stopping as soon as the list looks sorted. The algorithm only stops after a pass with no swaps.
(GCSE) Merge sort: joining two lists end to end and then sorting them. Merging compares the front items and keeps the new list in order.
(GCSE) Insertion sort: swapping items like a bubble sort. Insertion sort shifts larger items right and inserts the item into the gap.
Totalling and counting: setting the total or count to 0 inside the loop, so it is reset every time.
Maximum: starting it at 0 when the values can be negative (for example freezer temperatures of -18, -21 and -16). Start with the first item instead.
Average: working it out inside the loop, or dividing by the wrong number. Divide the total by the number of values after the loop.
Quick recap
L1: linear search checks each item in turn from the first until the target is found or the list ends; works on unsorted data; IGCSE students write it in pseudocode.
L2: (GCSE only) binary search checks the middle item and discards half each time; the data must be sorted.
L3: bubble sort compares adjacent items and swaps them, pass after pass, until a pass makes no swaps; IGCSE students write it in pseudocode.
L4: (GCSE only) merge sort splits the list into single items, then merges pairs in order until one list remains; fast but uses more memory.
L5: (GCSE only) insertion sort inserts each item into its place in the sorted part, shifting larger items right.
L6: (GCSE only) binary search for large sorted lists, linear for unsorted or small ones; merge sort for large lists, insertion sort for small or nearly sorted ones.
L7: initialise before the loop, update inside it, output after it: total = total + value, count = count + 1, replace the max or min when beaten, average = total ÷ number of values.
Download the whole module
Frequently asked questions
Which standard algorithms are on the Cambridge IGCSE 0478 syllabus?
Only linear search, bubble sort, totalling, counting, and finding the maximum, minimum and average. Binary search, merge sort and insertion sort are on OCR J277 only.
Do I need to memorise the code for the searching and sorting algorithms?
For OCR J277, no: you need the main steps, the segments of code, and to apply and identify each algorithm, but not to remember the code. For Cambridge 0478, you should be able to write and amend a linear search and a bubble sort in pseudocode.
What is the difference between a linear search and a binary search?
A linear search checks each item in turn from the first and works on unsorted data. A binary search checks the middle item and discards half of the remaining items each time, so it is much faster on large lists, but the data must be sorted first.
When does a bubble sort stop?
A bubble sort stops after a pass in which no swaps are made. The list may already be in order before that pass, but the algorithm needs a pass with no swaps to know it is sorted.
What is the difference between a merge sort and an insertion sort?
A merge sort splits the list into single items and then merges pairs of lists in order; it is fast on large lists but uses more memory. An insertion sort inserts each item into its correct place in a sorted part at the start of the list; it uses little extra memory and is quick on small or nearly sorted lists.
How do you find the average of the values in an array?
Set a total to 0 before the loop, add each value to the total inside the loop, and after the loop divide the total by the number of values.
Previous module: Algorithm design revision notes.
More help: browse the GCSE Computer Science revision hub.