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
#!/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] |
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
#!/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 |