Skip to content

Commit 513142c

Browse files
committed
Binary Search using While Loop and recursion
1 parent fca5654 commit 513142c

1 file changed

Lines changed: 35 additions & 0 deletions

File tree

DSA/Binary_search.py

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,3 +76,38 @@ def binarysearch(arr,target):
7676
# Average Case: O(log N)
7777
# Worst Case: O(log N)
7878
# Auxiliary Space: O(1), If the recursive call stack is considered then the auxiliary space will be O(logN).
79+
80+
81+
# Binary Search using While Loop
82+
# def search(arr,l,r,v):
83+
# while l<=r:
84+
# mid=l+(r-1)//2
85+
# if arr[mid]==v:
86+
# return mid
87+
# elif arr[mid]<r:
88+
# l=mid+1
89+
# else:
90+
# r=mid-1
91+
# return -1
92+
93+
94+
# Binary Search using Recursion
95+
# def search(arr,l,r,v):
96+
# if l<=r:
97+
# mid=l+(r-1)//2
98+
# if arr[mid]==v:
99+
# return mid
100+
# elif arr[mid]>r:
101+
# return search(arr,l,mid-1,v)
102+
# else:
103+
# return search(arr,mid+1,r,v)
104+
# return -1
105+
106+
107+
108+
# arr=[int(x)for x in input('array').split(",")]
109+
# v=int(input())
110+
# result=search(arr,0,len(arr),v)
111+
# print(result)
112+
113+

0 commit comments

Comments
 (0)