How do computers find an item in a list quickly?
Understand and explain how the linear search and binary search algorithms work, trace each one, and compare them including the requirement that binary search needs a sorted list.
A focused answer to AQA GCSE Computer Science 3.1.3, covering how linear search and binary search work, how to trace each one, and how they compare including why binary search needs a sorted list.
Reviewed by: AI editorial process; not yet individually human-reviewed
Have a quick question? Jump to the Q&A page
Jump to a section
What this dot point is asking
AQA wants you to explain how linear search and binary search work, trace them on a list of values, and compare them, including knowing that binary search only works on a sorted list.
Linear search
It works on any list, sorted or not, which is its main advantage. The downside is that for a list of items it may need up to comparisons (when the target is last or absent), so it is slow for large lists. On average it checks about half the list.
Binary search
Because each step roughly halves the number of items left to check, binary search is far quicker than linear search on large lists. The reason it needs a sorted list is that the "discard a half" rule is only valid when the values are in order, so the algorithm knows which half cannot contain the target.
Comparing the two
The trade-off is that if a list is unsorted and you only search it once, the cost of sorting it first may outweigh the saving, so linear search can be the sensible choice. Binary search pays off on large lists that are already sorted or searched many times.
How the two algorithms work step by step
A linear search keeps a position that starts at the first element and moves one place right after each comparison, checking each item against the target and stopping if it matches or when it runs off the end. A binary search keeps two pointers, the lowest and highest positions still in play, and repeatedly examines the middle item between them: if the middle matches, it stops; if the target is smaller, it moves the high pointer just below the middle; if larger, it moves the low pointer just above the middle, halving the range each time. Describing the algorithms in terms of these moving positions is exactly what a "describe how the algorithm works" question rewards.
Efficiency in numbers
The efficiency difference is dramatic and worth quoting with figures. For a list of items, linear search makes up to comparisons, so doubling the list doubles the worst-case work. Binary search makes at most about comparisons, so doubling the list adds only one extra comparison. For 1000 items that is up to 1000 versus about 10; for a million items it is up to a million versus about 20. This is why binary search is preferred for large, already-sorted data, while linear search remains useful for short or unsorted lists where sorting first would not pay off.
Try this
Q1. State one condition that must be true for a binary search to work. [1 mark]
- Cue. The list must be sorted (in order).
Q2. A list has 1024 sorted items. State the maximum number of items a binary search must check. [1 mark]
- Cue. About 10, because and each step halves the list.
Exam-style practice questions
Practice questions written in the style of AQA exam questions on this dot point, with worked answer explainers. The year tag is the paper they imitate, not the source.
AQA 20204 marksThe sorted list [2, 5, 8, 12, 16, 23, 38, 45] is searched for the value 23 using a binary search. Trace the search, stating the middle value examined at each step and the part of the list kept, and give the number of comparisons made.Show worked answer →
Step 1: with 8 items, take the middle (position 4, value 12). , so discard the lower half and keep [16, 23, 38, 45].
Step 2: middle of the remaining four (value 23 or 38 depending on rounding; AQA accepts either midpoint). Taking 38: , so keep [16, 23]. Taking 23 first instead would find it in this step.
Step 3: middle of [16, 23] is 23, which matches. The target is found in 3 comparisons (2 if the earlier midpoint lands on 23).
Markers reward a consistent midpoint rule, correctly discarding the half that cannot contain 23, and a comparison count consistent with the trace.
AQA 20234 marksCompare linear search and binary search. State one advantage of each, and explain why binary search cannot be used on the list [7, 2, 9, 4].Show worked answer →
Advantage of linear search: it works on any list, sorted or not, and needs no sorting first, so it is simple and fine for short or unsorted data. Advantage of binary search: on a large sorted list it is far faster, needing at most about comparisons instead of up to .
Binary search cannot be used on [7, 2, 9, 4] because the list is not sorted. Binary search relies on discarding the half that cannot contain the target, which is only valid if the values are in order; on an unsorted list it could discard the half that actually holds the target and miss it.
Markers reward one valid advantage of each and the explicit reason (the list is unsorted, so halving is invalid).
Related dot points
- Understand and explain how the bubble sort and merge sort algorithms work, trace each one, and compare them in terms of method and efficiency.
A focused answer to AQA GCSE Computer Science 3.1.4, covering how bubble sort and merge sort work, how to trace each one, and how they compare in method and efficiency.
- Computational thinking through abstraction, decomposition and algorithmic thinking, and understanding what an algorithm is and the difference between an algorithm and a program.
A focused answer to AQA GCSE Computer Science 3.1.1, covering abstraction, decomposition and algorithmic thinking, what an algorithm is, and how an algorithm differs from a program.
- Represent and interpret algorithms using flowcharts and pseudocode, recognise the standard flowchart symbols, and read and write AQA-style pseudocode.
A focused answer to AQA GCSE Computer Science 3.1.2, covering how to represent algorithms with flowcharts and pseudocode, the standard flowchart symbols, and reading and writing AQA-style pseudocode.
- Use one-dimensional and two-dimensional arrays and records to store collections of data, and access elements using indexes and field names.
A focused answer to AQA GCSE Computer Science 3.2.6, covering one-dimensional and two-dimensional arrays and records, and accessing elements using indexes and field names.
Sources & how we know this
- AQA GCSE Computer Science (8525) specification — AQA (2020)