From 4856f3030983130f85d6d44a557e1af3135d14c0 Mon Sep 17 00:00:00 2001 From: Kavin18 <148603725+Kavin56@users.noreply.github.com> Date: Fri, 17 May 2024 15:16:56 +0530 Subject: [PATCH] Delete Searching algorithms directory --- Searching algorithms/Binary search.py | 31 ------------- Searching algorithms/Exponential Search.py | 39 ---------------- Searching algorithms/Fibonacci Search.py | 49 -------------------- Searching algorithms/Interpolation Search.py | 32 ------------- Searching algorithms/Jump Search.py | 33 ------------- Searching algorithms/Linear search.py | 18 ------- Searching algorithms/Meta Binary Search.py | 18 ------- Searching algorithms/Sentinel Search.py | 22 --------- Searching algorithms/Ternary Search.py | 32 ------------- 9 files changed, 274 deletions(-) delete mode 100644 Searching algorithms/Binary search.py delete mode 100644 Searching algorithms/Exponential Search.py delete mode 100644 Searching algorithms/Fibonacci Search.py delete mode 100644 Searching algorithms/Interpolation Search.py delete mode 100644 Searching algorithms/Jump Search.py delete mode 100644 Searching algorithms/Linear search.py delete mode 100644 Searching algorithms/Meta Binary Search.py delete mode 100644 Searching algorithms/Sentinel Search.py delete mode 100644 Searching algorithms/Ternary Search.py diff --git a/Searching algorithms/Binary search.py b/Searching algorithms/Binary search.py deleted file mode 100644 index e000128..0000000 --- a/Searching algorithms/Binary search.py +++ /dev/null @@ -1,31 +0,0 @@ - -def binary_search(arr, target): - low = 0 - high = len(arr) - 1 - - while low <= high: - mid = (low + high) // 2 - mid_val = arr[mid] - - if mid_val == target: - return mid - elif mid_val < target: - low = mid + 1 - else: - high = mid - 1 - - return -1 - -def main(): - arr = list(map(int, input("Enter the array elements: ").split())) - arr.sort() - target = int(input("Enter the number to search for: ")) - - index = binary_search(arr, target) - if index != -1: - print(f"{target} found at index {index}.") - else: - print(f"{target} not found.") - -if __name__ == "__main__": - main() diff --git a/Searching algorithms/Exponential Search.py b/Searching algorithms/Exponential Search.py deleted file mode 100644 index ed878d5..0000000 --- a/Searching algorithms/Exponential Search.py +++ /dev/null @@ -1,39 +0,0 @@ -def binarySearch( arr, l, r, x): - if r >= l: - mid = l + ( r-l ) // 2 - - - if arr[mid] == x: - return mid - - if arr[mid] > x: - return binarySearch(arr, l, - mid - 1, x) - - return binarySearch(arr, mid + 1, r, x) - - return -1 - -def exponentialSearch(arr, n, x): - - if arr[0] == x: - return 0 - - - i = 1 - while i < n and arr[i] <= x: - i = i * 2 - - return binarySearch( arr, i // 2, - min(i, n-1), x) - - -arr = list(map(int,input("Enter the array elements: ").split())) -n = len(arr) -x = int(input("enter the number to search: ")) -result = exponentialSearch(arr, n, x) -if result == -1: - print ("Element not found in the array") -else: - print ("Element is present at index %d" %(result)) - diff --git a/Searching algorithms/Fibonacci Search.py b/Searching algorithms/Fibonacci Search.py deleted file mode 100644 index ebd056c..0000000 --- a/Searching algorithms/Fibonacci Search.py +++ /dev/null @@ -1,49 +0,0 @@ -from bisect import bisect_left - -def fibMonaccianSearch(arr, x, n): - - fibMMm2 = 0 - fibMMm1 = 1 - fibM = fibMMm2 + fibMMm1 - - while (fibM < n): - fibMMm2 = fibMMm1 - fibMMm1 = fibM - fibM = fibMMm2 + fibMMm1 - - offset = -1 - - while (fibM > 1): - - i = min(offset+fibMMm2, n-1) - - - if (arr[i] < x): - fibM = fibMMm1 - fibMMm1 = fibMMm2 - fibMMm2 = fibM - fibMMm1 - offset = i - - - elif (arr[i] > x): - fibM = fibMMm2 - fibMMm1 = fibMMm1 - fibMMm2 - fibMMm2 = fibM - fibMMm1 - - else: - return i - - if(fibMMm1 and arr[n-1] == x): - return n-1 - - return -1 - - -arr = list(map(int,input("Enter the array elements: ").split())) -n = len(arr) -x = int(input("enter the number to search: ")) -ind = fibMonaccianSearch(arr, x, n) -if ind>=0: - print("Found at index:",ind) -else: - print(x,"isn't present in the array"); diff --git a/Searching algorithms/Interpolation Search.py b/Searching algorithms/Interpolation Search.py deleted file mode 100644 index f78c49f..0000000 --- a/Searching algorithms/Interpolation Search.py +++ /dev/null @@ -1,32 +0,0 @@ -def interpolationSearch(arr, lo, hi, x): - - - if (lo <= hi and x >= arr[lo] and x <= arr[hi]): - - - pos = lo + ((hi - lo) // (arr[hi] - arr[lo]) * - (x - arr[lo])) - - if arr[pos] == x: - return pos - - if arr[pos] < x: - return interpolationSearch(arr, pos + 1, - hi, x) - - if arr[pos] > x: - return interpolationSearch(arr, lo, - pos - 1, x) - return -1 - -arr = list(map(int,input("Enter the array elements: ").split())) -n = len(arr) - -x = int(input("enter the number to search: ")) -index = interpolationSearch(arr, 0, n - 1, x) - -if index != -1: - print("Element found at index", index) -else: - print("Element not found") - diff --git a/Searching algorithms/Jump Search.py b/Searching algorithms/Jump Search.py deleted file mode 100644 index 5e687d8..0000000 --- a/Searching algorithms/Jump Search.py +++ /dev/null @@ -1,33 +0,0 @@ -arr = list(map(int, input("Enter the array elements : ").split())) - -import math - -def jump_search(arr, target): - n = len(arr) - arr.sort() # Ensure array is sorted - step = int(math.sqrt(n)) - prev = 0 - - while arr[min(step, n)-1] < target: - prev = step - step += int(math.sqrt(n)) - if prev >= n: - return -1 - - while arr[prev] < target: - prev += 1 - if prev == min(step, n): - return -1 - - if arr[prev] == target: - return prev - - return -1 - -target = int(input("Enter the number to search for: ")) - -index = jump_search(arr, target) -if index != -1: - print(f"{target} found at index {index}.") -else: - print(f"{target} not found in the array.") diff --git a/Searching algorithms/Linear search.py b/Searching algorithms/Linear search.py deleted file mode 100644 index f48fd4e..0000000 --- a/Searching algorithms/Linear search.py +++ /dev/null @@ -1,18 +0,0 @@ -def search(arr, N, x): - - for i in range(0, N): - if (arr[i] == x): - return i - return -1 - - -if __name__ == "__main__": - arr = list(map(int,input("enter the array elements: ").split())) - x = int(input("enter the number to search: ")) - N = len(arr) - - result = search(arr, N, x) - if(result == -1): - print("Element is not present in array") - else: - print("Element is present at index", result) diff --git a/Searching algorithms/Meta Binary Search.py b/Searching algorithms/Meta Binary Search.py deleted file mode 100644 index 788e625..0000000 --- a/Searching algorithms/Meta Binary Search.py +++ /dev/null @@ -1,18 +0,0 @@ -import math - -def bsearch(A, key_to_search): - n = len(A) - lg = int(math.log2(n-1)) + 1 - pos = 0 - for i in range(lg - 1, -1, -1): - if A[pos] == key_to_search: - return pos - new_pos = pos | (1 << i) - if new_pos < n and A[new_pos] <= key_to_search: - pos = new_pos - return pos if A[pos] == key_to_search else -1 - -if __name__ == "__main__": - A = list(map(int, input("Enter the array elements: ").split())) - key = int(input("Enter the number to search: ")) - print(bsearch(A, key)) diff --git a/Searching algorithms/Sentinel Search.py b/Searching algorithms/Sentinel Search.py deleted file mode 100644 index 84bc4cc..0000000 --- a/Searching algorithms/Sentinel Search.py +++ /dev/null @@ -1,22 +0,0 @@ -def sentinelSearch(arr, n, key): - - last = arr[n - 1] - - arr[n - 1] = key - i = 0 - - while (arr[i] != key): - i += 1 - - arr[n - 1] = last - - if ((i < n - 1) or (arr[n - 1] == key)): - print(key, "is present at index", i) - else: - print("Element Not found") - -arr = list(map(int,input("Enter the array elements: ").split())) -n = len(arr) -key = int(input("enter the number to search: ")) - -sentinelSearch(arr, n, key) diff --git a/Searching algorithms/Ternary Search.py b/Searching algorithms/Ternary Search.py deleted file mode 100644 index 1cce21d..0000000 --- a/Searching algorithms/Ternary Search.py +++ /dev/null @@ -1,32 +0,0 @@ -import math as mt - -def ternarySearch(l, r, key, ar): - if (r >= l): - mid1 = l + (r - l) //3 - mid2 = r - (r - l) //3 - - if (ar[mid1] == key): - return mid1 - if (ar[mid2] == key): - return mid2 - - if (key < ar[mid1]): - return ternarySearch(l, mid1 - 1, key, ar) - elif (key > ar[mid2]): - return ternarySearch(mid2 + 1, r, key, ar) - else: - return ternarySearch(mid1 + 1, mid2 - 1, key, ar) - - return -1 - -l, r = 0, 9 -ar = [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 ] -l = 0 -r = 9 -key = 5 -p = ternarySearch(l, r, key, ar) -print("Index of", key, "is", p) - -key = 50 -p = ternarySearch(l, r, key, ar) -print("Index of", key, "is", p)