Sort by splitting and merging
Merge sort splits the list in half, sorts each half recursively and merges the two sorted halves. Merging needs only one pass because the smallest remaining item is always at the front of one half.
left, right = [1, 4], [2, 3]
# take 1, then 2, then 3, then 4Think before coding
There are about log2(n) levels of splitting and each level merges n items, so the total is n log n. Taking from the left half when values are equal keeps the sort stable. Work through the example by hand before changing the starter. Decide what should happen for an empty input, a single value and a repeated value where those cases apply. The checks use several inputs so a hard-coded answer cannot stand in for the rule.
Your task
Write merge_sort(items) returning a new sorted list using merge sort, without sorted or list.sort.
The explanation opens here once every check passes.