πŸ” How to Find Things in Lists β€” Search Algorithms

Watch linear and binary search work step by step. Understand when each algorithm shines β€” and when it doesn't.

Designed with the WJEC specification in mind
CS GCSE Β§1.4CS A-Level Unit 1CS A-Level Unit 3

πŸ€” What are search algorithms?

Search algorithms help computers find specific items in lists. Linear search checks every item one by one. Binary search is smarter β€” it keeps cutting the list in half, but only works on sorted lists!

πŸ• Analogy: Linear search is like looking for a book by checking every shelf. Binary search is like opening a dictionary to the middle and deciding "too early" or "too late" to find your word faster!
βš™οΈ

Controls

Unchecked
Checking
In range
Midpoint
Eliminated
Found!
Generate an array and pick a target number to search for.
Comparisons0
Array Size15
StatusReady
πŸ“Š

Linear Search

Checks each element one by one from the start until the target is found or the end is reached.

Requirement: None β€” works on any array (sorted or unsorted).

When to use: Small arrays, unsorted data, or when the target is likely near the start.

Best
O(1)
Average
O(n)
Worst
O(n)
⚑

Binary Search

Repeatedly halves the search space by comparing the target with the middle element.

Requirement: Array must be sorted first.

When to use: Large sorted arrays. Massively faster than linear for big data sets.

Best
O(1)
Average
O(log n)
Worst
O(log n)
πŸ“

Exam Tips

  • GCSE: Know that binary search only works on sorted data
  • A-Level: Remember the time complexities: Linear O(n), Binary O(log n)
  • Key point: Binary search halves the search space each step
  • Common mistake: Trying to use binary search on unsorted arrays