Algorithm 1 Iterative Randomized Select

Input: a sequence AA of nn elements and an integer ii

Output: the ii-th element of AA

1:p=1p = 1

2:r=nr = n

3:while p<rp < r do

4:q=q = RandomizedPartition(A,p,rA, p, r)

5:if q<iq < i then

6:p=q+1p = q + 1

7:else if q>iq > i then

8:r=q1r = q - 1

9:else

10:return A[q]A[q]

11:end if

12:end while

13:return A[p]A[p]