CS Thinking / supporting

Binary Search

Also known as: bisection search, half-interval search

principle

An efficient algorithm for finding a target value in a sorted list by repeatedly halving the search range. Binary search is orders of magnitude faster than linear search for large sorted datasets.

๐Ÿ’ก Intuition

Looking up a word in a dictionary: open to the middle, then go left or right depending on where your word falls.

Core Idea

Each comparison eliminates half the remaining possibilities โ€” O(log n) vs O(n) for linear search.

๐Ÿ”ฌ Example

Find 37 in [1,5,12,23,37,49,56]: check middle (23), go right, check middle (49), go left, find 37.

๐ŸŽฏ Why It Matters

Binary search is orders of magnitude faster than linear search for large sorted datasets.

โš ๏ธ Common Confusion

Binary search only works on sorted data โ€” applying it to unsorted data gives wrong results.

Related Concepts

Next Steps

How Binary Search Connects to Other Ideas

To understand binary search, you should first be comfortable with searching, array and efficiency. Once you have a solid grasp of binary search, you can move on to linear search.

Go Deeper

Frequently Asked Questions

What is Binary Search in CS Thinking?

An efficient algorithm for finding a target value in a sorted list by repeatedly halving the search range.

Why is Binary Search important?

Binary search is orders of magnitude faster than linear search for large sorted datasets.

What do students usually get wrong about Binary Search?

Binary search only works on sorted data โ€” applying it to unsorted data gives wrong results.

What should I learn before Binary Search?

Before studying Binary Search, you should understand: searching, array, efficiency.