Question: Create an algorithm Randomized-Select2(A,i,j) that reorders A so that the ith through the jth order statistics of A are in A[i..j] (unsorted), where 1 i

 Create an algorithm Randomized-Select2(A,i,j) that reorders A so that the ith

Create an algorithm Randomized-Select2(A,i,j) that reorders A so that the ith through the jth order statistics of A are in A[i..j] (unsorted), where 1 i

For example, if your input is A = [3,10,5,1,22,30,12,28,9,7] and you call Randomized-Select2(A, 3, 6), the algorithm might return with A contain- ing the following reordered contents [3,1,5,9,7,10,22,28,30,12]. Your code may return the data in a different order, but the first 2 elements should be 1 and 3, the middle 4 elements should be 5, 7, 9, ,and 10, and the last four elements should be 12, 22, 28, and 30.

Provide a brief description of your algorithm in English and provide pseudocode.

RANDOMIZED-SELECT (A,p,r,i) 123456789ifp==rreturnA[p]/1irp+1whenp=rmeansthati=1q=RANDOMIZED-PARTITION(A,p,r)k=qp+1ifi==kreturnA[q]/thepivotvalueistheanswerelseifi

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 Databases Questions!