Question: Consider the pseudo-code below for both insertion sort and merge sort. Re-write the for-loop as a while loop in the merge sort pseudo-code. (You do

Consider the pseudo-code below for both insertion sort and merge sort. Re-write the for-loop as a while loop in the merge sort pseudo-code. (You do not need to show the modified while-loop merge sort.) Then count how many lines need to execute to sort the array [3, 2, 1] for both algorithms. Show some work to receive full (and partial) credit. Only count lines the computer thinks on. Note: for merge sort, do not count the function calls, splits or array creation. Just the number of lines inside the merge function. Also, assume no work needs to be done merging a size 1 and 0 array. (Example: sorting [2, 1] with insertion sort 11 lines, merge 14 lines.) TopDownMerge(A, iBegin, iMiddle, iEnd, BI) Merge sort iiBegin, j- iMiddle; //11 Le Lnere are elements in the left or right runs.. for (k iBegin; k = and A[j] > x end while i-i1 end while
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
