Skip to content

Commit

Permalink
recursive binary search
Browse files Browse the repository at this point in the history
  • Loading branch information
abdoulayegk committed Jul 22, 2020
1 parent 01e1a31 commit a6774ed
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions recursive_bs.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
""" In this programme we are going to implement binary search tree using recursion method"""

def recursive_bs(array,target,low,high):
while(low <= high):
mid = (low+high )//2
if (target == array[mid]):
return array[mid]
elif (target < array[mid]):
return recursive_bs(array,target,low,mid-1)
elif (target > array[mid]):
return recursive_bs(array,target,mid+1, high)
print('Element not found in the array ')
return False

#arr = [12,14,17,18,19,22,25,28,30]
#print(recursive_bs(arr,1,0,len(arr)))
n=int(input("Enter the number of elements in your list:\n"))
array = []
for i in range(n):
array.append(int(input('Enter the element into your array:\n')))

array.sort()

target =int(input("Enter the element you are looking for:\n"))
print(recursive_bs(array,target,0,len(array)))

0 comments on commit a6774ed

Please sign in to comment.