How do the linear search and binary search algorithms work, and when is each suitable?
The linear search and binary search algorithms, how each works, and the conditions under which each is suitable.
A focused answer to the WJEC GCSE Computer Science Unit 1 content on searching algorithms, covering how the linear search and binary search work step by step, the requirement that binary search needs sorted data, and the relative efficiency of the two methods with worked examples.
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 topic is asking
WJEC wants you to know how the linear search and binary search algorithms work and when each is suitable. This is part of the Algorithms and programming principles content in Unit 1 of WJEC GCSE Computer Science (3500).
Linear search
Binary search
How the two compare for efficiency
Choosing a search
A linear search is best when the list is small or not sorted, or when you only search occasionally and do not want the cost of sorting first. A binary search is best when the list is large and already sorted (or is sorted once and searched many times), because the time saved on each search outweighs the one-off sorting cost. In practice, programmers weigh up how often the data changes and how often it is searched: data that is searched far more often than it changes is worth sorting once so that every later search can be a fast binary search.
Try this
Q1. State one requirement that must be true before a binary search can be used. [1 mark]
- Cue. The list must be sorted (in order).
Q2. State one advantage of a linear search over a binary search. [1 mark]
- Cue. It is simpler and works on any list, whether sorted or not.
Exam-style practice questions
Practice questions written in the style of WJEC exam questions on this dot point, with worked answer explainers. The year tag is the paper they imitate, not the source.
WJEC-style Unit 14 marksDescribe how a binary search works to find a value in a sorted list.Show worked answer →
A Unit 1 algorithms question. A binary search works on a sorted list. It looks at the middle item of the list (1 mark). If that item is the one being searched for, the search ends; if the target is smaller than the middle item, the search continues in the lower half, and if it is larger, it continues in the upper half (1 mark for comparing and choosing a half). The chosen half is searched the same way, repeatedly halving the list until the item is found or no items remain (1 mark). Because it halves the list each time, it finds the item in far fewer steps than checking every item (1 mark). Markers reward checking the middle, discarding half each time and the need for sorted data. A common error is to forget that binary search requires the list to be sorted.
WJEC-style Unit 13 marksExplain one advantage and one disadvantage of a binary search compared with a linear search.Show worked answer →
A Unit 1 comparison question. An advantage of binary search is that it is usually much faster on large lists, because it halves the search area each step rather than checking items one by one (1 mark). A disadvantage is that it only works on data that is already sorted, so unsorted data must be sorted first, which takes time (1 mark). By contrast a linear search is simpler and works on any list, sorted or not, but is slow on large lists (1 mark for a valid contrasting point). Markers reward faster-on-large-lists versus needs-sorted-data. A common error is to say binary search always works, ignoring the sorted requirement.
Related dot points
- Computational thinking through decomposition and abstraction, what an algorithm is, and expressing algorithms using flowcharts and pseudocode.
A focused answer to the WJEC GCSE Computer Science Unit 1 content on computational thinking and algorithms, covering decomposition and abstraction, what an algorithm is, and how algorithms are expressed using flowcharts (with the standard symbols) and pseudocode, with worked examples.
- The bubble sort and merge sort algorithms, how each puts data into order, and the relative efficiency of the two methods.
A focused answer to the WJEC GCSE Computer Science Unit 1 content on sorting algorithms, covering how the bubble sort works by repeatedly swapping adjacent items, how the merge sort works by splitting and merging, and the relative efficiency of the two methods with worked examples.
- The three programming constructs (sequence, selection and iteration), the use of variables and constants, and arithmetic, relational and logical operators.
A focused answer to the WJEC GCSE Computer Science Unit 1 content on programming constructs, covering sequence, selection and iteration (including IF statements and FOR and WHILE loops), the difference between variables and constants, and arithmetic, relational and logical operators with worked examples.
- The use of subprograms (procedures and functions) and parameters, and the benefits of a modular, structured approach to programming.
A focused answer to the WJEC GCSE Computer Science Unit 1 content on subprograms and program structure, covering procedures and functions, the use of parameters, the difference between a procedure and a function, and the benefits of a modular, structured approach to writing programs.
- The common data types, the use of data structures such as arrays and records, and the difference between validation and verification.
A focused answer to the WJEC GCSE Computer Science Unit 1 content on data organisation, covering the common data types (integer, real, Boolean, character and string), data structures such as arrays and records, and the difference between validation and verification with examples of each technique.