##### ###### ##### ### # # ### # # ###### ## ## ## ## ## ## ## # # # # # ## ##### #### ##### # # # # # # # #### ## # ## ## ## ## # # # # # ## ## # ###### ## ### # ### # ######
##### ###### ##### ### # # ### # # ###### ## ## ## ## ## ## ## # # # # # ## ##### #### ##### # # # # # # # #### ## # ## ## ## ## # # # # # ## ## # ###### ## ### # ### # ######
Cut the search space in half with each step. Turn O(n) linear search into O(log n) binary search.
The power of halving the search space.
How binary search halves the search space.
Finding an exact target in a sorted array.
Implementation with careful boundary handling.
Find the first element greater than or equal to target.
Implementation that finds the insertion point.
Find the first element strictly greater than target.
Locate the range of equal elements.
Test your understanding
When you can't search an array, search the answer space.
Implementation of binary search on the answer.
Another binary search on the answer problem.
Test your understanding
When the answer is a floating-point value.
Why `mid = (low + high) / 2` can loop forever.
Common mistakes in boundary conditions.
Integer overflow in `(low + high) / 2`.
Test your understanding
Template for finding the first value satisfying a condition.
Template for finding the last value satisfying a condition.
Test your understanding
Start leaning basics.
Start leaning basics.
Start leaning basics.
Start leaning basics.
Start leaning basics.
Start leaning basics.
Test your understanding
Start leaning basics.
Start leaning basics.
Start leaning basics.
Start leaning basics.
Start leaning basics.
Start leaning basics.
Test your understanding
Start leaning basics.
Start leaning basics.
Start leaning basics.
Test your understanding
Summary of binary search techniques.