From f787bd69bbc3d28066513ddf8f208981bc0dcba3 Mon Sep 17 00:00:00 2001 From: kishan_svt Date: Sat, 13 Oct 2018 07:45:15 +0530 Subject: [PATCH] Searching_Algo --- searching_algo/binary_search.py | 12 ++++++++++++ searching_algo/linera_search.py | 6 ++++++ 2 files changed, 18 insertions(+) create mode 100644 searching_algo/binary_search.py create mode 100644 searching_algo/linera_search.py diff --git a/searching_algo/binary_search.py b/searching_algo/binary_search.py new file mode 100644 index 0000000..c0fba34 --- /dev/null +++ b/searching_algo/binary_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 diff --git a/searching_algo/linera_search.py b/searching_algo/linera_search.py new file mode 100644 index 0000000..0e31b10 --- /dev/null +++ b/searching_algo/linera_search.py @@ -0,0 +1,6 @@ +def linear_search(arr, element): + for i in arr: + if i == element: + return True + return False +