Skip to content

Instantly share code, notes, and snippets.

@andrewsouthard1
Last active May 10, 2017 18:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save andrewsouthard1/0559badbfdcbc25c79499dd4be84995a to your computer and use it in GitHub Desktop.
Save andrewsouthard1/0559badbfdcbc25c79499dd4be84995a to your computer and use it in GitHub Desktop.
Binary Search - After Comments
def binary_search(n, arr)
middle = arr[arr.length / 2]
i = 0
j = arr.length - 1
while i < j
if middle == n
return true
elsif middle < n
i = middle
middle = i + j / 2
else
p "Middle is greater than n"
j = middle
p "j: #{j}"
middle = i + j / 2
p "middle: #{middle}"
end
end
false
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment