📁 Paper 1 · 3.1 Fundamentals of Algorithms
3.1.3b Searching Algorithms — Binary Search
AQA 8525 · GCSE Computer Science · ~12 min read
Notes
──
Video
──
Slides
──
Worksheet
──
Quiz

What is Binary Search?

Binary search is a searching algorithm that works on a sorted list. It repeatedly halves the search area by comparing the target to the middle element, eliminating half the remaining items at each step.

It is much faster than linear search for large sorted lists but requires the list to be sorted first.

How Binary Search Works — Step by Step

  1. Start with the whole list as the search area
  2. Find the middle element: midpoint = (low + high) DIV 2
  3. If middle = target → found! Return index
  4. If target < middle → search the left half (discard right half)
  5. If target > middle → search the right half (discard left half)
  6. Repeat from step 2 until found or no items remain
  7. If no items remain → return "not found"

Worked Example — Searching for 7 in [1, 3, 5, 7, 9, 11, 14]

List (sorted): indices 0–6. Target = 7.

Step 1: low=0, high=6, mid=(0+6) DIV 2 = 3 → list[3] = 7 = target → Found!

1
3
5
7
9
11
14

Found at index 3 in just 1 comparison!

Example Needing Multiple Steps — Find 11

List: [1, 3, 5, 7, 9, 11, 14]. Target = 11.

Step 1: low=0, high=6, mid=3 → list[3]=7. 11 > 7 → search right half

1
3
5
7
9
11
14

Step 2: low=4, high=6, mid=(4+6) DIV 2=5 → list[5]=11 = target → Found!

1
3
5
7
9
11
14

Found at index 5 in 2 comparisons!

Trace Table — Finding 11 in [1, 3, 5, 7, 9, 11, 14]

Steplowhighmidlist[mid]Action
1063711 > 7 → low = 4
24651111 = 11 → Found at index 5!

AQA Pseudo-code

SUBROUTINE binarySearch(list, target) low0 high ← LEN(list) - 1 foundFalse position-1 WHILE lowhigh AND NOT found mid ← (low + high) DIV 2 IF list[mid] = target THEN foundTrue positionmid ELSEIF list[mid] > target THEN highmid - 1 // target in left half ELSE lowmid + 1 // target in right half ENDIF ENDWHILE RETURN position // -1 if not found ENDSUBROUTINE

Efficiency of Binary Search

CaseComparisonsExample (n=7)
Best case1Target is the middle element
Average/Worst caselog₂(n)~3 comparisons

For n = 1,000,000 items, binary search needs at most ~20 comparisons. Linear search needs up to 1,000,000!

Comparison: Binary vs Linear Search

FeatureLinear SearchBinary Search
List must be sorted?NoYes
Worst case comparisonsnlog₂(n)
n = 1,000,0001,000,000~20
ComplexitySimplerMore complex
Best forUnsorted or small listsSorted, large lists
Exam tip: Always state that binary search requires a sorted list — this earns a mark on its own. The midpoint formula in AQA is: mid = (low + high) DIV 2. DIV means integer division (round down).
⚠️ Common Mistakes
  • Forgetting that the list must be sorted before binary search can be applied
  • Rounding midpoint up instead of down — always use DIV (integer division, rounds down)
  • Updating low/high incorrectly: target > mid → low = mid + 1; target < mid → high = mid - 1
  • Claiming binary search is always better — for small or unsorted lists, linear search may be more appropriate
Video coming soon
This lesson video is in production

Key points covered in this video

  • Why binary search needs a sorted list
  • The halving process step by step with visual examples
  • Computing midpoints using (low + high) DIV 2
  • Completing trace tables for binary search
  • Efficiency comparison: O(log n) vs O(n)
Click slide or press arrow keys to navigate
✍️

Exam-style Worksheet — 3.1.3b Binary Search

8 AQA-style questions · 23 marks · Mark schemes revealed on submit

Q1State one requirement of binary search that is NOT required for linear search.[1 mark]
✅ Mark scheme
Mark scheme
The list must be sorted / in order [1].
Q2Describe the steps of a binary search algorithm.[4 marks]
✅ Mark scheme
Mark scheme
Find the middle element of the search area [1]; compare it to the target [1]; if equal, return found; if target is less, search the left half; if target is greater, search the right half [1]; repeat until found or search area is empty [1].
Q3Perform a binary search for target = 9 in [2, 4, 6, 8, 9, 12, 15]. Show low, mid, high for each step.[4 marks]
✅ Mark scheme
Mark scheme
Step 1: low=0,high=6,mid=3,list[3]=8; 9>8 → low=4 [1]. Step 2: low=4,high=6,mid=5,list[5]=12; 9<12 → high=4 [1]. Step 3: low=4,high=4,mid=4,list[4]=9=target → found [1]; returns index 4 [1].
Q4Write the AQA pseudo-code formula for calculating the midpoint in binary search.[1 mark]
✅ Mark scheme
Mark scheme
mid ← (low + high) DIV 2 [1]. Accept equivalent notation.
Q5A sorted list of 128 items is searched using binary search. What is the maximum number of comparisons needed?[2 marks]
✅ Mark scheme
Mark scheme
log₂(128) = 7 comparisons [2]. Working: 128→64→32→16→8→4→2→1 = 7 halvings [1 for method, 1 for answer]. Accept 7 or 8.
Q6Compare binary search and linear search. Give one advantage of each.[4 marks]
✅ Mark scheme
Mark scheme
Binary advantage: far fewer comparisons on large sorted lists — O(log n) vs O(n) [1]; e.g. 1,000,000 items: ~20 vs 1,000,000 comparisons [1]. Linear advantage: works on unsorted lists [1]; simpler to implement [1]. Award up to 4.
Q7Write AQA pseudo-code for a binary search on a list called 'data' searching for 'target'. Include WHILE, ELSEIF, DIV, and RETURN.[5 marks]
✅ Mark scheme
Mark scheme
Initialise low, high [1]; WHILE low ≤ high AND NOT found [1]; mid ← (low + high) DIV 2 [1]; IF/ELSEIF correctly updating low = mid+1 or high = mid-1 [1]; RETURN position / -1 with correct ENDWHILE [1].
Q8A programmer has a database of 1,000,000 unsorted records. They want to use binary search. Explain what they must do first, and why.[2 marks]
✅ Mark scheme
Mark scheme
They must sort the records first [1]; because binary search only works on sorted data — it relies on eliminating half the list at each step, which requires the data to be in order [1].
Compare your answers to the mark schemes above.
Topic Quiz
Question 1 of 15
You scored
out of 15
Card 1 of 6
Click to flip
🎉
All cards reviewed!
TermDefinition
🎯

Mini Test — 3.1.3b Binary Search

Timed exam conditions. No feedback until you submit.

  • 8 questions · 8 marks · 10 minutes
  • 5 multiple choice + 3 short answer
  • Mark schemes revealed after submission
← 3.1.3a Linear Search
6 of 57 · AQA 8525
3.1.4a Bubble Sort →