When can you apply binary search?medium

Type
conceptual
Topic
binary-search
Frequency
common
Roles
ml-engineer
Tags
binary-search, array
Answer

Use binary search when the search space is sorted or has a monotonic true/false condition.

Explanation

Binary search repeatedly discards half the search space. It works not only on arrays but also on answer ranges, such as finding the minimum capacity that satisfies a condition.

Follow-upWhat causes infinite loops in binary search?