Revision Notes
OxfordAQA A-Level Computer Science: Advanced algorithms (9645) – Revision Notes
Condensed revision notes on graph searches, Dijkstra's algorithm and tree traversals for OxfordAQA A-level Computer Science, with a quick self-test.
- Subject
- Computer Science
- Level
- A LEVEL
- Topic
- Advanced algorithms
- Author
- Marlbridge Academic Team
- Updated
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 (A Level)
- 11 Advanced algorithms (whole topic)
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 the advanced algorithms study guide, which has the full explanations and longer worked examples. They cover sections 3.11.1 Graph algorithms and 3.11.2 Tree algorithms from the OxfordAQA 9645 specification (International AS and A-level Computer Science, Version 1.1), which is used for International AS exams in May/June 2025 onwards and International A-level exams in May/June 2026 onwards. Section 3.11 sits entirely in the International A-level, examined in Unit 3: Advanced Programming, the on-screen paper in C#, Python or VB.Net.
When you can answer the self-test below without looking, move on to the practice questions. Use the printable checklist to tick off outcomes, the course hub for other topics, and a free 10-minute diagnostic to find weak spots. Graph and tree terms are in the advanced data structures notes.
Code fragments are Python, since the specification defines no pseudo-code standard. Neighbours are taken in alphabetical order unless a question says otherwise.
Key terms
| Term | Meaning |
|---|---|
| Breadth-first search (BFS) | Visits vertices layer by layer outwards from the start; uses a queue |
| Depth-first search (DFS) | Follows one branch as far as possible, then backtracks; uses a stack (or recursion) |
| Backtracking | Returning to the most recent vertex that still has an unvisited neighbour |
| Dijkstra’s algorithm | Finds the shortest (lowest total weight) route from one vertex to all others in a weighted graph |
| Tree traversal | Visiting every node of a binary tree exactly once in a set order |
| Expression tree | Binary tree with operators at internal nodes and operands at leaves |
| Prefix / postfix | Operator written before / after its two operands; neither needs brackets |
3.11.1 Graph algorithms
BFS compared with DFS
| BFS | DFS | |
|---|---|---|
| Data structure | Queue (FIFO) | Stack (LIFO) or recursion |
| Order | Nearest vertices first | Deepest first, then backtrack |
| Typical application (specification) | Shortest path in an unweighted graph | Navigating a maze |
| Gives the fewest-edge route? | Yes | Not guaranteed |
Method: BFS
- Mark the start visited; enqueue it.
- Dequeue the front vertex and output it.
- Enqueue each of its unvisited neighbours, marking each visited and noting its parent.
- Repeat from step 2 until the queue is empty.
Method: DFS (recursive)
- Mark the current vertex visited and output it.
- For each unvisited neighbour in turn, call DFS on it.
- When none are left, the call ends: this is the backtrack.
Worked reminder. Edges C–F, C–J, F–M, J–M, M–T.
- BFS from C: queue goes [F, J] → [J, M] → [M] → [T] → empty. Order C, F, J, M, T.
- DFS from C: C → F → M (M’s first unvisited neighbour is J) → J, dead end, back to M → T. Order C, F, M, J, T.
Code shape. The two loop versions differ in one line: BFS removes from the front (queue.pop(0) or deque.popleft()), DFS removes from the end (stack.pop()).
def bfs_order(graph, start):
seen, queue = [start], [start]
while queue:
v = queue.pop(0)
for n in graph[v]:
if n not in seen:
seen.append(n)
queue.append(n)
return seen
Dijkstra’s shortest path algorithm
You must be able to trace it. You are not expected to recall its steps or code it unless the question paper gives you the algorithm.
Method: Dijkstra trace
- Start vertex 0; all others ∞.
- Pick the unvisited vertex with the smallest total distance; its distance is now final.
- For each unvisited neighbour: if (distance of picked vertex + edge weight) < neighbour’s current distance, update it and record the picked vertex as its previous vertex.
- Repeat until all vertices are final. Read a route by following previous vertices back from the target, then reversing.
Worked reminder. Edges P–R 7, P–T 2, T–R 3, R–V 1, T–V 8; start P.
| Picked | P | R | T | V |
|---|---|---|---|---|
| P (0) | 0 | 7 (P) | 2 (P) | ∞ |
| T (2) | 5 (T) | 2 | 10 (T) | |
| R (5) | 5 | 6 (R) | ||
| V (6) | 6 |
Route to V: V ← R ← T ← P, so P → T → R → V, total 6. Notice R’s distance dropped from 7 to 5, and V’s from 10 to 6: a vertex’s value can change several times before it is picked.
Applications: satellite navigation and route planners; routing data across networks (link-state routing protocols such as OSPF use it); any problem where edge weights are costs, times or distances to minimise.
Why not BFS for weighted graphs? BFS counts edges and ignores weights, so a route with fewer edges can still cost more.
3.11.2 Tree algorithms
| Traversal | Order | Uses in the specification |
|---|---|---|
| Pre-order | Node, left, right | Copying a tree; prefix expression from an expression tree |
| In-order | Left, node, right | Binary search tree: output contents in ascending order |
| Post-order | Left, right, node | Postfix expression from an expression tree; emptying a tree |
Left is always visited before right. The only change between the three is when the node itself is output.
Worked reminder: binary search tree. Inserting 33, 18, 50, 9, 27, 61:
33
/ \
18 50
/ \ \
9 27 61
- Pre-order: 33, 18, 9, 27, 50, 61
- In-order: 9, 18, 27, 33, 50, 61 (ascending, because it is a BST)
- Post-order: 9, 27, 18, 61, 50, 33
Worked reminder: expression tree for x − y × (z + w). Root −, left child x, right child × (whose children are y and +, and + has children z and w).
- Prefix (pre-order):
− x × y + z w - Postfix (post-order):
x y z w + × −
Why these uses? Pre-order creates a parent before its children, so a copy can be built top-down. Post-order deals with both children before their parent, so emptying never deletes a node that still links to undeleted children.
Implementation pattern. A recursive subroutine with base case “node is empty: do nothing” and two recursive calls (left subtree, then right subtree); the output line goes before, between or after those calls.
Must-know distinctions
- Queue vs stack: BFS = queue; DFS = stack.
- Fewest edges vs lowest weight: BFS finds the first; Dijkstra finds the second.
- Visit order vs route: the BFS visit order is not a route. Build the route from the parent (or previous-vertex) records.
- In-order vs sorted: in-order gives ascending order only for a binary search tree.
- Prefix vs postfix: pre-order → prefix; post-order → postfix.
Quick self-test
- Which data structure does BFS use, and which does DFS use?
- Edges G–L, G–N, L–P, N–P, N–R, P–V. Give the BFS order from G.
- For the same graph, give the DFS order from G.
- Using BFS parents, give the fewest-edge route from G to V.
- Edges A–B 5, A–C 1, C–B 2. Give the shortest distance and route from A to B.
- Why would BFS give the wrong answer to question 5?
- A tree has root 5. Its left child 8 has children 1 (left) and 6 (right). Its right child 3 has only a right child, 7. Give all three traversals.
- Evaluate the postfix expression
6 2 3 + × 4 −. - Which traversal empties a tree, and why?
- Which traversal produces a prefix expression from an expression tree?
- State the base case of a recursive traversal.
- Give the typical application of DFS named in the specification.
Answers
- BFS: queue. DFS: stack (or the call stack, if recursive).
- G, L, N, P, R, V.
- G, L, P, N, R, V. From P, the first unvisited neighbour is N, then from N go to R; backtrack to P for V.
- G → L → P → V (P was discovered from L, V from P).
- 3, by A → C → B (1 + 2), beating the direct edge of 5.
- BFS finds the fewest edges, A → B (one edge, weight 5), and ignores the weights.
- Pre-order 5, 8, 1, 6, 3, 7; in-order 1, 8, 6, 5, 3, 7; post-order 1, 6, 8, 7, 3, 5.
- 2 + 3 = 5; 6 × 5 = 30; 30 − 4 = 26.
- Post-order: both subtrees are deleted before their parent, so no node is deleted while it still links to children.
- Pre-order.
- The node (subtree) is empty, so the subroutine returns without doing anything.
- Navigating a maze.
Where marks are usually lost
- Swapping queue and stack between BFS and DFS.
- Not following the neighbour order stated in the question, which changes the whole trace.
- In BFS, marking a vertex visited only when it leaves the queue, so it gets queued twice.
- Giving the BFS visit order when the question asks for a route.
- In Dijkstra, choosing the next vertex by the smallest single edge rather than the smallest total distance.
- Updating a vertex that is already final in Dijkstra.
- Not showing the distance table or previous vertices when asked to trace: the final answer alone shows no method.
- Visiting right before left in a traversal.
- Claiming in-order gives ascending output for any binary tree.
- Mixing up which traversal gives prefix and which gives postfix.
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, published by OxfordAQA: section 3.11 Advanced algorithms.
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.
Related resources
-
Study guides
OxfordAQA A-Level Computer Science: Advanced algorithms (9645)
Study guide to OxfordAQA A-level Computer Science topic 11: breadth-first, depth-first and Dijkstra traces, tree traversals and their uses.
Computer Science · OxfordAQA · A Level
Read guide -
Practice questions
OxfordAQA A-Level Computer Science: Advanced algorithms (9645) – Practice Questions
Original questions with marked answers on BFS, DFS, Dijkstra traces and tree traversals for OxfordAQA International A-level Computer Science.
Computer Science · OxfordAQA · A Level
Try questions -
Study guides
OxfordAQA A-Level Computer Science: Advanced data structures (9645)
Study guide to OxfordAQA International A-level Computer Science topic 10: graphs, trees, hash tables, priority queues and dictionaries, worked through.
Computer Science · OxfordAQA · A Level
Read guide
Related articles
-
teaching
A Level tuition in Dubai: Cambridge or Pearson Edexcel International A Level?
Schools in Dubai and Abu Dhabi teach either Cambridge International AS & A Level or Pearson Edexcel International A Level. How the two are structured, why it matters for tuition, and how online classes from Lahore work.
9 October 2026
-
curriculum guides
Choosing subjects at IGCSE and A Level
How subject choices at 14 and 16 affect university options later, and how to keep pathways open without overloading a timetable.
28 July 2026
Studying this with a teacher
Working through Computer Science A LEVEL?
This page is free and stays free. If you would rather be taught it, Marlbridge runs Computer Science classes one-to-one and in small groups of up to 15, online in your own time zone. The first trial class is free. WhatsApp replies within an hour (8am–11pm Pakistan time, every day); email the same day.
OxfordAQA Computer Science teachers at Marlbridge