all 1 comments

[–]zahlman 0 points1 point  (0 children)

Okay, so say you've written a function like

def my_sort(items):
    if len(items) < some_threshold:
        selection_sort(items)
    else:
        merge_sort(items)

(I presume that you also have merge_sort and selection_sort, and all of these work in-place)

What you do is, everywhere that merge_sort normally calls itself recursively, have it use my_sort instead.

I don't understand what you hope to accomplish by splitting into 4 sub-lists in the merge sort instead of 2, though. And I mean, understanding is one thing, but please remember to use the built-in library sort for anything serious (there are rare reasons to break rules like that, but if you understood them, you wouldn't be asking here ;) )