Skip to content

Instantly share code, notes, and snippets.

@quantum9Innovation
Last active December 31, 2019 21:56
Show Gist options
  • Save quantum9Innovation/bd4efea71771613c963fc4c33c88a722 to your computer and use it in GitHub Desktop.
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.
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