Divide-and-conquer sorting is built on one primitive: combining two lists that are already sorted into a single sorted list, in linear time.
Write merge(a, b) where a and b are each already sorted in ascending order. Return a NEW list containing every element of both, in sorted order.
Requirements:
This linear-time merge is the engine behind merge sort in the next step.
def merge(a, b):
"""Merge two already-sorted lists into a single sorted list."""
# TODO: use two pointers i, j; append the smaller head each time, then the tail.
pass
The editor and the test runner need a wide screen. Open this page on a desktop browser and your progress will be waiting.
Divide-and-conquer sorting is built on one primitive: combining two lists that are already sorted into a single sorted list, in linear time.
Write merge(a, b) where a and b are each already sorted in ascending order. Return a NEW list containing every element of both, in sorted order.
Requirements:
This linear-time merge is the engine behind merge sort in the next step.
Press Run Tests or ββ© to check your solution.