Skip to content

Commit 2174e74

Browse files
authored
Add files via upload
1 parent ff99d27 commit 2174e74

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

binary_search.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
def binary_search(L,x):
2+
left, right = 0, len(L)-1
3+
4+
while left <= right :
5+
mid = left + right//2
6+
if L[mid] == x:
7+
return mid
8+
elif L[mid]<x:
9+
left = mid+1
10+
else:
11+
right = mid-1
12+
return -1
13+
14+
L =[1,2,3,4,5,6,7,8,9,10,11,12,13,14,15]
15+
x = 11
16+
output = binary_search(L,x)
17+
print(output)
18+

0 commit comments

Comments
 (0)