Overview

Quickselect(A,l,r,k) (find the -th smallest element in )
//Pick the pivot , put it on index such that all elements on the left are smaller and all elements on the right are bigger. Return this index If then return else if then return Quickselect(A,l,t-1,k) (Left block) else then return Quickselect(A,t+1,r,k-(t-l+1)) (Right block) ( is the local rank)

Time Analysis

Goal: Las Vegas Algorithm with expected run time

We define # of comparisons # of calls of Quickselect on elements with (we divide different sizes of problems into buckets, and our problem size is always declining)

Observation If we choose the middle half of the elements as pivot element, then the search room is reduced by factor at most (and the problem size is reduced to the next bucket) The search room will be reduced by factor with probability of

Claim: Then (geometric serie ) Proof We also see that the pivot element is one of the middle elements (good pivots) with probability of . If we choose such good pivots, the problem size drops to the next bucket, and we will never call Quickselect again on this problem size. () Since this happens with probability , we must have