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
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
Related questions
Question
Apply
![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](/v2/_next/image?url=https%3A%2F%2Fcontent.bartleby.com%2Fqna-images%2Fquestion%2F0f7775f3-edad-4f27-ba1b-f7886a7505bd%2F680c9831-ccbf-4fd0-ad15-f9fab81fc319%2Fy1a49h5_processed.png&w=3840&q=75)
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
![](/static/compass_v2/shared-icons/check-mark.png)
This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
Step by step
Solved in 2 steps with 1 images
![Blurred answer](/static/compass_v2/solution-images/blurred-answer.jpg)
Knowledge Booster
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.Recommended textbooks for you
![Database System Concepts](https://www.bartleby.com/isbn_cover_images/9780078022159/9780078022159_smallCoverImage.jpg)
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)](https://www.bartleby.com/isbn_cover_images/9780134444321/9780134444321_smallCoverImage.gif)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
![Digital Fundamentals (11th Edition)](https://www.bartleby.com/isbn_cover_images/9780132737968/9780132737968_smallCoverImage.gif)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
![Database System Concepts](https://www.bartleby.com/isbn_cover_images/9780078022159/9780078022159_smallCoverImage.jpg)
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)](https://www.bartleby.com/isbn_cover_images/9780134444321/9780134444321_smallCoverImage.gif)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
![Digital Fundamentals (11th Edition)](https://www.bartleby.com/isbn_cover_images/9780132737968/9780132737968_smallCoverImage.gif)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
![C How to Program (8th Edition)](https://www.bartleby.com/isbn_cover_images/9780133976892/9780133976892_smallCoverImage.gif)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
![Database Systems: Design, Implementation, & Manag…](https://www.bartleby.com/isbn_cover_images/9781337627900/9781337627900_smallCoverImage.gif)
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
![Programmable Logic Controllers](https://www.bartleby.com/isbn_cover_images/9780073373843/9780073373843_smallCoverImage.gif)
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education