Searching Algorithms
Aligned to the OCR J277 specification
- Topic
- Algorithms
- Level
- Intermediate
- Reading time
- 7 min
- Published
- 11 June 2026
- Updated
- 1 July 2026
On this page
Key takeaways
- Linear search checks each element one by one from the start, works on any list (sorted or unsorted), and requires up to n comparisons for a list of n items.
- Binary search halves the remaining search space each step, so it needs at most log base 2 of n comparisons - but the list MUST be sorted first or it gives wrong results.
- To find the midpoint in binary search, use integer division: mid = (low + high) DIV 2, always rounding down.
- A common mistake is applying binary search to an unsorted list - always check the list is sorted before choosing binary search.
- Binary search ends either when the target is found OR when low > high (meaning the target is not in the list).
Want more lessons like this one?
Generate lessons on anything you study. Free account, no card needed.
Key terms
- Linear search
- A searching algorithm that checks each element in a list one at a time, from the first to the last, until the target is found or the list is exhausted.
- Binary search
- A searching algorithm that repeatedly halves the search space by comparing the target to the middle element; requires the list to be sorted first.
- Index
- The numbered position of an element in a list, starting at 0 for the first element.
- Midpoint
- In binary search, the middle index of the current search range, calculated as (low + high) DIV 2 using integer division.
- Search space
- The portion of the list that binary search still needs to check; it is halved after each comparison.
- Not found condition
- In binary search, the search ends with 'not found' when low becomes greater than high, meaning no elements remain to check.
Frequently asked questions
Linear search checks each element one at a time from the start and works on any list. Binary search halves the search space each step but requires the list to be sorted first. For a list of 1,024 items binary search needs at most 10 comparisons; linear search needs up to 1,024.
No. Binary search only works correctly on a sorted list. If the list is not sorted, binary search will produce incorrect results. You must sort the list first, or use linear search instead.
Use integer division: mid = (low + high) DIV 2, rounding down. For low = 5 and high = 9, mid = 14 DIV 2 = 7. Never use a decimal result - always round down.
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
Designing and Refining Algorithms
Sorting Algorithms
Related lessons
8 min
9 min
8 min