Browse Source

Searching_Algo

pull/7/head
kishan_svt 5 years ago
parent
commit
f787bd69bb
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