Binary Search
Divide and conquer with logarithmic time complexity.
7
Problems
0
Easy
7
Medium
0
Hard
How Binary Search Works
Binary Search eliminates half the search space with each comparison. Starting with a range [low, high], you check the middle element and decide whether the answer lies in the left or right half. This gives O(log n) time complexity. Beyond basic sorted array search, binary search applies to any problem where you can define a monotonic condition — a boundary where values go from "no" to "yes" (or vice versa). You're essentially searching for that boundary.
When to Use Binary Search
Pattern Recognition
Look for these trigger words in problem statements:
binary search
binary-search
search a 2d matrix
koko eating bananas
search in rotated sorted array
find minimum in rotated sorted array
time based key-value store
median of two sorted arrays
Common Mistakes
- Infinite loops from incorrect mid calculation or boundary updates (use low + (high - low) // 2)
- Off-by-one errors in the loop condition: while low <= high vs while low < high
- Not correctly identifying the search space — sometimes you search on the answer, not the array
- Forgetting that binary search requires a monotonic property to work correctly
When NOT to Use Binary Search
- When the array is unsorted and you can't sort it
- When there's no monotonic property to exploit
- When the search space is tiny (linear scan is simpler and equally fast)
Practice Problems
Master Binary Search
Build pattern recognition with interactive MCQs. Understand why to use Binary Search, not just how.
Download LeetEye Free