Skip to topic
    ← Back to course topics

    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

    1. 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
    1. 1Day 1-3: Practice dry-running complex loops and recursive subroutines using trace tables, verifying every variable mutation on past paper mark schemes.
    2. 2Day 4-6: Memorise and write from scratch the core algorithms: Bubble Sort, Insertion Sort, Binary Search, and Linear Search in standard pseudocode.
    3. 3Day 7-9: Implement abstract data structure operations in pseudocode (push/pop for stacks, enqueue/dequeue for queues, linked list insertion).
    4. 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)
    Trace

    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.

    Write

    Produce syntactically valid pseudocode or high-level code that completely implements the given functional requirements, including parameter passing and return values.

    Explain

    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)
    Pitfall: Mixing up 0-based and 1-based indexing when tracing loops or writing pseudocode array access routines.
    ❌ Weak Answer (Loses Marks):The algorithm loops through the array from 1 to length and compares items, swapping them if needed.
    Example improved answer:For an array of size n with indices 0 to n - 1, the outer loop executes from i = 0 to n - 2, and the inner loop executes from j = 0 to n - i - 2, comparing array[j] with array[j + 1] and swapping if array[j] > array[j + 1].
    Examiner Tip: Explicitly state loop bounds and use strict array indexing consistent with the question prompt or AQA standard pseudocode.
    Pitfall: Updating multiple variables on a single row in a trace table rather than creating a new row for each state change.
    ❌ Weak Answer (Loses Marks):Students fill in values across multiple columns in one single row even when iterations change variable values sequentially.
    Example improved answer:Only write a value in a column when that specific variable changes its value; leave unchanged columns blank on that row, and drop to a new line whenever a loop restarts or a step alters state.
    Examiner Tip: Never overwrite or cram multiple values into a single trace table cell. Each state mutation warrants its own row.
    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. 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. 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. 3.Step 3: Identify call stack frame 3 (base case): mystery(3, 0). Condition (b == 0) evaluates to True. Returns 1.
    4. 4.Step 4: Unwind the stack: frame 2 computes 3 * 1 = 3. Frame 1 computes 3 * 3 = 9.
    Final Answer: mystery(3, 2) evaluates to 9 (computing a^b, i.e., 3^2 = 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. 1.Step 1: Initialise a tracking variable 'index' to 0 and a boolean flag 'found' to False.
    2. 2.Step 2: Set up a while loop with condition (index < n AND found == False) to avoid redundant iterations.
    3. 3.Step 3: Inside the loop, check if scores[index] == target. If True, set found to True; else, increment index by 1.
    4. 4.Step 4: After loop termination, check if found is True: return index; else return -1.
    Final Answer: function linearSearch(scores, n, target) index = 0 while index < n if scores[index] == target then return index endif index = index + 1 endwhile return -1 endfunction
    Active Recall Memory Test
    What is the primary difference between a pre-condition loop (WHILE) and a post-condition loop (REPEAT UNTIL)?
    Key Fact: A pre-condition loop tests its condition before executing and may execute zero times; a post-condition loop executes at least once before testing the condition.
    In a trace table, when should a student leave a column cell blank?
    Key Fact: When the value of that specific variable has not changed during that operational step.
    What is an off-by-one error, and how does it typically arise in array algorithms?
    Key Fact: A boundary error where a loop iterates one time too many or too few, commonly caused by confusing '<' with '<=' or using 1-based size on a 0-based array.
    Frequently Asked Questions
    Can I use Python syntax instead of pseudocode in AQA exams?
    Yes, AQA accepts standard pseudocode or any major high-level programming language such as Python, C#, or Java. However, you must write syntactically consistent code and avoid relying on hidden language-specific libraries or shortcuts like .sort() or [::-1] when asked to implement algorithmic logic.
    How do examiners award marks for pseudocode questions?
    Marks are awarded analytically based on specific functional criteria rather than syntax perfection. Points typically cover correct variable initialisation, accurate loop conditions, correct comparison logic, appropriate data updates, and returning or outputting the correct result.
    What happens if my trace table has the correct final values but wrong rows?
    You will lose intermediate accuracy marks. AQA mark schemes strictly assess the step-by-step state progression; cramming multiple iterations into a single row or skipping state updates demonstrates incorrect algorithmic tracing.
    Do I need to memorise specific sorting algorithms for AQA A-Level?
    Yes, you must be able to trace and write standard implementations of Bubble Sort, Insertion Sort, Merge Sort, and Quick Sort. You must also understand their best, worst, and average-case time complexities in Big-O notation.