An algorithm is a finite, well‑defined set of instructions that solves a problem or performs a computation. Every algorithm must be:
Cambridge AS & A‑Level expects you to show how an algorithm is developed from a high‑level idea to detailed pseudocode.
During refinement you repeatedly use the three basic constructs (sequence, decision, iteration) and, where appropriate, recursion.
| Construct | Purpose | Pseudocode Pattern |
|---|---|---|
| Sequence | Execute statements one after another. | READ a READ b SET sum ← a + b WRITE sum |
| Decision (Selection) | Choose between alternative paths. | IF a > b THEN
SET max ← a
ELSE
SET max ← b
ENDIF |
| Iteration (Repetition) | Repeat a block of statements while a condition holds. | SET i ← 1
WHILE i ≤ n DO
WRITE i
SET i ← i + 1
ENDWHILE |
| Recursion | A procedure calls itself to solve a smaller instance of the same problem. | FUNCTION factorial(n)
IF n = 0 THEN
RETURN 1
ELSE
RETURN n * factorial(n‑1)
ENDIF
ENDFUNCTION |
IF, WHILE, ENDWHILE).READ/WRITE (or INPUT/OUTPUT).Given a radius r, compute the area $A = \pi r^2$.
READ r SET A ← 3.14159 * r * r WRITE "Area =", A
Assign a grade based on a mark m (0–100).
READ m
IF m ≥ 80 THEN
SET grade ← 'A'
ELSE IF m ≥ 70 THEN
SET grade ← 'B'
ELSE IF m ≥ 60 THEN
SET grade ← 'C'
ELSE IF m ≥ 50 THEN
SET grade ← 'D'
ELSE
SET grade ← 'F'
ENDIF
WRITE "Grade:", grade
Calculate $S = 1 + 2 + \dots + n$.
READ n
SET i ← 1
SET S ← 0
WHILE i ≤ n DO
SET S ← S + i
SET i ← i + 1
ENDWHILE
WRITE "Sum =", S
Given n integers stored in an array $A[1..n]$, determine the maximum value.
READ n
FOR i ← 1 TO n DO
READ A[i]
ENDFOR
SET max ← A[1]
FOR i ← 2 TO n DO
IF A[i] > max THEN
SET max ← A[i]
ENDIF
ENDFOR
WRITE "Maximum =", max
READ n // size of the array
FOR i ← 1 TO n DO
READ A[i]
ENDFOR
READ key // value to find
SET found ← FALSE
FOR i ← 1 TO n DO
IF A[i] = key THEN
SET found ← TRUE
EXITFOR
ENDIF
ENDFOR
IF found THEN
WRITE "Key found at position", i
ELSE
WRITE "Key not present"
ENDIF
When to use: Small or unsorted data sets where simplicity is more important than speed.
READ n
FOR i ← 1 TO n DO
READ A[i] // assume A is sorted in ascending order
ENDFOR
READ key
SET low ← 1
SET high ← n
SET found ← FALSE
WHILE low ≤ high DO
SET mid ← (low + high) DIV 2
IF A[mid] = key THEN
SET found ← TRUE
EXITWHILE
ELSE IF A[mid] < key THEN
SET low ← mid + 1
ELSE
SET high ← mid - 1
ENDIF
ENDWHILE
IF found THEN
WRITE "Key found at position", mid
ELSE
WRITE "Key not present"
ENDIF
When to use: Large, sorted data sets – runs in $O(\log n)$ time.
READ n
FOR i ← 1 TO n DO
READ A[i]
ENDFOR
FOR i ← 2 TO n DO
SET key ← A[i]
SET j ← i - 1
WHILE j ≥ 1 AND A[j] > key DO
SET A[j+1] ← A[j]
SET j ← j - 1
ENDWHILE
SET A[j+1] ← key
ENDFOR
WRITE "Sorted array:"
FOR i ← 1 TO n DO
WRITE A[i]
ENDFOR
READ n
FOR i ← 1 TO n DO
READ A[i]
ENDFOR
FOR i ← 1 TO n-1 DO
FOR j ← 1 TO n-i DO
IF A[j] > A[j+1] THEN
SET temp ← A[j]
SET A[j] ← A[j+1]
SET A[j+1] ← temp
ENDIF
ENDFOR
ENDFOR
WRITE "Sorted array:"
FOR i ← 1 TO n DO
WRITE A[i]
ENDFOR
Both algorithms have a worst‑case time‑complexity of $O(n^2)$. They are acceptable for small data sets or when teaching basic concepts.
FUNCTION factorial(n)
IF n = 0 THEN
RETURN 1
ELSE
RETURN n * factorial(n‑1)
ENDIF
ENDFUNCTION
READ n
SET result ← factorial(n)
WRITE "n! =", result
Recursion replaces explicit loops with self‑reference. The algorithm must have a base case (here, $n=0$) to guarantee termination.
Assume a graph is represented by an adjacency list Adj[1..V]. The algorithm visits all vertices reachable from a start vertex s.
READ V // number of vertices
FOR i ← 1 TO V DO
READ Adj[i] // list of neighbours for vertex i
ENDFOR
READ s // start vertex
CREATE empty STACK S
CREATE array visited[1..V] ← FALSE
PUSH S, s
SET visited[s] ← TRUE
WHILE S is not empty DO
POP S, v
WRITE "Visit", v
FOR each w in Adj[v] DO
IF NOT visited[w] THEN
PUSH S, w
SET visited[w] ← TRUE
ENDIF
ENDFOR
ENDWHILE
| Unit | Topic (as in the syllabus) | Notes Covered in This Document | Paper(s) & AO(s) |
|---|---|---|---|
| 1 | Data Representation – Binary, Hexadecimal, Character Sets, Image & Sound, Compression | Binary/hex basics, ASCII/Unicode, RLE, JPEG & MP3 concepts (see §6.1) | Paper 1 (AO1), Paper 2 (AO2) |
| 2 | Computer Systems – Architecture, CPU, Memory, Storage, Networks | Brief overview of architecture and network layers (see §6.2) | Paper 1 (AO1) |
| 3 | Software Development – Algorithms, Pseudocode, Flowcharts, Testing | All of §§1‑5, §8, §9 (full algorithm design cycle) | Paper 1 (AO1‑AO3), Paper 2 (AO2‑AO3) |
| 4 | Databases – Data Modelling, SQL, Normalisation | Entity‑relationship basics and SELECT/INSERT examples (see §6.3) | Paper 1 (AO1‑AO2) |
| 5 | Web Development – HTML, CSS, Client‑Server Model, Security | HTML form skeleton, basic CSS, HTTPS overview (see §6.4) | Paper 1 (AO1‑AO2) |
| 6 | Security – Threats, Counter‑measures, Cryptography | Symmetric/asymmetric encryption, hashing, SSL/TLS, quantum‑cryptography note (see §6.5) | Paper 1 (AO1‑AO2) |
| 7 | Ethics, Professionalism, Ownership, Licensing | Professional bodies, open‑source vs. proprietary licences, ethical decision‑tree (see §6.6) | Paper 1 (AO1‑AO2) |
| 8 | Data Structures – Arrays, Lists, Stacks, Queues, Trees, Graphs | Array, stack (DFS), queue example, binary tree traversal (see §5.8) | Paper 1 (AO1‑AO2) |
| 9 | Algorithms – Searching, Sorting, Recursive & Iterative Solutions | Linear & binary search, insertion & bubble sort, factorial recursion (see §5) | Paper 1 (AO1‑AO3), Paper 2 (AO2‑AO3) |
| 10 | Programming – Structured Programming, OOP concepts, Error handling | Structured pseudocode, brief OOP overview, try‑catch pattern (see §6.7) | Paper 1 (AO1‑AO2), Paper 2 (AO2‑AO3) |
| 11 | Systems Development – SDLC, Project Management, Documentation | Stepwise refinement, trace tables, risk register example (see §6.8) | Paper 2 (AO2‑AO3) |
| 12 | Emerging Technologies – AI, Virtual Machines, Parallel Processing | Search‑tree AI, basic VM model, multi‑core parallelism (see §6.9) | Paper 2 (AO2‑AO3) |
| 13‑20 | A‑Level extensions (Advanced Data Representation, Advanced Algorithms, AI, etc.) | Compressed image/audio formats, advanced sorting (merge‑sort), neural‑net basics, exception handling, concurrency primitives (see §6.10‑6.13) | Paper 3 (AO1‑AO3) |
SELECT name FROM Students WHERE grade = 'A';Vehicle class).TRY
… statements …
CATCH error
WRITE "Error:", error
ENDTRY| Criterion | What to Consider | Typical Measure |
|---|---|---|
| Time‑complexity | Number of elementary operations as the input size grows. | Big‑O notation (e.g., $O(n)$, $O(n^2)$, $O(\log n)$). |
| Space‑complexity | Extra memory required beyond the input. | $O(1)$, $O(n)$, etc. |
| Readability & Maintainability | Clear structure, meaningful names, consistent indentation. | Qualitative – judged by peer review or examiner marking. |
| Scalability | How performance changes as data size increases. | Derived from time‑ and space‑complexity. |
Use the sorting and searching examples to compare efficiencies: linear search $O(n)$ vs. binary search $O(\log n)$; insertion sort $O(n^2)$ vs. merge sort $O(n\log n)$ (the latter appears in the A‑Level unit).
n.n values and accumulate their sum.n to obtain the average.READ n
SET total ← 0
FOR i ← 1 TO n DO
READ x
SET total ← total + x
ENDFOR
IF n = 0 THEN
WRITE "No data"
ELSE
SET avg ← total / n
WRITE "Average =", avg
ENDIF
n = 0, n = 1, maximum allowed size).= instead of == or <=).n = 0 or empty input.DIV) with real division (/) in pseudocode.Create an account or Login to take a Quiz
Log in to suggest improvements to this note.
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.