Browse Source

Merge pull request #7 from Kishan-Srivastava/master

Searching_Algo
pull/10/head
Jeffery Russell 5 years ago
committed by GitHub
parent
commit
7993c5c6c2
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 18 additions and 0 deletions
  1. +12
    -0
      searching_algo/binary_search.py
  2. +6
    -0
      searching_algo/linera_search.py

+ 12
- 0
searching_algo/binary_search.py View File

@ -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

+ 6
- 0
searching_algo/linera_search.py View File

@ -0,0 +1,6 @@
def linear_search(arr, element):
for i in arr:
if i == element:
return True
return False

Loading…
Cancel
Save