Question: Q1: Merging Merge Sort with Insertion Sort [Marks 3] Although merge sort runs in o (n log n) worst-case time and insertion sort runs in

 Q1: Merging Merge Sort with Insertion Sort [Marks 3] Although merge

Q1: Merging Merge Sort with Insertion Sort [Marks 3] Although merge sort runs in o (n log n) worst-case time and insertion sort runs in 0 (na) worst-case time, the constant factors in insertion sort can make it faster in practice for small problem sizes on many machines. Thus, it makes sense to coarsen the leaves of the recursion by using insertion sort within merge sort when subproblems become sufficiently small. Consider a modification to merge sort in which sublists at level k of the tree are sorted using insertion sort and then merged using the standard merging routine. The levels of the tree start from 1, i.e. the root node is at level 1. Write a python function named merge_insertion_sort that takes an array A of integer values and a value k from the user (All the values for A are inserted in the same line with space in between as shown below. You must not use any character other than space to separate values). The function recursively creates the tree like in merge sort but rather than creating log n levels by dividing A, the insertion sort is used on the nodes at level k to sort the list at each node. Once the insertion sort has been used on all the subarrays at level k, the merging takes place using Merge Sort Algorithm. Please exactly follow the formatting given below. State any assumption as a comment in your program. You can take the code of Merge Sort ONLY from any online source and then edit it. Order of call to insertion sort shown below can differ. Sample Output of the program: Enter tree_level: 4 Enter List A: 32 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 Insertion Sort output: 1 2 3 4 Insertion Sort output: 5 6 7 8 Insertion Sort output: 9 10 11 12 Insertion Sort output: 13 14 15 16 Insertion Sort output: 17 18 19 20 Insertion Sort output: 21 22 23 24 Insertion Sort output: 25 26 27 28 Insertion Sort output: 29 30 31 32 Sorted List: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!