Created
March 9, 2023 17:16
-
-
Save NicolaM94/6ae1707c1ff234e2dc93ae47988ac7da to your computer and use it in GitHub Desktop.
Binary search implementation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def binarySearch (array, element): | |
a = 1 | |
b = len(array) | |
while array[int((a+b)/2)] != element: | |
m = int((a+b)/2) | |
if (array[m]) > element: | |
b = m - 1 | |
else: | |
a = m + 1 | |
if a > b: | |
return False | |
return True |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment