Browse Source
Merge pull request #7 from Kishan-Srivastava/master
Searching_Algo
pull/10/head
Jeffery Russell
6 years ago
committed by
GitHub
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with
18 additions and
0 deletions
-
searching_algo/binary_search.py
-
searching_algo/linera_search.py
|
|
@ -0,0 +1,12 @@ |
|
|
|
def binary_search(arr,element): |
|
|
|
lower = 0 |
|
|
|
upper = len(arr) - 1 |
|
|
|
while(lower < upper): |
|
|
|
mid = (lower + (upper - 1)) // 2 |
|
|
|
if arr[mid] > element: |
|
|
|
upper = mid-1 |
|
|
|
elif arr[mid] < element: |
|
|
|
lower = mid + 1 |
|
|
|
else: |
|
|
|
return True |
|
|
|
return False |
|
|
@ -0,0 +1,6 @@ |
|
|
|
def linear_search(arr, element): |
|
|
|
for i in arr: |
|
|
|
if i == element: |
|
|
|
return True |
|
|
|
return False |
|
|
|
|