Created
December 19, 2011 05:41
-
-
Save philosodad/1495566 to your computer and use it in GitHub Desktop.
Learn How You Fail
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 binary_search search_array, key | |
if search_array[search_array.length/2] == key then return search_array.length/2 end | |
if search_array[search_array.length/2] < key then binary_search (search_array(search_array.length/2...search_array.length), key) end | |
if search_array[search_array.length/2] > key then binary_search(search_array(0..search_array.length/2), key) end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment