Apply algorithm 4.5.1 in P.173 with n=6 and A=(3,5,4,1,3,2). Draw the corresponding walkthrough as shown in P.173. No subsequent recursive call to Quicksort is needed

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

Apply algorithm 4.5.1 in P.173 with n=6 and A=(3,5,4,1,3,2). Draw the corresponding walkthrough as shown in P.173. No subsequent recursive call to Quicksort is needed.

Algorithm 4.5.1: QuickSort(p,q)
// Assumes an “external" invocation of the form QuickSort(1, n) and
// (recursively) sorts A[p], A[p + 1],.., A[q] into order:
Begin
If (p < g) Then
M + A[q];
j+p;
For k + p to (q – 1) Do
If (A[k]< M) Then
x- A[j];
A[j] + A[k];
A[k] + x;
j+j+1;
// the if
// the for-k loop
End;
End;
A[q] + A[j];
A[j] + M; // this is the end of the "partitioning"
QuickSort( p,j- 1);
QuickSort(j+1, q ); |/ the second "recursive" sub-call
// the first "recursive" sub-call
// the if-statement at the beginning
// the recursive algorithm
End;
End.
Walkthrough assuming an "external" invocation of the form Q(1, 11); that is,
// QuickSort the array A from position, p = 1 to the last position, q = 11.
A
1= p
q = 11
k
A[k] A[k]<<M
5 7 60 9 821573
5 7 6 0 9 82157 3
5 76 0 9 8 2 1 5 7 3
5 7 60 9 8 2 1 5 7 3
0 76 59 8 2 1 5 7 3
0 7 6 5 9 8 2 1 5 7 3
0 76 5 9 8 2 1 5 7 3
0 2 6 5 9 8 7 1 5 7 3
0 2 1 5 9 8 7 6 5 7 3
0 2 15 9 8 7 6 5 7 3
0 2 15 9 876 5 7 3
0 2 1 3 9 8 7 6 5 75
м-3 1
5.
2
7
F
3
6.
4
T
F
6.
8.
F
7
3
8
T
4
F
10
7
F
// the first Partition of A is:
<3
3
>=3
// and first j= 4
Now, p = 1 and j – 1 = 3, so the next "action" taken by QuickSort is the
invocation of QuickSort itself with new parameter values, QuickSort(1,3).
Before continuing the walk through, we digress for a moment to describe a
common mechanism for implementing recursion (in modern high-level computer
languages). Each invocation of the algorithm, including the sub-calls inside the
Transcribed Image Text:Algorithm 4.5.1: QuickSort(p,q) // Assumes an “external" invocation of the form QuickSort(1, n) and // (recursively) sorts A[p], A[p + 1],.., A[q] into order: Begin If (p < g) Then M + A[q]; j+p; For k + p to (q – 1) Do If (A[k]< M) Then x- A[j]; A[j] + A[k]; A[k] + x; j+j+1; // the if // the for-k loop End; End; A[q] + A[j]; A[j] + M; // this is the end of the "partitioning" QuickSort( p,j- 1); QuickSort(j+1, q ); |/ the second "recursive" sub-call // the first "recursive" sub-call // the if-statement at the beginning // the recursive algorithm End; End. Walkthrough assuming an "external" invocation of the form Q(1, 11); that is, // QuickSort the array A from position, p = 1 to the last position, q = 11. A 1= p q = 11 k A[k] A[k]<<M 5 7 60 9 821573 5 7 6 0 9 82157 3 5 76 0 9 8 2 1 5 7 3 5 7 60 9 8 2 1 5 7 3 0 76 59 8 2 1 5 7 3 0 7 6 5 9 8 2 1 5 7 3 0 76 5 9 8 2 1 5 7 3 0 2 6 5 9 8 7 1 5 7 3 0 2 1 5 9 8 7 6 5 7 3 0 2 15 9 8 7 6 5 7 3 0 2 15 9 876 5 7 3 0 2 1 3 9 8 7 6 5 75 м-3 1 5. 2 7 F 3 6. 4 T F 6. 8. F 7 3 8 T 4 F 10 7 F // the first Partition of A is: <3 3 >=3 // and first j= 4 Now, p = 1 and j – 1 = 3, so the next "action" taken by QuickSort is the invocation of QuickSort itself with new parameter values, QuickSort(1,3). Before continuing the walk through, we digress for a moment to describe a common mechanism for implementing recursion (in modern high-level computer languages). Each invocation of the algorithm, including the sub-calls inside the
Expert Solution
steps

Step by step

Solved in 2 steps with 1 images

Blurred answer
Knowledge Booster
Matrix multiplication
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
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education