Skip to content
Learnearn.uk » A Level Computer Science Home » Binary Search

Binary Search

Binary Search

What is Binary Search?

Binary search is an efficient algorithm used to find a specific element in a sorted array or list. It works by repeatedly dividing the search space in half until the target element is found or determined to be absent.

How does Binary Search work?

Binary search starts by comparing the target element with the middle element of the array. If they are equal, the search is complete. If the target element is smaller, the search continues on the lower half of the array; otherwise, it continues on the upper half.

This process is repeated until the target element is found or the search space is empty.

Demonstration

Pros & Cons

Python Code