Demonstrate that an algorithm is a solution to a problem expressed as a finite, well‑defined sequence of steps.
| Characteristic | What It Means | Why It Matters for Exams |
|---|---|---|
| Correctness | Produces the required output for all valid inputs. | Ensures the answer marks the highest marks in AO2. |
| Efficiency | How quickly it runs (time) and how much extra memory it needs (space). | Used when comparing two possible solutions. |
| Generality | Works for any input that satisfies the problem’s constraints, not just a single example. | Shows understanding of abstraction – a common AO2 requirement. |
| Determinism | Given the same input, the algorithm always follows the same sequence of steps and yields the same result. | Important when justifying correctness. |
Pseudocode mixes natural language with programming constructs. The assignment arrow ← is used for clarity.
// Find the maximum value in an array A[1..n]INPUT: array A, integer n
max ← A[1]
FOR i ← 2 TO n DO
IF A[i] > max THEN
max ← A[i]
END IF
END FOR
OUTPUT max
Flowcharts use standard symbols (oval = Start/End, parallelogram = Input/Output, rectangle = Process, diamond = Decision). The diagram below follows the Cambridge conventions.
+-------------------+
| Start |
+----------+--------+
|
+----------v--------+
| Input A[1..n] |
+----------+--------+
|
+----------v--------+
| max ← A[1] |
+----------+--------+
|
+----------v-------------------+
| i ← 2 |
+----------+-------------------+
|
+----------v-------------------+
| i ≤ n ? --------------------+--- No --->+-----------------+
+----------+-------------------+ | Output max |
| Yes +-----+
+----------v-------------------+
| A[i] > max ? ---------------+--- Yes -->+-----------------+
+----------+-------------------+ | max ← A[i] |
| No +-----+
+----------v-------------------+
| i ← i + 1 |
+----------+-------------------+
|
+----------v-------------------+
| Repeat loop (back to i ≤ n) |
+------------------------------+
Useful for concise description of well‑known algorithms.
gcd(a, b) =
a if b = 0
gcd(b, a mod b) otherwise
Complexity: Time = O(n), Space = O(1).
INPUT: sorted array L[1..n], target xlow ← 1
high ← n
WHILE low ≤ high DO
mid ← ⌊(low + high) / 2⌋
IF L[mid] = x THEN
OUTPUT mid
STOP
ELSE IF L[mid] < x THEN
low ← mid + 1
ELSE
high ← mid - 1
END IF
END WHILE
OUTPUT “not found”
Complexity: Time = O(log n), Space = O(1).
| Algorithm | Time (Big‑O) | Space (Big‑O) | Typical exam comment |
|---|---|---|---|
| Linear search | O(n) | O(1) | Best‑case O(1) if first element matches; worst‑case O(n). |
| Binary search | O(log n) | O(1) | Requires the list to be sorted – a point to mention for correctness. |
| Maximum in an array (single pass) | O(n) | O(1) | Only one loop, no extra data structures. |
Your generous donation helps us continue providing free Cambridge IGCSE & A-Level resources, past papers, syllabus notes, revision questions, and high-quality online tutoring to students across Kenya.