Merge Sort
Last updated
Was this helpful?
Last updated
Was this helpful?
Like, Merge Sort is aalgorithm. It divides input array in two halves, calls itself for the two halves and then merges the two sorted halves.The merge() functionis used for merging two halves. The merge(arr, l, m, r) is key process that assumes that arr[l..m] and arr[m+1..r] are sorted and merges the two sorted sub-arrays into one. See following C implementation for details.
The following diagram fromshows the complete merge sort process for an example array {38, 27, 43, 3, 9, 82, 10}. If we take a closer look at the diagram, we can see that the array is recursively divided in two halves till the size becomes 1. Once the size becomes 1, the merge processes comes into action and starts merging arrays back till the complete array is merged.