Standard algorithms
| English | Chinese | Pinyin |
|---|---|---|
| linear search | 线性查找 | xiàn xìng chá zhǎo |
| bubble sort | 冒泡排序 | mào pào pái xù |
| counting | 计数 | jì shù |
| totalling | 求和 | qiú hé |
The classic recipes
- A few standard algorithms appear again and again.
- You must know linear search 线性查找, bubble sort 冒泡排序, and the counting 计数/totalling 求和 patterns.
- Each is short, but worth recognising instantly.
Linear search
found ← FALSE
FOR i ← 0 TO 9
IF list[i] = searchValue THEN found ← TRUE
NEXT i
OUTPUT found
- A linear search checks each item in turn, from the start, until it finds the value (or reaches the end).
- It works on any list — no sorting needed.

A flowchart for the sum algorithm, using the standard symbols (start/end, input/output, process, decision).
Standard algorithms
compare adjacent, swap if needed
Step through a bubble sort — compare neighbours and swap until everything is in order.
A linear search finds a value by:
Linear search examines items one by one until it finds the value or reaches the end.
Bubble sort
FOR i ← 0 TO 8
IF list[i] > list[i + 1] THEN
temp ← list[i]
list[i] ← list[i + 1]
list[i + 1] ← temp
NEXT i
- A bubble sort compares each side-by-side pair and swaps them if they are out of order.
- It repeats this until no more swaps are needed — leaving the list sorted.

Bubble sort compares each side-by-side pair and swaps them if they are out of order, repeating until sorted.
A bubble sort puts a list in order by:
It swaps out-of-order neighbours and repeats passes until no swaps are needed.
Totalling, counting, max/min/average
- Totalling — keep a running total:
total ← total + value. - Counting — add 1 each time something happens:
count ← count + 1. - Maximum/minimum — keep the largest/smallest value seen so far.
- Average — divide the total by how many values there are.
Which line adds a value to a running total?
total ← total + value accumulates a sum; count ← count + 1 counts occurrences.
Match each standard algorithm to how it works.
These four — search, sort, total and max — are the building blocks of most exam algorithms.
Using totalling on the list [2, 4, 6, 8], what is the final total?
2 + 4 + 6 + 8 = 20.
You've got it
- linear search checks each item in turn (works on any list)
- bubble sort swaps out-of-order neighbours, repeating until sorted
- totalling (
total ← total + value) and counting (count ← count + 1) - max/min = keep the best so far; average = total ÷ count