Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Merge ( A , p , q , r ) n L = q - p + 1 , / / length of A [

Merge(A,p,q,r)
nL=q-p+1,// length of A[p:q]
nR=r-q,// length of A[q+1:r]
let L[0:nL-1] and R[0:nR-1] be new arrays
for i=0 to nL-1,?? copy A[p:q] into L[0:nL-1]
L[i]=A[p+i]
for j=0 to nR-1?? copy A[q+1:r] into R[0:nR-1]
R[j]=A[q+j+1]
i=0,??i indexes the smallest remaining element in L
j=0,??j indexes the smallest remaining element in R
k=p,??k indexes the location in A to fill
// As long as each of the arrays L and R contains an unmerged element,
// copy the smallest unmerged element back into A[p:r].
while L[i]R[j]A[k]=L[i]i=i+1A[k]=R[j]j=j+1k=k+1LRA[p:r]A[k]=L[i]i=i+1k=k+1A[k]=R[j]j=j+1k=k+1j
A[k]=R[j]
j=j+1
k=k+1i
A[k]=L[i]
i=i+1
k=k+1
while j
A[k]=R[j]
j=j+1
k=k+1j
ifL[i]R[j]
A[k]=L[i]
i=i+1
else A[k]=R[j]
j=j+1
k=k+1???
Having gone through one ofL and R entirely, copy the???
remainder of the other to the end ofA[p:r].
while i
A[k]=L[i]
i=i+1
k=k+1
while j
A[k]=R[j]
j=j+1
k=k+1i and j
ifL[i]R[j]
A[k]=L[i]
i=i+1
else A[k]=R[j]
j=j+1
k=k+1???
Having gone through one ofL and R entirely, copy the???
remainder of the other to the end ofA[p:r].
while i
A[k]=L[i]
i=i+1
k=k+1
while j
A[k]=R[j]
j=j+1
k=k+1
State a loop invariant for the while loop of lines 12318 of the MERGE procedure.
Show how to use it, along with the while loops of lines 20323 and 24327, to prove
that the MERGE procedure is correct.
image text in transcribed

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Intelligent Information And Database Systems Second International Conference Acids Hue City Vietnam March 2010 Proceedings Part 1 Lnai 5990

Authors: Manh Thanh Le ,Jerzy Swiatek ,Ngoc Thanh Nguyen

2010th Edition

3642121446, 978-3642121449

More Books

Students also viewed these Databases questions

Question

a valuing of personal and psychological privacy;

Answered: 1 week ago