diff --git a/algorithms/sorting/binary_search.py b/algorithms/sorting/binary_search.py index afcfbaa..cef4e2b 100644 --- a/algorithms/sorting/binary_search.py +++ b/algorithms/sorting/binary_search.py @@ -25,10 +25,11 @@ def binary_search(value, list_to_search): search_value = -1 max_index = len(list_to_search) - 1 min_index = 0 - middle_index = int(math.floor( (max_index + min_index) / 2)) - current_element = list_to_search[middle_index] - + while max_index >= min_index: + + middle_index = int(math.floor( (min_index + max_index) / 2)) + current_element = list_to_search[middle_index] if current_element == value: return current_element @@ -38,10 +39,7 @@ def binary_search(value, list_to_search): elif value < current_element: max_index = middle_index - 1 - - middle_index = int(math.floor( (min_index + max_index) / 2)) - current_element = list_to_search[middle_index] - + return search_value pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

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:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy