Slides Algo Select Ralgorithm Typed
Slides Algo Select Ralgorithm Typed
Selec.on
Randomized
Selec.on
(Algorithm)
Design
and
Analysis
of
Algorithms
I
Prerequisites
Watch
this
aBer:
• QuickSort
-‐
Par..oning
around
a
pivot
• QuickSort
–
Choosing
a
good
pivot
• Probability
Review,
Part
I
Tim
Roughgarden
The
Problem
For
simplicity
Input
:
array
A
with
n
dis.nct
numbers
and
a
number
Output : ith order sta.s.c (i.e., ith smallest element of input array)
Tim
Roughgarden
Reduc.on
to
Sor.ng
O(nlog(n))
algorithm
The
3rd
order
sta.s.c
on
the
leB
side
of
the
pivot.
The
2nd
order
sta.s.c
on
the
right
side
of
the
pivot.
The
5th
order
sta.s.c
on
the
right
side
of
the
pivot.
Randomized
Selec.on
Rselect
(array
A,
length
n,
order
sta.s.c
i)
Tim
Roughgarden
Tem
ver
What
is
the
running
.me
of
the
RSelect
algorithm
if
pivots
are
always
chosen
in
the
worst
possible
way?
Example :
-‐-‐ “average” is over random pivot choices made by the algorithm
Tim Roughgarden