Skip to content

Instantly share code, notes, and snippets.

View suganya-sangith's full-sized avatar

Suganya Gnanasekar suganya-sangith

  • Thoughtworks
  • Chennai
View GitHub Profile
@suganya-sangith
suganya-sangith / binary_search.rb
Created November 12, 2018 12:40
Binary search algorithm in Ruby
#!/home/suganya/.rvm/rubies/ruby-2.4.1/bin/ruby
require "byebug"
class BinarySearch
def search(arr, element_to_search)
if arr.length == 1
return arr[0] == element_to_search ? arr[0] : "No match found"
else
mid_element_index = middle_element(arr)
mid_element = arr[mid_element_index]
@suganya-sangith
suganya-sangith / merge_sort.rb
Last active November 4, 2018 18:43
Sorting Algorithms
#!/home/suganya/.rvm/rubies/ruby-2.4.1/bin/ruby
require "byebug"
module MergeSort
def self.partition(array)
if array.length == 0
return []
elsif array.length == 1
return array
end