added recursive binary search

This commit is contained in:
2026-03-03 18:09:02 -05:00
parent d9414d044c
commit 1d5e02949a

View File

@@ -42,7 +42,9 @@ class Search:
print("Not found.")
return checks
"""
This function pre
"""
def linear_search_count(self, arr, target):
checks = 0
for value in arr:
@@ -52,6 +54,19 @@ class Search:
return checks
def binary_search_recursive(self, arr, target, low, high):
if low > high:
return -1
mid = (low + high) // 2
if arr[mid] == target:
return mid
elif arr[mid] < target:
return self.binary_search_recursive(arr, target, mid + 1, high)
else:
return self.binary_search_recursive(arr, target, low, mid - 1)
### write your tests in main function
def main():