Question: Following is a function 'QuickSort ( A , p , r ) ' to sort an array A from index p to r . QuickSort

Following is a function 'QuickSort(A,p,r)' to sort an array A from index p to r.
QuickSort(A, p, r)
if p < r
q = Partition(A, p, r)
QuickSort(A, p, q-1)
QuickSort(A, q+1, r)
Given an array A =[2,8,7,1,3], the function calls will be made in the following order.
QuickSort(A,1,5)
Partition(A,1,5)
QuickSort(A,1,2)
Partition(A,1,2)
QuickSort(A,1,0)
QuickSort(A,2,2)
QuickSort(A,4,5)
Partition(A,4,5), A=[1,2,3,7,8]
QuickSort(A,4,3)
QuickSort(A,5,5)
The array A will be [2,1,3,8,7] at the end of Partition(A,1,5)
The array A will be [1,2,3,8,7] at the end of Partition(A,1,2)
The array A will be [1,2,3,7,8] at the end of Partition(A,4,5)
Here is the question.
Given the array A =[1,5,6,7,2],
Show the function calls with parameters in the correct order and
show what the array A will be at the end of each Partition()

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!