Skip to content
This repository has been archived by the owner on Oct 31, 2019. It is now read-only.

Commit

Permalink
Merge pull request #440 from hannahkriegler/binarySearch
Browse files Browse the repository at this point in the history
added binary search in python
  • Loading branch information
MJ10 authored Oct 16, 2017
2 parents 2ea0acb + e5ac6f3 commit df50668
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions Binary Search/hannahkriegler.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
def main(array, target):
l = 0
r = len(array)-1
binary_search(array,target,l,r)


def binary_search(array,target,low,high):
if high < low :
print("search was unsuccesful")
return
mid = (low + high) // 2
if array[mid] > target:
binary_search(array,target,low,mid-1)
elif array[mid] < target:
binary_search(array,target,mid+1,high)
else :
print("index of target is " + str(mid))


main([1,3,4,6,7,8,12],12)

0 comments on commit df50668

Please sign in to comment.