Following and writing algorithms — AQA A-Level Computer Science
Following and writing algorithms in AQA A-Level Computer Science involves tracing execution flow using trace tables and designing precise pseudocode or flowchart solutions to complex computational problems. Mastering this topic ensures students can rigorously verify variable states, avoid off-by-one errors, and formulate efficient search, sort, and traversal routines.
Following and writing algorithms explained
This statement asks you to explain, in your own words, what a program does step by step, and then to justify two claims about it: that it is correct and that it is efficient.
Read the full explanation
Correctness means the program produces the right output for valid inputs, including edge cases. You support that claim with logical reasoning, such as tracing the algorithm through a loop invariant or by walking through each branch, and with test data chosen to cover typical, boundary and invalid inputs. Efficiency means how the resources the program uses, such as time and memory, grow as the input grows. You argue for efficiency by reasoning about how many steps the algorithm performs relative to input size, for example noting that a single pass through a list of n items is linear while nested loops over the same list are quadratic.
Your focus
- Be able to articulate how a program works, arguing for its correctness and its efficiency using logical reasoning, test data and user
Which command word is this?
Follow the execution of an algorithm step-by-step, recording all changes to variable values and outputting results in a trace table without skipping intermediate states.
Following and writing algorithms exam tips
Topic Overview
Following and writing algorithms forms the computational backbone of AQA A-Level Computer Science. It assesses a student's ability to interpret, trace, debug, and construct algorithmic logic across standard paradigms, including sequence, selection, iteration, and recursion.
This topic connects directly to theoretical complexity, data structures, and practical programming. Students must be capable of representing solutions clearly using structured pseudocode or flowcharts, ensuring boundary conditions and corner cases are handled robustly.
Key Concepts
- →Trace Tables: Tabular tracking of dry-run variable states and boolean conditions across distinct iterations.
- →Standard Algorithmic Paradigms: Systematic design of linear searches, binary searches, bubble sorts, insertion sorts, and recursive tree/graph traversals.
- →Control Structures: Precise use of definite iteration (FOR), indefinite iteration (WHILE / REPEAT UNTIL), and nested branching (IF-THEN-ELSE).
- →Preconditions, Postconditions, and Invariants: Logical statements defining what must be true before, during, and after algorithm execution to prove correctness.
Marking Points
- Explains the program's purpose and the sequence of steps it performs, not just the code's surface syntax
- Justifies correctness by reasoning through the algorithm on representative inputs or with a loop invariant
- Selects test data that covers normal, boundary and invalid cases, and states the expected result for each
- Argues efficiency by describing how time or memory use grows with input size
- Distinguishes between the logic that makes a program correct and the performance that makes it efficient
- Uses precise terminology such as iteration, branch, invariant and complexity in a coherent explanation
Examiner Tips
- 💡Structure your explanation as: purpose, then how it works, then correctness argument, then efficiency argument
- 💡When choosing test data, name the category of each test (normal, boundary, erroneous) and give the expected output
- 💡Use the terms linear and quadratic only when you can justify them from the loop structure
- 💡Keep correctness and efficiency as separate arguments so each is clearly evidenced
- 💡Always specify array dimensions and base indices (0 or 1) clearly if not provided in the exam prompt.
- 💡When asked to write pseudocode, use standard constructs rather than language-specific syntax shortcuts like Python slice notation or list comprehensions.
- 💡Dry-run your own written pseudocode with extreme boundary values (e.g., empty array, target at first position, target at final position) before considering your answer finished.
Common Mistakes
- Describes only what a line of code does rather than the overall behaviour of the program; explain the purpose of the algorithm as a whole
- Claims a program is correct because it runs without errors; a program can run without crashing and still give wrong answers, so test against expected outputs
- Chooses only typical test data; include boundary values and invalid inputs as well
- Asserts efficiency by saying a program is fast; justify it by reasoning about how the number of operations grows with input size
- Assuming trace table rows represent whole lines of code rather than discrete state changes, causing students to bundle multiple iterations together.
- Confusing loop termination boundaries, particularly off-by-one errors (e.g., using '<=' instead of '<' when indexing 0-indexed arrays).
- Failing to implement an early exit mechanism in search algorithms, leading to suboptimal algorithmic execution that does not meet specification requirements.
Revision Plan
- 1Day 1-3: Practice dry-running complex loops and recursive subroutines using trace tables, verifying every variable mutation on past paper mark schemes.
- 2Day 4-6: Memorise and write from scratch the core algorithms: Bubble Sort, Insertion Sort, Binary Search, and Linear Search in standard pseudocode.
- 3Day 7-9: Implement abstract data structure operations in pseudocode (push/pop for stacks, enqueue/dequeue for queues, linked list insertion).
- 4Day 10-12: Solve timed past-paper Paper 1 and Paper 2 algorithmic design questions (6-mark and 9-mark questions) without an IDE.
Exam Question Types
- 📋Trace Table Completion: Populating a pre-drawn grid to track variables through nested loops, string manipulations, or recursive calls.
- 📋Pseudocode Design: Writing a complete subroutine from a textual specification, adhering to constraints such as optimal time efficiency or early termination.
- 📋Algorithm Correction / Refactoring: Identifying logical or syntax errors in an existing algorithm snippet and providing the corrected lines.
Command Word Expectations (AQA)
Follow the execution of an algorithm step-by-step, recording all changes to variable values and outputting results in a trace table without skipping intermediate states.
Produce syntactically valid pseudocode or high-level code that completely implements the given functional requirements, including parameter passing and return values.
Set out the operational stages of an algorithm, detailing how data is modified, compared, or moved to achieve its final outcome.
How Students Lose Marks (Examiner Pitfalls)
Step-by-Step Worked Solutions
Question: Trace the following recursive algorithm for mystery(3, 2): function mystery(a, b) if b == 0 then return 1 else return a * mystery(a, b - 1) endif endfunction
- 1.Step 1: Identify call stack frame 1: mystery(3, 2). Condition (b == 0) evaluates to False (2 != 0). Returns 3 * mystery(3, 1).
- 2.Step 2: Identify call stack frame 2: mystery(3, 1). Condition (b == 0) evaluates to False (1 != 0). Returns 3 * mystery(3, 0).
- 3.Step 3: Identify call stack frame 3 (base case): mystery(3, 0). Condition (b == 0) evaluates to True. Returns 1.
- 4.Step 4: Unwind the stack: frame 2 computes 3 * 1 = 3. Frame 1 computes 3 * 3 = 9.
Question: Write an algorithm in pseudocode that performs a linear search on a 1D array named 'scores' containing 'n' integer elements to find a target value 'target'. The algorithm must return the index of the target if found, or -1 if the target is not present. It must stop searching immediately once found.
- 1.Step 1: Initialise a tracking variable 'index' to 0 and a boolean flag 'found' to False.
- 2.Step 2: Set up a while loop with condition (index < n AND found == False) to avoid redundant iterations.
- 3.Step 3: Inside the loop, check if scores[index] == target. If True, set found to True; else, increment index by 1.
- 4.Step 4: After loop termination, check if found is True: return index; else return -1.