From 7d3e4ebe050d44e0f65d3145df414a9e7dee6f71 Mon Sep 17 00:00:00 2001 From: brendanAlbert Date: Mon, 1 Oct 2018 20:56:32 -0700 Subject: [PATCH] Update binary_search.py --- sorting/binary_search.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/sorting/binary_search.py b/sorting/binary_search.py index afcfbaa..05429b0 100644 --- a/sorting/binary_search.py +++ b/sorting/binary_search.py @@ -19,7 +19,7 @@ def binary_search(value, list_to_search): Arguments: value (that we are searching for), list_to_search (the list) - Return: the value if it is found in the list or -1 if the value is not found. + Return: the index of the value if it is found or -1 otherwise. """ search_value = -1 @@ -31,7 +31,7 @@ def binary_search(value, list_to_search): while max_index >= min_index: if current_element == value: - return current_element + return middle_index elif value > current_element: min_index = middle_index + 1 @@ -42,7 +42,7 @@ def binary_search(value, list_to_search): middle_index = int(math.floor( (min_index + max_index) / 2)) current_element = list_to_search[middle_index] - return search_value + return middle_index id_list = [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20] 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