Question
PYTHON PROGRAMMING: Merge sort is a recursive sorting algorithm that continually splits a list in half following the divide and conquer strategy. Once two halves
PYTHON PROGRAMMING: Merge sort is a recursive sorting algorithm that continually splits a list in half following the divide and conquer strategy. Once two halves are sorted, the fundamental operation merge is performed. Write the functions merge(list1, list2) and merge_sort(numList) to correctly sort a list of numbers. merge_sort is a recursive function that calls merge to return the final sorted list.
Remember:
- If the list is empty or has one item, it is sorted by definition
- Merging is the process of taking two smaller sorted lists and combining them together into a single, sorted, new list
EXAMPLES:
>>> merge_sort([12,35,87,26,9,28,7])
[7, 9, 12, 26, 28, 35, 87] >>> merge([12,26,35,87],[7,9,28])
[7, 9, 12, 26, 28, 35, 87] >>> merge([12,35],[26,87])
[12, 26, 35, 87]
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started