All tools

Algorithms

Algorithm Visualiser — Sorting, Searching & Pathfinding

Watch sorting and searching algorithms execute step-by-step with a live trace table. Covers bubble sort, insertion sort, linear search and binary search for GCSE, plus Dijkstra's algorithm and A* pathfinding for A Level Computer Science. Every step shows exactly what changes — just like an exam trace question.

AQA GCSEOCR GCSECambridge IGCSEAQA A LevelOCR A Level
Algorithm:
5
0
2
1
8
2
1
3
9
4
3
5
7
6
4
7
Value colour Comparing Swapping Sorted ✓

Step 1/62 Bubble sort: scan left→right, swap adjacent pairs if out of order. Largest "bubbles" to the end each pass.

Speed:

Trace table (last 0 steps)

Passja[j]a[j+1]Action
Press Play or Step → to see trace

Big O complexity reference

A Level only

Big O notation is assessed at A Level (AQA 7517, OCR H446) — not required at GCSE. GCSE students should focus on tracing algorithms by hand and comparing the number of comparisons made.

AlgorithmLevelBest caseWorst caseSpace
Bubble SortGCSEO(n)O(n²)O(1)
Insertion SortGCSEO(n)O(n²)O(1)
Linear SearchGCSEO(1)O(n)O(1)
Binary SearchGCSEO(1)O(log n)O(1)
Dijkstra'sA LevelO((V+E)log V)O((V+E)log V)O(V)
A* SearchA LevelO(E)O(b^d)O(V)

A Level exam tip: Dijkstra guarantees the shortest path in a non-negative weighted graph but explores in all directions. A* uses a heuristic h(n) to focus the search toward the goal — it finds the same optimal path but typically visits far fewer nodes. A* is only optimal when h(n) is admissible (never overestimates the true cost). V = vertices, E = edges, b = branching factor, d = depth.

Algorithm guide — what you need to know for the exam

Each algorithm below is assessed at either GCSE or A Level. Click the algorithm in the visualiser above to see it in action with a live trace table.

🫧

Bubble Sort

GCSE

Repeatedly scans the array comparing adjacent pairs and swapping them if they are in the wrong order. After each complete pass, the largest unsorted element "bubbles" to its correct position at the end. The algorithm can terminate early if a complete pass produces no swaps — this is an important efficiency feature to mention in the exam.

Exam technique: Trace by writing out the full array after each pass. Count the number of comparisons and swaps made. Note if early termination occurs because a complete pass had no swaps.
📌

Insertion Sort

GCSE

Builds a sorted section one element at a time, starting from the left. Takes each new element from the unsorted part and inserts it into the correct position in the sorted section by shifting larger elements one place to the right.

Exam technique: Trace by showing the sorted section growing one element at a time. For each new element, show it being compared against sorted elements from right to left until the correct position is found.
🔍

Linear Search

GCSE

Checks each element from the start of the list in order until the target is found or the list is exhausted. Works on both sorted and unsorted data. Simple to implement but can require checking every element in the worst case.

Exam technique: State which element is being checked at each step. State the total number of comparisons made to find the target (or confirm it is not present). Remember: linear search works on unsorted lists — binary search does not.

Binary Search

GCSE

Requires a sorted list. Finds the midpoint of the current search range, compares it to the target, then discards the half that cannot contain the target and repeats. For 1,024 elements at most 10 comparisons are needed — far fewer than checking every element.

Exam technique: Show the low, mid and high pointers at each step. Calculate mid = ⌊(low + high) / 2⌋. State which half is discarded and why. The list must be sorted — state this if the question asks when to use binary vs linear search.
🗺️

Dijkstra's Algorithm

A Level O((V+E) log V)

Finds the shortest path in a weighted graph from a source node to all other nodes. Uses a priority queue (ordered by distance) to always expand the nearest unvisited node first. Guarantees the optimal shortest path for graphs with non-negative edge weights.

Exam technique: Trace by maintaining a distance table with columns for each node. Show which node is dequeued at each step, which distances are updated, and the final shortest-path reconstruction by following previous-node pointers.

A* Search

A Level O(b^d) worst case

An informed extension of Dijkstra that uses a heuristic h(n) — an estimate of the remaining cost to reach the goal. Combines actual cost from the start g(n) with the heuristic estimate: f(n) = g(n) + h(n). Always expands the node with the lowest f score. Finds the optimal path if h(n) is admissible (never overestimates).

Exam technique: Know the distinction between g(n) (cost so far), h(n) (heuristic estimate) and f(n) = g(n) + h(n) (total estimated cost). Understand admissibility. Trace the open set (frontier) and closed set (visited) at each step.
📌

GCSE vs A Level: At GCSE you need to trace algorithms by hand and describe how they work — you do not need Big O notation. Big O time and space complexity is A Level only (AQA 7517, OCR H446). For GCSE, focus on being able to write out each step and compare algorithms based on number of comparisons for a given input.

Frequently asked questions — algorithms

What sorting algorithms do I need for GCSE Computer Science?

At GCSE (AQA 8525, OCR J277, Cambridge 0478) you need to know bubble sort and insertion sort — how they work step by step and how to trace through them by hand. You should be able to write out the state of the array after each pass of bubble sort, and show each insertion for insertion sort. Big O time complexity is not required at GCSE; it is A Level content.

Do I need to know Big O notation for GCSE?

No. Big O notation (O(n), O(n²), O(log n)) is assessed at A Level only — AQA 7517 and OCR H446. At GCSE you need to be able to trace algorithms by hand and compare them based on the number of comparisons made. For example, a GCSE question might ask: "How many comparisons does a binary search make on a list of 16 items?" — you work this out from the algorithm, not from Big O.

What is the difference between linear search and binary search?

Linear search checks each element in order from the first — it works on any list (sorted or unsorted) but can require checking every element in the worst case. Binary search repeatedly halves the search space and is much faster, but the list must already be sorted. For a list of 1,024 items, binary search takes at most 10 comparisons rather than up to 1,024 for linear search.

What are Dijkstra and A* used for?

Both are A Level algorithms for finding the shortest path through a weighted graph. Dijkstra's algorithm explores nodes in order of their distance from the start. A* improves on this by using a heuristic — an estimate of remaining distance — to focus the search towards the goal. Both are assessed at A Level (AQA 7517 and OCR H446). They are not required at GCSE.

How do I trace a bubble sort in the exam?

Write out the full array. On each pass, compare adjacent pairs from left to right — if the left value is greater than the right, swap them. Write out the array after each complete pass. If a full pass makes no swaps, the array is sorted and you can stop — always note this early termination in your answer.

Related resources