79566867

Date: 2025-04-10 14:05:14
Score: 1
Natty:
Report link

The magic of MergeSort() is in the halving of the boundaries of the array. It. In the first call, it sets a mid point of the full array. In the next call, that mid point is passed to back to the function as the "r" or right boundary. That's how it halves the left side of the array down to a 2 item array.

Because it calls itself, mergeSort will keep doing this until the entire left side is broken down. THEN the right side is done in the same fashion. Each call has its own stack frame sorted in memory containing the l, r parameters and the new m variable. And these stack frames are unwound or fed backwards into merge()

Remember, it's not halving the original array, it's halving the indices of the array

Reasons:
  • Long answer (-0.5):
  • No code block (0.5):
  • Low reputation (1):
Posted by: adam daudrich