Doubt regarding function calling

when we called merge sort function for the first sort we started creating branches of elements till we hit a single element…and then according to the base case we return to the previous call. After that why function merge will run when merge sort of mid+1-e array is there. I didn’t understand that point when we call mergesort again and again and then why sorting function( in this case merge() )will be called after merge sort

@aryaman.kumar26
pehle hum mid nikal rahe hai
phir ab hamare paa do array aa gayi,
ek s se mid tak aur dusri mid+1 se e tak.
hum ab mergesort in dono array par call kar rahe hai taaki ye dono array sort ho jaye.
ab iske baad jab dono array sort ho ke aa jayegi tab hum merge function call kareneg jo in dono sorted array ko merge kar dega aur ek final sorted array dega.

bus itna hi hai merge sort.

aur merge algorithm same hai merging of two sorted hai.
to tumhe bhi merging algorithm samajhna hai ,
agar abh bhi samaj nahi aaya to video ek baar phir dekho , sayad samjh aa jaye.

ek baar ye recursion tree dekho sayad samajh aa jaye


hope its clear if yes dont forget to hit like and mark resolved :smiley:

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.

In 4,5,8 steps when we have reached to one element, our base case returns then what happens

@aryaman.kumar26,
Then the merge function will merge two elements to make a subarray of size 2 {38,27}.
Try dry run on pen and paper, it always gives insight of whats actually happening.

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.