Non recursive merge sort program




















On the debug version, the required time is about The following is a non-recursive version of my own, because the code is really rubbish, neither debug nor release has any advantages, so I will not do a specific analysis, and the reader will check it by himself. Let's do a thorough optimization of the above code, and remove some unnecessary redundant calculations, such as calculating the specific number of merges, and removing repeated assignment operations to obtain relatively efficient code.

Obviously, the efficiency of the Debug version is faster than the recursive version, but the optimized efficiency of the Release version is still not as good as the recursive version. Obviously, in some cases, the recursive form of writing, although it is difficult to understand, in fact, the mathematical induction is good, it is not difficult to write correct recursive code , the practicality is poor, and many people do not recommend it for the readability of the code.

Write recursive form, although the form is concise. Even in general, the recursive writing method will lose efficiency due to frequent stacking and popping. But the fact may not be the case. The optimization of recursive functions by compilers is sometimes obviously stronger than that of general non-recursive algorithms. Improve Article. Save Article. Like Article. Recursive Python Program for merge sort. First merge subarrays of. First merge subarrays. Iterative Merge sort Bottom Up.

Increasing sub array size by powers of 2. WriteLine "" ;. Next QuickSort. Improve this question. Aishwat Singh Aishwat Singh 3, 1 1 gold badge 24 24 silver badges 43 43 bronze badges. I think you can come up with some approach just by spending 20minutes reading standard literature.

Now read my sentence again. Wiki has a minimal example of bottom up merge sort. By minimal, I mean it uses min to check for end of array, it copies data instead of swapping pointers, and merge does a lot of conditional checks for every element moved.

Add a comment. Active Oldest Votes. Improve this answer. Sign up or log in Sign up using Google. Sign up using Facebook. Sign up using Email and Password.



0コメント

  • 1000 / 1000