mirror of
https://github.com/autistic-symposium/master-algorithms-py.git
synced 2025-04-29 20:26:07 -04:00
Update binary_search.py
This commit is contained in:
parent
a449abf709
commit
5456593be9
@ -23,16 +23,20 @@ def binary_search_recursive(array, item, higher=None, lower=0):
|
||||
|
||||
|
||||
def binary_search_iterative(array, item):
|
||||
|
||||
if lens(nums) == 0:
|
||||
return False
|
||||
|
||||
lower, higher = 0, len(array)
|
||||
|
||||
while lower < higher:
|
||||
while lower <= higher:
|
||||
mid = (higher + lower) // 2
|
||||
|
||||
if array[mid] == item:
|
||||
return mid
|
||||
|
||||
elif array[mid] > item:
|
||||
higher = mid
|
||||
higher = mid - 1
|
||||
|
||||
else:
|
||||
lower = mid + 1
|
||||
|
Loading…
x
Reference in New Issue
Block a user