Created
May 10, 2017 17:29
-
-
Save andrewsouthard1/3790bc7ed64a492f3e6bc2bcb519f77d to your computer and use it in GitHub Desktop.
Binary Search - First Draft
This file contains hidden or 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 binary_search(n, arr) | |
middle = arr[arr.length / 2] | |
if middle == n | |
return true | |
elsif middle < n | |
i = middle | |
j = arr.length - 1 | |
middle = i + j / 2 | |
else | |
i = 0 | |
j = middle | |
middle = i + j / 2 | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment