From b8de7242778d509e06403228a064dbcfa71dd990 Mon Sep 17 00:00:00 2001 From: Jyotika Date: Wed, 30 Oct 2019 09:16:34 +0530 Subject: [PATCH] added exponential searching algo --- searching_algo/exponentialSearch.py | 33 +++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 searching_algo/exponentialSearch.py diff --git a/searching_algo/exponentialSearch.py b/searching_algo/exponentialSearch.py new file mode 100644 index 0000000..607d811 --- /dev/null +++ b/searching_algo/exponentialSearch.py @@ -0,0 +1,33 @@ +def search(arr, l, r, x): + if r >= l: + m = (l+r)/2 + if arr[m] == x: + return m + + if arr[m] > x: + return search(arr, l, m-1, x) + + else: + return search(arr, m, r, x) + + return -1 + +def exponentialSearch(arr, n, x): + + if arr[0] == x: + return 0 + + i = 1 + while i