Answered step by step
Verified Expert Solution
Question
1 Approved Answer
MERGE.A; p; q; r / 1 nL D q p C 1 / / length of A p W q 2 nR D r q
MERGE.A; p; q; r
nL D q p C length of Ap W q
nR D r q length of Aq C W r
let L W nL and R W nR be new arrays
for i D to nL copy Ap W q into L W nL
Li D Ap C i
for j D to nR copy Aq C W r into R W nR
Rj D Aq C j C
i D i indexes the smallest remaining element in L
j D j indexes the smallest remaining element in R
k D p k indexes the location in A to ll
As long as each of the arrays L and R contains an unmerged element,
copy the smallest unmerged element back into Ap W r
while i nL and j nR
if Li Rj
Ak D Li
i D i C
else Ak D Rj
j D j C
k D k C
Having gone through one of L and R entirely, copy the
remainder of the other to the end of Ap W r
while i nL
Ak D Li
i D i C
k D k C
while j nR
Ak D Rj
j D j C
k D k C
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