Answered step by step
Verified Expert Solution
Link Copied!
Question
1 Approved Answer

can you rewrite this pesudocode to partition in thirds instead of halves?RANDOMIZED - SELECT ( A , p , r , i ) if p

can you rewrite this pesudocode to partition in thirds instead of halves?RANDOMIZED-SELECT (A,p,r,i)
if p==r
return A[p]
q= RANDOMIZED-PARTITION (A,p,r)
k=q-p+1
if i==k,// the pivot value is the answer
return A[q]
elseif (A,p,q-1,i)(A,q+1,r,i-k)(A,p,r)i=RANDOM(p,r)A[r]A[i](A,p,r)iA[p.r]A[pdotsr](A,p,r)x=A[r]i=p-1j=pr-1A[j]xi=i+1A[i]A[j]A[i+1]A[r]i+1i
return RANDOMIZED-SELECT (A,p,q-1,i)
else return RANDOMIZED-SELECT (A,q+1,r,i-k)
RANDOMIZED-PARTITION (A,p,r)
i=RANDOM(p,r)
exchange A[r] with A[i]
return PARTITION (A,p,r)
RANDOMIZED-SELECT returns the ith smallest element of the array A[p.r].
Name, SID, Date
The key to the algorithm is the PARTITION procedure, which rearranges the subar-
ray A[pdotsr]in place.
PARTITION (A,p,r)
x=A[r]
i=p-1
for j=ptor-1
ifA[j]x
i=i+1
exchange A[i] with A[j]
exchange A[i+1] with A[r]
return i+1
image text in transcribed

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image
Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

MySQL/PHP Database Applications

Authors: Brad Bulger, Jay Greenspan, David Wall

2nd Edition

0764549634, 9780764549632

More Books

Students explore these related Databases questions