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 first ➤ Send email to utah-algo-ta@googlegroups.com, with subject “Project topic”; one email per group; names and UIDs I 1 meetings about proposal 3 weeks from now Ftd of October Trek � 2
LAST CLASS ➤ Randomness can help design e ffi cient algorithms — examples “polynomial identity” testing, testing if a number is prime, … � 3
TODAY’S PLAN ➤ Randomness can avoid “unlucky” choices — quick sort, hashing ➤ Reasoning about randomized algorithms ➤ Expectations and linearity � 4
REASONING ABOUT RANDOMIZED ALGORITHMS ➤ 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 it is never wrong Las Vegas algorithm Isan be large if running resource time are unlucky we run t.me t is algorithm has that Prob e th 2 � 5
REASONING ABOUT RANDOMIZED ALGORITHMS ➤ Running time can be varying — expected running time, … is a runtime I able rand.mu ➤ Success probability Runtime depends on ➤ General tradeo ff — boosting cointosses so tfmulhe we far size EE EYmnIiet ExeeEaemdmrIFao Ala that has Then there is an variable runtime success prob 9,80 k T l s � 6
Ah pick log's r r times Repeat run algorithm ALG if it succeeds output answer E at failure prob of Ata L
FLASHBACK — SORTING Aln D ➤ Consider following algorithm: AID 9 ➤ Pick A[0] as the “pivot”; ➤ Partition A[] into “less than pivot” and “greater than pivot” ➤ Sort recursively; return appended sorted lists BE Oki s that are safe elements of A TlaltTlb 1041 DAFT 43 n Tfn l atb n b 0 l worst n a Case � 7
A[0] AS PIVOT — BAD EXAMPLES? when is the running time NI QI has size O G n L has size Bl e One n s fo 1 In l n 1 In A b 3 F TINI TIF TIF 1041 I 113171,1411 solves to Oln Ign n in the middle of the sorted almost is A fo If then algorithm does well version of Al � 8
Instead of picking Alo a pivot as RANDOM PIVOT a random Afi pick ➤ Probability of lop-sided partition min la b F Prob that what is EeeEz gt A a x is Ig Probability of succeeding No liopsided split � 9
FORMALIZING — EXPECTED RUNNING TIME Expected running time of Quick Sor Theoremi Ofn log n is on algorithm running time of algorithm Xn n on array of size q h2 I range of V r n i Prf x i Efx n � 10
RANDOM VARIABLES AND EXPECTATION integral that takes rXeal values X depending on Random variable choices of algorithm i i x Efx prob i c 21 coin is heads 0.12 1.12 12 go if tails u I if t 6 f 2 tt depending on aoupf.etoflft X 3 5 6 � 11
recurrence for writing an “PROBABILISTIC RECURRENCE” Efxn Qnin h smallest i a d n t ECXn.it oh Ef Xiao Prob of picking In Efx i It EfXn if 1044 3 k in tn Yi Yn i yn E Xn yn define � 12
In Yi i Yu ith Yn where 0 Yo I 2nlogn that induction y Can prove by Proof works by yis2ibyi plugging in tog n ith i i tog ni tn yn Yi Elf i.bg i i logn ln i lognJ n f2fn i logn n logn 2nX
EXPECTATION IS SMALL => SMALL RUNNING TIME WHP? i iI f ooo nlogh tooo nloyn is that Xu Prob Claim 00 � 13
MARKOV’S INEQUALITY random variable non negative X is If a s t Efx3 Pr then X Eµf hf suppose Mx Pat hF ELI E iprlx.it ji Mx ti � 14 O
0 i Prfx i Consider c Efx i i fi ElxDPrfx i3 cEfx7 PrfxscECx3 TE Efx
BACK TO EXAMPLE � 15
HASHING — N BALLS INTO N BINS � 16
EXPECTED SIZE OF BIN � 17
LINEARITY OF EXPECTATION � 18
PUZZLE ➤ Question: suppose n “numbered” balls are placed on a line from left to right. What is the expected number of balls that are in the “right position”? � 19
Recommend
More recommend