Revision Notes
OxfordAQA A-Level Computer Science (9645): Following and writing algorithms – Revision Notes
Recall notes for OxfordAQA 9645 sub-topic 3.3.3: the definition of an algorithm, reading pseudocode, converting it to code, trace tables and a self-test.
- Subject
- Computer Science
- Level
- AS LEVEL
- Topic
- Topic 3 – Program design
- Author
- Marlbridge Academic Team
- Updated
- Reviewed by
- Harris Khan (what this means)
Aligned to OxfordAQA A Level Computer Science (9645), 2024-onwards. Official specification .
Syllabus page (what it covers and how it is assessed): OxfordAQA A Level Computer Science.
Syllabus points this page covers
9645 (AS Level)
- 3.3.3 Following and writing algorithms
This page covers 1 of the 4 subtopics in topic 3, Program design.
Found an error? Report a correction.
Need help with this topic? Request a free trial class for A Level Computer Science (9645).
These notes condense sub-topic 3.3.3 Following and writing algorithms of OxfordAQA International AS and A-level Computer Science (9645), Version 1.1 (AS content in topic 3.3 Program design). For full worked traces, see the following and writing algorithms study guide; then practise with the following and writing algorithms practice questions.
What the specification requires
- Understand the term algorithm: a sequence of steps that can be followed to complete a task and that always terminates.
- Be familiar with pseudocode to express algorithms. You must understand pseudocode, but you will not be expected to write it in the exam.
- Convert an algorithm from pseudocode into high-level language program code.
- Hand-trace algorithms.
Key terms
| Term | Meaning |
|---|---|
| Algorithm | A sequence of steps that completes a task and always terminates |
| Pseudocode | Structured, English-like description of an algorithm, not tied to a language |
| Terminates | Finishes after a finite number of steps for every valid input |
| Trace table | A table of variable values recorded step by step |
| Hand-trace | Following an algorithm by hand with given data |
| DIV | Integer division (quotient only) |
| MOD | The remainder after integer division |
Notation used in these notes
← assignment, = comparison, <> not equal, upper-case keywords, indexes from 0. The specification sets no pseudocode style of its own.
Three features of an algorithm
- Steps in a fixed order.
- Each step is clear enough to follow without guessing.
- It always terminates.
A loop whose condition can never become false is not an algorithm. n ← 10; WHILE n <> 0: n ← n - 3 gives 10, 7, 4, 1, −2 and never reaches 0.
How to hand-trace
- Write one column per variable, plus one for output or conditions.
- Fill the starting values in the first row.
- Follow statements in order, one at a time.
- Add a row when a value changes; carry unchanged values down.
- Check the loop condition after every pass.
- Stop only when the algorithm ends or returns.
Worked reminders
Greatest common divisor (84, 36)
WHILE b <> 0
t ← b
b ← a MOD b
a ← t
ENDWHILE
RETURN a
| Step | a | b | t |
|---|---|---|---|
| Start | 84 | 36 | |
| Pass 1 | 36 | 12 | 36 |
| Pass 2 | 12 | 0 | 12 |
Returns 12. b shrinks each pass, so the loop terminates.
Prime test (21)
| i | i * i | 21 MOD i | Result |
|---|---|---|---|
| 2 | 4 | 1 | continue |
| 3 | 9 | 0 | return False |
For 29, the values 2 to 5 leave remainders 1, 2, 1 and 4; at i = 6, 36 exceeds 29, so it returns True.
Count digits of 7305
| Pass | n after | count |
|---|---|---|
| 1 | 730 | 1 |
| 2 | 73 | 2 |
| 3 | 7 | 3 |
| 4 | 0 | 4 |
Pseudocode to Python
| Pseudocode | Python |
|---|---|
x ← 5 |
x = 5 |
IF x = 5 THEN |
if x == 5: |
a DIV b |
a // b |
a MOD b |
a % b |
<> |
!= |
WHILE cond ... ENDWHILE |
while cond: |
FOR EACH ch IN text |
for ch in text: |
RETURN x |
return x |
Keep the structure and order of statements. Change only syntax.
def count_digits(n):
count = 0
while n > 0:
n = n // 10
count = count + 1
return count
count_digits(7305) returns 4. For an input of 0 it returns 0, although 0 has one digit, so check special cases such as 0 when you trace.
Trace table template
Use one column for each variable, one for any condition you test, and one for output. For IsPrime(29) the trace is as follows (recomputed).
| i | i * i | i * i <= 29 | 29 MOD i | Action |
|---|---|---|---|---|
| 2 | 4 | true | 1 | continue |
| 3 | 9 | true | 2 | continue |
| 4 | 16 | true | 1 | continue |
| 5 | 25 | true | 4 | continue |
| 6 | 36 | false | loop ends; return True |
Rules that save marks: write the starting values in the first row, change only one variable per row where possible, and write the condition result so that the reader can see why the loop stops.
Exam traps
- Updating in the wrong order (for example using the new
atoo early in Gcd). - Skipping a row because the answer seems obvious.
- Off-by-one in conditions (
<against<=). =meaning two things. In pseudocode it often means comparison; in Python it is assignment.- Stopping the trace early. Complete the algorithm, including the final return or output.
- Not showing termination. Point to a value that moves towards the stopping condition.
Quick self-test
- Define algorithm.
- What does “always terminates” mean?
- Must you write pseudocode in the exam?
- State what 47 MOD 5 and 47 DIV 5 give.
- Give the output of this:
x ← 1; WHILE x < 50: x ← x * 3; OUTPUT x. - Trace Gcd(84, 36). What is returned?
- How many passes does the digit-count loop make for 7305?
- What is the Python version of
a MOD b? - Why does
n ← n - 3starting at 10 withWHILE n <> 0never end? - Name two things a trace table records.
- In the reverse-string algorithm, why is
result ← ch + resultused rather thanresult + ch? - When converting pseudocode, what should stay the same?
Answers
- A sequence of steps that can be followed to complete a task and that always terminates.
- It finishes after a finite number of steps for every valid input.
- No, you must understand it but not write it.
- 2 and 9.
-
- The values are 3, 9, 27, 81, and then the loop stops.
-
-
a % b- The values 10, 7, 4, 1, −2 skip over 0.
- Variable values (and conditions or output).
- Putting the new character first reverses the order.
- The structure and the order of the statements.
- Following and writing algorithms study guide
- Following and writing algorithms practice questions
- Searching and sorting algorithms revision notes
Official syllabus
OxfordAQA International AS and A-level Computer Science (9645) specification, Version 1.1, for International AS exams May/June 2025 onwards and International A-level exams May/June 2026 onwards: sub-topic 3.3.3 Following and writing algorithms.
Related resources
-
Study guides
OxfordAQA A-Level Computer Science (9645): Structured approach to programming
OxfordAQA 9645 sub-topic 3.3.1 in depth: modularised programming, parameters, return values, local variables, advantages and drawing hierarchy and structure charts.
Computer Science · OxfordAQA · AS Level
Read guide -
Practice questions
OxfordAQA A-Level Computer Science (9645): Structured approach to programming – Practice Questions
Ten original OxfordAQA 9645 questions on sub-topic 3.3.1: modular design, parameters, return values, local variables and hierarchy and structure charts.
Computer Science · OxfordAQA · AS Level
Try questions -
Revision notes
OxfordAQA A-Level Computer Science (9645): Structured approach to programming – Revision Notes
Recall notes for OxfordAQA 9645 sub-topic 3.3.1: modularisation, parameters and return values, local variables, advantages, hierarchy and structure charts.
Computer Science · OxfordAQA · AS Level
Revise topic
Get free revision emails (optional)
Occasional emails with practice questions, worked explanations and links to free resources for the qualification and subjects you choose. No spam, and you can unsubscribe from any email. The free tools on this site never need an email.