ADVANCED ALGORITHMS Lecture 14: randomized algorithms 1 - - PowerPoint PPT Presentation

advanced algorithms
SMART_READER_LITE
LIVE PREVIEW

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


slide-1
SLIDE 1

ADVANCED ALGORITHMS

Lecture 14: randomized algorithms

1
slide-2
SLIDE 2

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

2

3 weeksfrom

now

I 1 meetings about

proposal

Ftd

  • f October

Trek

slide-3
SLIDE 3

LAST CLASS

3

➤ Randomness can help design efficient algorithms — examples

“polynomial identity” testing, testing if a number is prime, …

slide-4
SLIDE 4

TODAY’S PLAN

➤ Randomness can avoid “unlucky” choices — quick sort, hashing ➤ Reasoning about randomized algorithms ➤ Expectations and linearity

4
slide-5
SLIDE 5

REASONING 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

slide-6
SLIDE 6

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

slide-7
SLIDE 7

Ah

pick

r

log's

Repeat

r times run algorithm ALG

if it succeeds output answer

failure prob of Ata

E at

L

slide-8
SLIDE 8
slide-9
SLIDE 9

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

slide-10
SLIDE 10

A[0] AS PIVOT — BAD EXAMPLES?

8

QI

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

slide-11
SLIDE 11

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

slide-12
SLIDE 12

FORMALIZING — EXPECTED RUNNING TIME

10

Theoremi

Expected running time of Quick

Sor

is

Ofnlog

n

Xn

runningtime of algorithm

  • n algorithm
  • n array of size

n

rangeof

r V

I

n

q h2

Efx n

i

Prf x

i

slide-13
SLIDE 13

RANDOM VARIABLES AND EXPECTATION

11

integral

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

slide-14
SLIDE 14

“PROBABILISTIC RECURRENCE”

12

writing 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

slide-15
SLIDE 15

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

slide-16
SLIDE 16

EXPECTATION IS SMALL => SMALL RUNNING TIME WHP?

13

i

iI f

  • oonlogh

Claim

Prob

that

Xu

tooo nloyn is

00

slide-17
SLIDE 17

MARKOV’S INEQUALITY

14

If

X

is

a

non negative

random variable then

Pr

X

Efx3

s t

Pat

suppose Mx

Eµf

hf

hF

ELI E

iprlx.it ji

Mx

ti

O

slide-18
SLIDE 18

Consider

i Prfx

i

i

cEfx

i fi

ElxDPrfx i3

cEfx7 PrfxscECx3

TE

Efx

slide-19
SLIDE 19

BACK TO EXAMPLE

15
slide-20
SLIDE 20

HASHING — N BALLS INTO N BINS

16
slide-21
SLIDE 21

EXPECTED SIZE OF BIN

17
slide-22
SLIDE 22

LINEARITY OF EXPECTATION

18
slide-23
SLIDE 23

PUZZLE

19

➤ 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”?