Binary Search
easyGiven a sorted array of integers and a target, return the index of the target or -1 if not found
Binary Search (Classic)
Key Insight
Compare mid with target. If target < mid, search left half. If target > mid, search right half.
Step 1Initialize Pointers
Target: 9
L
R
-1
00
13
25
39
412
5Search space: [0..5]
Set left=0, right=5. Target is 9.
1 / 5