You are viewing a free preview of this lesson.
Subscribe to unlock all 10 lessons in this course and every other course on LearningBro.
This lesson brings together everything you have learned about algorithms and data structures, with exam-style questions, worked examples, and key tips for maximising your marks in the GCSE Computer Science exam.
In both AQA and OCR GCSE Computer Science exams, the algorithms topic typically appears in:
Use this decision flowchart to pick the right algorithm in an exam question:
graph TD
A["Read question"] --> B{"Searching or sorting?"}
B -->|Searching| C{"Is data sorted?"}
B -->|Sorting| D{"Small or nearly sorted?"}
C -->|Yes| E["Binary search O(log n)"]
C -->|No| F["Linear search O(n)"]
D -->|Yes| G["Insertion / Bubble sort"]
D -->|No| H["Merge sort O(n log n)"]
Question: Complete the trace table for the following algorithm.
a = 1
b = 1
OUTPUT a
OUTPUT b
FOR i = 1 TO 5
c = a + b
OUTPUT c
a = b
b = c
NEXT i
Answer:
| Step | i | a | b | c | Output |
|---|---|---|---|---|---|
| Initial | — | 1 | 1 | — | |
| — | 1 | ||||
| — | 1 | ||||
| 1 | 1 | 1 | 2 | 2 | 2 |
| 2 | 2 | 2 | 3 | 3 | 3 |
| 3 | 3 | 3 | 5 | 5 | 5 |
| 4 | 4 | 5 | 8 | 8 | 8 |
| 5 | 5 | 8 | 13 | 13 | 13 |
This algorithm generates the Fibonacci sequence: 1, 1, 2, 3, 5, 8, 13.
Question: A database contains 10,000 sorted records. A programmer needs to search for a specific record. Compare linear search and binary search for this task. [6 marks]
Model Answer:
Linear search checks each record one by one from the start:
Binary search repeatedly halves the search space:
Conclusion: Binary search is far more efficient for this task because the data is already sorted. It would find or confirm the absence of the record in at most 14 steps, compared to up to 10,000 for linear search.
Question: Write an algorithm in pseudocode that takes a list of numbers as input and outputs the largest number. [4 marks]
Model Answer:
numbers = [INPUT list of numbers]
max = numbers[0]
FOR i = 1 TO LENGTH(numbers) - 1
IF numbers[i] > max THEN
max = numbers[i]
ENDIF
NEXT i
OUTPUT max
Key marking points:
Question: Describe how a bubble sort would sort the list [4, 2, 7, 1, 3]. Show the state of the list after each complete pass. [4 marks]
Model Answer:
Bubble sort compares adjacent elements and swaps them if they are in the wrong order. After each pass, the largest unsorted element moves to its correct position.
| Pass | Result after pass |
|---|---|
| Original | [4, 2, 7, 1, 3] |
| Pass 1 | [2, 4, 1, 3, 7] |
| Pass 2 | [2, 1, 3, 4, 7] |
| Pass 3 | [1, 2, 3, 4, 7] |
| Pass 4 | [1, 2, 3, 4, 7] — no swaps, algorithm terminates |
| Term | Definition |
|---|---|
| Algorithm | A step-by-step set of instructions to solve a problem |
| Linear search | Checks each element in order; O(n) worst case |
| Binary search | Halves the search space each step; requires sorted data; O(log n) |
| Bubble sort | Compares and swaps adjacent elements; O(n²) |
| Merge sort | Divide and conquer; O(n log n); uses extra memory |
| Insertion sort | Inserts each element into correct position; O(n²) worst, O(n) best |
| Big O notation | Describes worst-case time complexity |
| Stack | LIFO data structure — push and pop |
| Queue | FIFO data structure — enqueue and dequeue |
| Trace table | Tracks variable values step by step |
| Command Word | What it means | What to do |
|---|---|---|
| State | Give a fact | One word or short phrase |
| Describe | Give an account of | Explain the process step by step |
| Explain | Give reasons | Say how AND why |
| Compare | Identify similarities and differences | Discuss both algorithms side by side |
| Evaluate | Weigh up and make a judgement | Give pros/cons and a conclusion |
Subscribe to continue reading
Get full access to this lesson and all 10 lessons in this course.