-
while (low < high)
is used when you're searching the range[low, high)
. When updatinghigh
, usehigh = mid
. When updatinglow
, uselow = mid + 1
. -
while (high - low > 1)
is used when you're searching the range(low, high)
…
This does solve a lot of Doubts, and must be sincerely mentioned in All DSA sites when mentioning binary search
The condition of the loop in binary search should be according to the needs of the search and we get a result like that
To understand it, think of it in a way , what's the smallest input or boundary conditions that a search segment can have for which you dont need any further iterations/recrusive calls.
Top comments (0)