The Merge Sort is a popular O(n log n) sorting algorithm, which has been discussed in detail, with examples and C code over here :Arrays and Sorting: Merge Sort ( with C Program source code). Over here, we will take a quick look at the Ruby implementation of Merge Sort.
def mergeArrays(arr,start_1,end_1,start_2,end_2)
temp = Array.new(end_1 + end_2 - start_1 - start_2 +2) index_1 = start_1 # Marks the index in the first sub-array, which needs to be put into the temporary array next index_2 = start_2 # Marks the index in the second sub-array, which needs to be put into the temporary array next index = 0# Mark the index in the Temporary array which is being filled