|
|
|
@ -11,14 +11,14 @@ Like **[QuickSort](https://github.com/Dentrax/Data-Structures-with-Go/tree/mast
|
|
|
|
|
MergeSort(arr[], l, r)
|
|
|
|
|
--------------------------
|
|
|
|
|
|
|
|
|
|
If r > l
|
|
|
|
|
* 1. Find the middle point to divide the array into two halves:
|
|
|
|
|
* 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:
|
|
|
|
|
* 2. Call mergeSort for first half:
|
|
|
|
|
Call mergeSort(arr, l, m)
|
|
|
|
|
* 3. Call mergeSort for second half:
|
|
|
|
|
* 3. Call mergeSort for second half:
|
|
|
|
|
Call mergeSort(arr, m+1, r)
|
|
|
|
|
* 4. Merge the two halves sorted in step 2 and 3:
|
|
|
|
|
* 4. Merge the two halves sorted in step 2 and 3:
|
|
|
|
|
Call merge(arr, l, m, r)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -30,10 +30,6 @@ The following diagram from **[Wikipedia](https://en.wikipedia.org/wiki/File:Mer
|
|
|
|
|
> * Output: Given array is `12 11 13 5 6 7`
|
|
|
|
|
> * Output: Sorted array is `5 6 7 11 12 13`
|
|
|
|
|
|
|
|
|
|
> * Input: Rotation of the above array by `2` will make array
|
|
|
|
|
> * Output: `3 4 5 6 7 1 2`
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
**Algorithm Complexity**
|
|
|
|
|
|
|
|
|
|
| Complexity | Notation |
|
|
|
|
|