📁 Topic 1 · 1.1 Algorithms
1.1f Binary search
Edexcel 4CP0 · iGCSE Computer Science · ~9 min read
Notes
──
Video
──
Slides
──
Worksheet
──
Quiz

What is Binary Search?

A binary search is a much more efficient searching algorithm than linear search. Instead of checking every element, it repeatedly halves the search area. Critical requirement: the list must be sorted in ascending order before binary search can be applied.

How Binary Search Works — Step by Step

  1. Find the middle element of the current search area (use integer division: (low + high) DIV 2)
  2. Compare the middle element with the target
  3. If they match → target found; return position
  4. If target < middle → search the left half (discard right half)
  5. If target > middle → search the right half (discard left half)
  6. Repeat until found or search area is empty (not found)

Binary Search — Example

List: [3, 7, 12, 18, 24, 35, 41, 56, 68, 79] — Search for 35

StepLowHighMid indexMid valueAction
10942435 > 24 → search right
25975635 < 56 → search left
356535✅ Found at index 5

Only 3 comparisons to find the target in a 10-item list!

Binary Search — Pseudocode (Edexcel 4CP0)

SET low TO 0
SET high TO LENGTH(list) - 1
SET found TO FALSE
WHILE low <= high AND found = FALSE DO
SET mid TO (low + high) DIV 2
IF list[mid] = target THEN
SET found TO TRUE
SEND "Found at " & mid TO DISPLAY
ELSE IF target < list[mid] THEN
SET high TO mid - 1
ELSE
SET low TO mid + 1
END IF
END WHILE
IF found = FALSE THEN
SEND "Not found" TO DISPLAY
END IF

Comparison: Binary vs Linear Search

FeatureLinear SearchBinary Search
List must be sorted?NoYes
Best case1 comparison1 comparison
Worst casen comparisonslog₂(n) comparisons
Efficiency for large listsSlowFast
ComplexityO(n)O(log n)
📝 Exam Tip: You must be able to trace a binary search step by step, showing the low, high and mid values at each step. Remember: mid = (low + high) DIV 2 (integer division).
⚠️ Common Mistakes
  • Applying binary search to an unsorted list — it only works on sorted lists
  • Using mid = (low + high) / 2 — must use DIV (integer division) to get a whole index
  • Forgetting to update low or high after each step — this causes an infinite loop
← 1.1e Linear Search Topic 1 · 1.1 Algorithms Next: 1.1g Bubble Sort →
🔒
Pro Content
Subscribe to access all 47 Edexcel iGCSE lessons.
£7.99/month
or £59/year