Skip to main content
WalesComputer ScienceSyllabus dot point

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.

Generated by Claude Opus 4.89 min answer

Reviewed by: AI editorial process; not yet individually human-reviewed

Have a quick question? Jump to the Q&A page

Jump to a section
  1. What this topic is asking
  2. Linear search
  3. Binary search
  4. How the two compare for efficiency
  5. Choosing a search
  6. Try this

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).

How the two compare for efficiency

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

Sources & how we know this