L09 RandomizedQuicksort
L09 RandomizedQuicksort
RANDOMIZED-QUICKSORT(A, p, q - 1)
RANDOMIZED-QUICKSORT(A, q + 1, r)
PARTITION is called at most n times, each call takes
O(1) plus the number of comparisons
(at each call a pivot is selected and never again included
in future calls) 8
Analysis of Randomized Quicksort
•
X(j)
ttt 0
tth 1
tht 1
thh 2
htt 1
hth 2
hht 2
hhh 3
i n-1
i+1 n
by linearity indicator
of expectation random variable
i j
MA512: Data Structures and Algorithms
27
Hoare’s Partition: pseudo code