10. merge sort
DIVIDE & CONQUER
time complexity- O(NlogN)
space complexity- O(N)
------------------------------------------------------------------------------------------------------------
For Splitting:-
1. We pass low and high to the function
2. find middle
3. recurse for ( low to mid ) & ( mid+1 to high )
4. call merge function for these low, mid, high
5. done
--------------------------------------------------------------------------------------------------------------------------
For merging:-
we give the function: low, mid, high
and break the array into intervals : (left to mid), (mid+1 to high)
and then use 2 pointer
----------------------
temp goes from i=low to i=high, so at last, we store numbers in array using i-low to make it 0 based index
--------------------------------------------------------------------------------------------------------------------------
Comments
Post a Comment