diff --git a/algorithms/1_BinarySearch/binarysearch.py b/algorithms/1_BinarySearch/binarysearch.py index ed3413e..6b4e9d6 100644 --- a/algorithms/1_BinarySearch/binarysearch.py +++ b/algorithms/1_BinarySearch/binarysearch.py @@ -32,9 +32,6 @@ def binary_search_recursive(numbers_list, number_to_find, left_index, right_inde return -1 mid_index = (left_index + right_index) // 2 - if mid_index >= len(numbers_list) or mid_index < 0: - return -1 - mid_number = numbers_list[mid_index] if mid_number == number_to_find: @@ -51,5 +48,5 @@ def binary_search_recursive(numbers_list, number_to_find, left_index, right_inde numbers_list = [12, 15, 17, 19, 21, 24, 45, 67] number_to_find = 21 - index = binary_search_recursive(numbers_list, number_to_find, 0, len(numbers_list)) - print(f"Number found at index {index} using binary search") \ No newline at end of file + index = binary_search_recursive(numbers_list, number_to_find, 0, len(numbers_list)-1) + print(f"Number found at index {index} using binary search")
Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.
Alternative Proxies: