Skip to content

Commit a1e64bc

Browse files
Merge pull request #718 from adarsh1mehra/binary-search-python
binary-search-python
2 parents 1f1cfa8 + c5c405e commit a1e64bc

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

Python/binary-search.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
def binary_search(item_list,item):
2+
first = 0
3+
last = len(item_list)-1
4+
print(last)
5+
found = False
6+
while( first<=last and not found):
7+
mid = (first + last)//2
8+
print(mid)
9+
if item_list[mid] == item :
10+
found = True
11+
return found
12+
else:
13+
if item < item_list[mid]:
14+
last = mid - 1
15+
else:
16+
first = mid + 1
17+
18+
19+
print(binary_search([1,2,3,5,8], 6))
20+
print(binary_search([1,2,3,5,8], 5))

0 commit comments

Comments
 (0)