forked from python/cpython
-
Notifications
You must be signed in to change notification settings - Fork 0
algorithms
OccupyMars2025 edited this page May 2, 2024
·
1 revision
(2024/1/16)when searching a sorted array using methods like binary search, it's not obvious about which index to return, should I return low, or "low + 1", or "high - 1", how to reason about the return value ?
https://github.com/OccupyMars2025/dengjunhui-data-structure-cpp-source-code/blob/main/src/Vector/bisect_from_python.py
while lo < hi:
mid = (lo + hi) // 2
if a[mid] < x:
lo = mid + 1
else:
hi = mid