



Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Material Type: Notes; Professor: Shull; Class: Fundamental Algorithms; Subject: Computer Science; University: Wellesley College; Term: Unknown 1989;
Typology: Study notes
1 / 6
This page cannot be seen from the preview
Don't miss anything!




To find i
th smallest element:
p ← Randomized-Partition(A,lo,hi)
if i = p-lo+
then return A[p]
elseif i < p-lo+
then search bottom half of array for i
else search top half of array for i-(p-lo+1)
lo p hi
p - lo smallest elements
hi - p largest elements
Randomized-Select(A,lo,hi,i)
if lo = hi
then return A[lo]
p ← Randomized-Partition(A,lo,hi)
if i = p-lo+
then return A[p]
elseif i < p-lo+
then return Randomized-Select(A,lo,p-1,i)
else return Randomized-Select(A,p+1,hi,i-(p-lo+1))
lo p=hi
n-1 elements
lo p hi
n/2
n/2