Space Complexity of the Merge Sort Algorithm

  No need of using several arrays at each stage. Why not simply work on the original array since it is all about swapping? You get it! That's the basic idea. All that is required at most, as can be seen inside the above Merge function is an array of equal size to the given array i.e. combined size of the L and H sub-arrays which is at most, the full size of the given array to be sorted. Note that we  continually reuse the arrays L and H and not create new ones at each step because once one merge function is done, when another is called for the next step, the former L and H are no longer in view (out of scope)

No comments:

Post a Comment

Popular Posts