10. merge sort

# Divide & Conquer


time: O
(NlogN)    space: 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
(left = low) & (right = mid+1)
and break the array into intervals : (left to mid), (right 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

Popular posts from this blog

30.) DP on subsequences

Sub-arrays

41. Heaps (striver sheet)