Linear Search and Binary Search
Aligned to the AQA 8525 specification
- Level
- Intermediate
- Reading time
- 6 min
- Published
- 2 June 2026
- Updated
- 1 July 2026
On this page
Key takeaways
- Linear search checks each element in sequence from the first until the target is found or the list ends; it works on unsorted lists and needs up to n comparisons in the worst case.
- Binary search requires the list to be sorted in ascending order, then repeatedly halves the search space by comparing the target to the middle element.
- Binary search needs at most about log2(n) comparisons, so a 1,000-item list takes at most 10 and a 1,000,000-item list at most 20, versus n for linear search.
- Binary search is not always the better choice: it requires sorted data, so on small or frequently-changing lists the cost of sorting first can exceed a simple linear search.
- After a non-match in binary search, set low = mid + 1 or high = mid - 1; using mid itself rechecks the midpoint and can cause an infinite loop.
Want more lessons like this one?
Generate lessons on anything you study. Free account, no card needed.
Key terms
- Searching algorithm
- A method that locates a specific target value within a list and returns its position, or reports that it is absent.
- Target
- The specific value a searching algorithm is trying to locate within a list.
- Comparison
- Each time the algorithm checks whether an element matches the target; fewer comparisons means a faster algorithm.
- Linear search
- An algorithm that checks each element in the list in sequence from the first until the target is found or the end is reached.
- Binary search
- An algorithm that repeatedly halves the search space by comparing the target to the middle element of the current range, requiring a sorted list.
Frequently asked questions
Linear search checks each element in order and works on any list, but may need up to n comparisons. Binary search requires a sorted list and repeatedly halves the search space, needing only about log2(n) comparisons, making it far faster on large datasets.
Binary search assumes that if the target is less than the midpoint it cannot be in the right half, so it discards that half. This assumption is only valid when the list is sorted in ascending order; on unsorted data binary search produces incorrect results.
The midpoint is mid = (low + high) divided by 2, rounded down using integer division. For low = 0 and high = 7, mid = 3.5 which rounds down to 3, not 4.
Generate revision on any topic you study
Type any topic you're studying and Aicademy generates a complete lesson, quiz, and flashcard set, personalised to your level.
Lessons on anything
Structured, level-matched lessons on any topic you study
Practice quizzes
Find out what you actually know before the exam does
Flashcard sets
Lock in key concepts with instant revision cards
Ask Aica
Stuck on something? Get a clear explanation, any time
Computational Thinking and Representing Algorithms
Bubble Sort
Related lessons
8 min