Skip to content

Commit 6fbbf90

Browse files
authored
Merge pull request #12 from d3xt3r0/master
Binary Search program with worst time complexity O(log n) and space complexity O(1)
2 parents e97c0c7 + 57b8673 commit 6fbbf90

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

binary_search_d3xt3r0.py

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

0 commit comments

Comments
 (0)