![]() |
VOOZH | about |
Merge Sort is a divide-and-conquer algorithm. It divides the input array into two halves, calls itself the two halves, and then merges the two sorted halves. The merge() function is used for merging two halves. The merge(arr, l, m, r) is a key process that assumes that arr[l..m] and arr[m+1..r] are sorted and merges the two sorted sub-arrays into one.
Please refer complete article on for more details.
There are only five steps to understand Merge Sort Algorithm:
- Step 1: Divide Array into Two Parts.
- Step 2: Merge Sort the first part of the array.
- Step 3: Merge Sort the second part of the array.
- Step 4: Merge Both the parts.
- Step 5: Return the Sorted Array
Base Conditions for Merge Sort is: Divide the Array till the size of Array is greater than 1.
5 6 7 11 12 13
Time Complexity: O(n log n)
Auxiliary Space: O(n)
The advantages of Merge Sort are mentioned below:
References: Please refer complete article on Merge Sort for more details.