we can translate this algorithm directly into python code def mergesort(nums)put items of nums in ascending order len(numsdo nothing if nums contains or items if split into two sublists / nums nums nums[: ]nums[ :recursively sort each piece mergesort(nums mergesort(nums merge the sorted pieces back into original list merge(nums nums numsyou might try tracing this algorithm with small list (say eight elements)just to convince yourself that it really works in generalthoughtracing through recursive algorithms can be tedious and often not very enlightening recursion is closely related to mathematical inductionand it requires practice before it becomes comfortable as long as you follow the rules and make sure that every recursive chain of calls eventually reaches base caseyour algorithms will work you just have to trust and let go of the grungy details let python worry about that for youcomparing sorts now that we have developed two sorting algorithmswhich one should we usebefore we actually try them outlet' do some analysis as in the searching problemthe difficulty of sorting list depends on the size of the list we need to figure out how many steps each of our sorting algorithms requires as function of the size of the list to be sorted take look back at the algorithm for selection sort rememberthis algorithm works by first finding the smallest itemthen finding the smallest of the remaining itemsand so on suppose we start with list of size in order to find the smallest valuethe algorithm has to inspect each of the items the next time around the outer loopit has to find the smallest of the remaining items the third time aroundthere are items of interest this process continues until there is only one item left to place thusthe total number of iterations of the inner loop for the selection sort can be computed as the sum of decreasing sequence ( ( ( in other wordsthe time required by selection sort to sort list of items is proportional to the sum of the first whole numbers there is well-known formula for this sumbut even if you do not know the formulait is easy to derive if you add the first and last numbers in the series you get adding the second and second to last values gives ( if you keep pairing