-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
01e1a31
commit a6774ed
Showing
1 changed file
with
26 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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))) | ||
|