Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions D_arrays/operation_on_arrays/A_searching.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
def method1(l: list, low: int, high: int, x: int) -> int:
if high >= low:
mid = (high + low) // 2
if l[mid] == x:
return mid
elif l[mid] > x:
return method1(l, low, mid - 1, x)
if high >= low: #check the is high no is greater than low
mid = (high + low) // 2 #find mid by taking avg of high & low
if l[mid] == x: #check the mid no is equal to finding no
return mid # if equal return mid no
elif l[mid] > x: # if mid is greater than X
return method1(l, low, mid - 1, x) # set high = mid-1
else:
return method1(l, mid + 1, high, x)
return method1(l, mid + 1, high, x) # set low = mid+1
else:
return -1
return method1(l, 0, len(l) - 1, x)
Expand Down