Merge Sort Algorithm
Merge Sort (divides input array in two halves, calls itself for the two halves and then merges the two sorted halves recursively)
Time-complexity: O(nlogn),Auxiliary Space: O(n),Stable Algorithmic Paradigm: Divide and Conquer Uses: Sorting linked lists(implementation details differ), Counting inversions in array
Algorithm:
MergeSort(arr[], l, r)
* If r > l
* 1. Find the middle point to divide the array into two halves:
* middle m = (l+r)/2
* 2. Call mergeSort for first half:
* Call mergeSort(arr, l, m)
* 3. Call mergeSort for second half:
* Call mergeSort(arr, m+1, r)
* 4. Merge the two halves sorted in step 2 and 3:
* Call merge(arr, l, m, r)