Database System Concepts
Database System Concepts
7th Edition
ISBN: 9780078022159
Author: Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher: McGraw-Hill Education
Bartleby Related Questions Icon

Related questions

bartleby

Concept explainers

Question

Please written by computer source

Attached is the pseudocode for the Merge algorithm. When this algorithm is called with Merge (A, 1, 4, 8) with A = (4, 6, 8, 9, 2, 5, 10, 12), how many times does line 15 execute? How many times does line 17 execute? How many times does line 22 execute? How many times does line 26 execute?

MERGE(A, p, q, r)
1
2
3 let L[0:n
4
5
12
13
14
15
16
6 for j = 0 to nR-1 // copy Alq +1:r] into R[0:nR - 1]
R[j] = A[q+j+1]
7
8
nL = q-p+1
nR = r-q
i=0
9 j = 0
// i indexes the smallest remaining element in L
//j indexes the smallest remaining element in R
// k indexes the location in A to fill
10 k
P
11
// 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 i <n and j<nr
if L[i] ≤ R[j]
A[k] = L[i]
i=i+1
else A[k] = R[j]
j=j+1
20
21
22
23
24
25
// length of A[p:q]
// length of Alq +1:r]
1] and R[0:nR - 1] be new arrays
for i = 0 to n-1 // copy A[p:q] into L[0:n₁ - 1]
L[i] = A[p + i]
17
18
k=k+1
19 // Having gone through one of L and R entirely, copy the
remainder of the other to the end of A[p:r].
//
26
27
while i <nL
A[k] = L[i]
i=i+1
k=k+1
while j<nR
A[k] = R[j]
j=j+1
k=k+1
expand button
Transcribed Image Text:MERGE(A, p, q, r) 1 2 3 let L[0:n 4 5 12 13 14 15 16 6 for j = 0 to nR-1 // copy Alq +1:r] into R[0:nR - 1] R[j] = A[q+j+1] 7 8 nL = q-p+1 nR = r-q i=0 9 j = 0 // i indexes the smallest remaining element in L //j indexes the smallest remaining element in R // k indexes the location in A to fill 10 k P 11 // 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 i <n and j<nr if L[i] ≤ R[j] A[k] = L[i] i=i+1 else A[k] = R[j] j=j+1 20 21 22 23 24 25 // length of A[p:q] // length of Alq +1:r] 1] and R[0:nR - 1] be new arrays for i = 0 to n-1 // copy A[p:q] into L[0:n₁ - 1] L[i] = A[p + i] 17 18 k=k+1 19 // Having gone through one of L and R entirely, copy the remainder of the other to the end of A[p:r]. // 26 27 while i <nL A[k] = L[i] i=i+1 k=k+1 while j<nR A[k] = R[j] j=j+1 k=k+1
Expert Solution
Check Mark
Knowledge Booster
Background pattern image
Computer Science
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
Recommended textbooks for you
Text book image
Database System Concepts
Computer Science
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:McGraw-Hill Education
Text book image
Starting Out with Python (4th Edition)
Computer Science
ISBN:9780134444321
Author:Tony Gaddis
Publisher:PEARSON
Text book image
Digital Fundamentals (11th Edition)
Computer Science
ISBN:9780132737968
Author:Thomas L. Floyd
Publisher:PEARSON
Text book image
C How to Program (8th Edition)
Computer Science
ISBN:9780133976892
Author:Paul J. Deitel, Harvey Deitel
Publisher:PEARSON
Text book image
Database Systems: Design, Implementation, & Manag...
Computer Science
ISBN:9781337627900
Author:Carlos Coronel, Steven Morris
Publisher:Cengage Learning
Text book image
Programmable Logic Controllers
Computer Science
ISBN:9780073373843
Author:Frank D. Petruzella
Publisher:McGraw-Hill Education