Skip to content

Instantly share code, notes, and snippets.

@visualsayed
visualsayed / ruby_binary_search.rb
Last active August 28, 2022 00:51
Implementing binary search in ruby
# recursive implementation of binary search in Ruby
def search(arr, val, start_index, end_index)
median = (start_index + end_index) / 2
if(arr[median] == val)
puts "#{val} is in this list."
elsif(start_index >= end_index)
puts "#{val} is not in this list."
else
if(val > arr[median])