Binary Search
Searches by repeatedly cutting the search space in half.
10
20
30
40
50
60
70
80
90
L
H
Initialize pointers.
Where It's Used
- Searching for an element in a sorted array.
- Finding the first or last position of a value.
- Determining a minimum or maximum value that satisfies a condition.
- Problems where the answer lies within a numeric range.
Problems Using This Pattern
Binary Search
Binary Search
First Bad Version
Binary Search
Find First and Last Position of Element in Sorted Array
Binary Search
Search Insert Position
Binary Search
Capacity To Ship Packages Within D Days
Binary Search