Answered step by step
Verified Expert Solution
Question
1 Approved Answer
please help, I'm lost... Suppose that we add a command to the MERGE procedure right before line 12 (see p. 31) asking whether L[11] (the
please help, I'm lost...
Suppose that we add a command to the MERGE procedure right before line 12 (see p. 31) asking whether L[11] (the last element of L before the sentinel) is smaller than R[1]. If that is the case, we know that the array consisting of the subarray L followed by the subarray R, is sorted in increasing order and no more comparisons are needed. Otherwise, if L[11]>R[1], the algorithm proceeds as before. Call this the "modified merge procedure" MMERGE and call MMERGE-SORT the procedure MERGE- SORT that uses MMERGE instead of MERGE. Suppose we run MMERGE-SORT on an array of length n which is already sorted. How many comparisons are needed? Is the running time for this sorted array better than the running time when using MERGE-SORT, Thetan ign) ? Explain using plain English. MERGE(A, p, q,r) 1 ni = q- p + 1 2 n = r-9 3 let L[1..ni + 1] and R[1..n2 + 1] be new arrays 4 for i = 1 to ni 5 L[i] = A[p + i - 1] 6 for j = 1 to n2 7 R[j] = A[q + j] 8 L[ni + 1] = 0 9 R[n2 + 1] = 0 10 i = 1 11 j = 1 12 for k = p tor 13 if L[i]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