Revision Notes
Cambridge A Level Computer Science (9618): Algorithms (19.1) – Revision Notes
Condensed 9618 notes on searches, bubble and insertion sorts, ADT operations and implementations, graphs and Big O time and space, with a self-test.
- Subject
- Computer Science
- Level
- A LEVEL
- Topic
- Topic 19: Computational thinking and Problem-solving
- Author
- Marlbridge Academic Team
- Updated
- Reviewed by
- Harris Khan (what this means)
Aligned to Cambridge A Level Computer Science (9618), 2026. Official specification .
Syllabus page (what it covers and how it is assessed): Cambridge A Level Computer Science.
Syllabus points this page covers
9618 (A Level)
- 19.1 Algorithms
Found an error? Report a correction.
Need help with this topic? Request a free trial class for A Level Computer Science (9618).
These notes condense section 19.1 “Algorithms” of Cambridge International AS & A Level Computer Science 9618: linear and binary search, insertion and bubble sort, finding, inserting and deleting in abstract data types, graphs, implementing ADTs from other types, and Big O notation for time and space. It is assessed in Paper 3 and in program code in Paper 4.
Related: Algorithms study guide · Algorithms practice questions · Topic 19 revision notes
Key terms
| Term | Meaning |
|---|---|
| ADT | Abstract data type: a collection of data with a set of operations, defined independently of how it is stored |
| Stack | LIFO: items added and removed at the top |
| Queue | FIFO: items added at the rear, removed from the front |
| Linked list | Nodes, each holding data and a pointer to the next node |
| Free list | Linked list of the unused nodes available for new items |
| Null pointer | Value (such as −1) showing there is no next node |
| Binary search tree | Each node has at most two children; left subtree smaller, right subtree larger |
| Graph | Vertices joined by edges; edges may be directed and/or weighted |
| Dictionary | Collection of key-value pairs, looked up by key |
| Time complexity | How the number of steps grows with n |
| Space complexity | How the extra memory needed grows with n |
Searching
| Linear | Binary | |
|---|---|---|
| Data must be sorted? | No | Yes |
| Direct access to any item needed? | No | Yes (array) |
| Method | Check each item in turn | Compare with middle; discard half |
| Worst case | n comparisons, O(n) | about log₂ n + 1 comparisons, O(log n) |
Binary search maximum comparisons: 11 items → 4; 500 → 9; 1,000 → 10; 1,000,000 → 20.
Sorting
Bubble sort: compare neighbours, swap if out of order; each pass puts the largest remaining item at the end; shorten each pass by one; stop when a pass makes no swaps (flag).
Insertion sort: take the next item; shift larger sorted items right; insert it in the gap.
| Initial order (8 items) | Bubble (with flag) | Insertion |
|---|---|---|
| Sorted | 7 comparisons | 7 comparisons |
| Reversed | 28 comparisons | 28 comparisons |
- Worst case both O(n²): n(n − 1) ÷ 2 comparisons.
- Best case (sorted) both about n − 1 comparisons.
- Both sort in place: extra space O(1).
- Insertion sort is usually better for nearly sorted data.
ADT operations
| ADT | Insert | Delete | Find |
|---|---|---|---|
| Stack | Push: check not full; increment top pointer; store item | Pop: check not empty; read item at top; decrement top pointer | Not required |
| Queue | Enqueue: check not full; move rear pointer (wrap round if circular); store item | Dequeue: check not empty; read item at front; move front pointer | Not required |
| Linked list | Take node from free list; find position; set new node’s pointer; update previous pointer (or start pointer) | Find node; make previous pointer skip it (or move start pointer); return node to free list | Follow pointers from start until found or null |
| Binary tree | Start at root; go left if smaller, right if larger, until a null pointer; attach new node there | Not required | Start at root; go left or right until found or null |
Pointer order rule for linked-list insertion: copy the previous node’s pointer into the new node before changing the previous node’s pointer.
Implementing ADTs from other types
- Stack: array + top pointer, or linked list (top = start).
- Queue: circular array + front and rear pointers (and a count), or linked list with front and rear pointers.
- Linked list: array of records (data, pointer) + start pointer + free pointer.
- Binary tree: array of records (data, left pointer, right pointer) + root pointer.
- Dictionary: hash table (key hashed to an array index) or binary search tree ordered by key.
Graphs
- Vertices + edges; directed or undirected; weighted or unweighted.
- May contain cycles; no root, unlike a tree.
- Justify by matching to the situation: towns and roads (weighted by distance), web pages and links (directed), people and friendships (undirected).
- Code for graphs is not required.
Big O summary
| Order | Example in this section |
|---|---|
| O(1) | Push or pop on an array stack; extra space for in-place sorts |
| O(log n) | Binary search; search of a balanced binary tree |
| O(n) | Linear search; linked list search; sorted data through a flagged bubble sort |
| O(n²) | Bubble and insertion sort, worst case |
Exam traps
- Binary search on unsorted data, or on a linked list without direct access.
- Bubble sort with no early stop when asked for an efficient version.
- Linked list: previous pointer changed first, losing the rest of the list.
- Free pointer not updated after taking a node.
- Pop or dequeue without checking for an empty structure.
- Graph described as a hierarchy.
Self-test
- Give the two conditions for using a binary search.
- What is the maximum number of comparisons for a binary search of 500 items?
- What does the flag in a bubble sort record?
- How many comparisons does a flagged bubble sort make on 6 items already in order?
- What is the worst-case time complexity of insertion sort?
- Why do bubble and insertion sort have O(1) space complexity?
- What must be checked before popping a stack?
- In a linked list insertion, what happens to the free pointer?
- Describe how to find an item in a binary search tree.
- Give one way to implement a dictionary.
- Give two features of a graph that a tree does not have to have.
- Why might a linked list be chosen over an ordered array for frequent insertions?
Answers
- The data must be sorted, and any item must be directly accessible (for example in an array).
-
- Whether any swap was made during the pass; no swaps means the list is sorted.
- 5 (one pass, no swaps).
- O(n²).
- They sort in place, needing only a fixed number of extra variables whatever n is.
- That the stack is not empty (top pointer not below the first position).
- It moves to the next node in the free list (the pointer of the node just taken).
- Start at the root; if the target is smaller go left, if larger go right; repeat until found or a null pointer is reached.
- A hash table with the key hashed to an index, or a binary search tree ordered by key.
- Any two: cycles; no root; edges with weights; directed edges in both directions; more than one path between vertices.
- Only pointers are changed; no items need to be moved to make room.
Related resources
-
Study guides
Cambridge A Level Computer Science (9618): Recursion
Study guide to 9618 section 19.2: essential features of recursion, writing and tracing recursive code, when it helps, and how a compiler uses the stack to unwind.
Computer Science · Cambridge · A Level
Read guide -
Practice questions
Cambridge A Level Computer Science (9618): Recursion – Practice Questions
Original 9618 practice questions with answers on recursion: base cases, traces, recursive strings and trees, writing recursive code and the call stack.
Computer Science · Cambridge · A Level
Try questions -
Revision notes
Cambridge A Level Computer Science (9618): Recursion – Revision Notes
Condensed 9618 notes on recursion: base and general cases, tracing winding and unwinding, stack frames, compiler translation and when recursion helps.
Computer Science · Cambridge · A Level
Revise topic
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.