Algorithms · 3 min read
Why binary search gets stuck on two numbers
Trace a binary search that never finishes on [4, 9]. Fix the boundary update in Python and test the cases that reveal an off-by-one error.
Read the guideindex 0 1
value [4, 9]
↑ ↑
lo, mid hi