0

Binary Search

Halve the search space every step. Works on any monotonic predicate, not just sorted arrays.

Newinterview weight 8022 problems2 visualisers
18
mastery
Attempts logged
0
Predicted success on the next one
33%
Solved here
0 / 22

What you actually need to hold in your head

  • Search on the answer, not the array
  • Find the boundary where the predicate flips
  • Off-by-one lives in the lo, hi and mid updates
  • Thirty steps is enough for a billion elements

Watch it run

Step through the algorithm before you write it.

Patterns in this topic

The trigger phrases are what you are training yourself to notice.

Binary Search problems

Ordered by sheet phase, so the early ones are the highest signal.

0 / 22 solved
1
2
3
EBinary Search
4
5
MBinary Search
6
MBinary Search
7
8
9
10
HBinary Search
11
12
13
14
15
16
17
EBinary Search
18
19
20
MBinary Search
21
22