Last active
December 31, 2019 21:56
-
-
Save quantum9Innovation/bd4efea71771613c963fc4c33c88a722 to your computer and use it in GitHub Desktop.
A simple binary search algorithm written in python for searching through arrays in O(log_2(n)) time.
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,target): | |
min = 0 | |
max = len(array)-1 | |
guess = 0 | |
while max>=min: | |
guess = floor((min+max)/2) | |
if array[guess] == target: return guess | |
else if array[guess] < target: min = guess+1 | |
else: max = guess-1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment