Skip to content

Commit 71001bf

Browse files
author
Bhrigu Kansra
authored
Merge pull request #35 from Pratyush2703/Binarysearch.py
Create BinarySearch.py
2 parents 95da8b7 + 4724cd0 commit 71001bf

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

searching/BinarySearch.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
def binarySearch(alist, item):
2+
2 if len(alist) == 0:
3+
3 return False
4+
4 else:
5+
5 midpoint = len(alist)//2
6+
6 if alist[midpoint]==item:
7+
7 return True
8+
8 else:
9+
9 if item<alist[midpoint]:
10+
10 return binarySearch(alist[:midpoint],item)
11+
11 else:
12+
12 return binarySearch(alist[midpoint+1:],item)

0 commit comments

Comments
 (0)