ADVANCED ALGORITHMS
Lecture 14: randomized algorithms
1
ADVANCED ALGORITHMS Lecture 14: randomized algorithms 1 - - PowerPoint PPT Presentation
ADVANCED ALGORITHMS Lecture 14: randomized algorithms 1 ANNOUNCEMENTS HW 3 out; due Friday after fall break Look out for project topics! announcement in a little while Groups of 2-3 Give a list of >= 5 topics, top choice
ADVANCED ALGORITHMS
Lecture 14: randomized algorithms
1ANNOUNCEMENTS
➤ HW 3 out; due Friday after fall break ➤ Look out for project topics! — announcement in a little while ➤ Groups of 2-3 ➤ Give a list of >= 5 topics, top choice first ➤ Send email to utah-algo-ta@googlegroups.com, with subject “Project
topic”; one email per group; names and UIDs
23 weeksfrom
now
I 1 meetings about
proposal
Ftd
Trek
LAST CLASS
3➤ Randomness can help design efficient algorithms — examples
“polynomial identity” testing, testing if a number is prime, …
TODAY’S PLAN
➤ Randomness can avoid “unlucky” choices — quick sort, hashing ➤ Reasoning about randomized algorithms ➤ Expectations and linearity
4REASONING ABOUT RANDOMIZED ALGORITHMS
5➤ A[1, …, N] is an array in which N/2 elements promised to be zero.
Find one i such that A[i] = 0
➤ Let i be random index; check if A[i] = 0, if so return it; ➤ Else repeat
LasVegas algorithm
it is
never wrong
running
Isanbe largeif
resource time
we are unlucky
Prob
that
algorithm has
run t.me t
is
e th
2
REASONING ABOUT RANDOMIZED ALGORITHMS
6➤ Running time can be varying — expected running time, … ➤ Success probability ➤ General tradeoff — boosting
I
runtime
is
a
rand.mu
able
Runtime depends on
we
tfmulhe
cointosses
so
far
sizeEEEYmnIiet
ExeeEaemdmrIFao
Then there is an
Ala that has
success prob 9,80
runtime
variable
l s T
k
Ah
pick
r
log's
Repeat
r times run algorithm ALG
if it succeeds output answer
failure prob of Ata
E at
L
FLASHBACK — SORTING
7➤ Consider following algorithm:
➤ Pick A[0] as the “pivot”; ➤ Partition A[] into “less than pivot” and “greater than pivot” ➤ Sort recursively; return appended sorted lists
AID
AlnD
9
BE
Oki
s
elementsof A
that are safe
Tfn
TlaltTlb 1041
43
n
DAFT
atb
n
l
worst
a n
l
b
Case
A[0] AS PIVOT — BAD EXAMPLES?
8QI
when is the running time
NI
One
e
Bl
has size
n L
G
hassizeO
1In
1In l
fo
n
s n
A b 3 F
TINI TIF TIF 1041
113171,1411
I
solvesto OlnIgn n
If
Afo
is
almost
in the middle of the sorted
version of Al
then algorithmdoes well
RANDOM PIVOT
9➤ Probability of lop-sided partition
Instead of picking Alo
as a pivot
pick
a random Afi
what is
Prob that
minla b
F
A
a
gt
EeeEz
x
Probability of
succeeding
is
Ig
No liopsided split
FORMALIZING — EXPECTED RUNNING TIME
10Theoremi
Expected running time of Quick
Sor
is
Ofnlog
n
Xn
runningtime of algorithm
n
rangeof
r V
I
nq h2
Efx n
i
Prf x
i
RANDOM VARIABLES AND EXPECTATION
11integral
that
Random variable
X
takes rXeal values
depending on choices of algorithm
Efx
i prob x
i
i c21
go if
coin isheads
0.12
1.12 12
I
if
u
tails
X
dependingonaoupf.etoflft
2 tt t 6 f
6
3 5
“PROBABILISTIC RECURRENCE”
12writing an
recurrence for
Efxn
Qnin
a
i
h smallest
d
n
Prob of picking
EfXiao
t ECXn.itoh
k
3
In Efxi It EfXnif1044
define
yn
E Xn
yn
tn Yi
Yn i
in
Yn
In
Yi i Yu ith
where
Yo
Can prove
by
induction
that
y
I 2nlogn
Proof works by
plugging in
yis2ibyi
Yi
yn
tn
i i tog
ni
tog n ith
Elf
i.bg i
i logn ln i
lognJ n
f2fn i logn
n
2nX
logn
EXPECTATION IS SMALL => SMALL RUNNING TIME WHP?
13iI f
Claim
Prob
that
Xu
tooo nloyn is
00
MARKOV’S INEQUALITY
14If
X
is
a
non negative
random variable then
Pr
X
Efx3
s t
Pat
suppose Mx
ELI E
iprlx.it ji
Mx
ti
O
Consider
i Prfx
i
i
cEfx
i fi
ElxDPrfx i3
cEfx7 PrfxscECx3
TE
Efx
BACK TO EXAMPLE
15HASHING — N BALLS INTO N BINS
16EXPECTED SIZE OF BIN
17LINEARITY OF EXPECTATION
18PUZZLE
19➤ Question: suppose n “numbered” balls are placed on a line from left to
position”?