cse 202: design and analysis of algorithms · cse 202: design and analysis of algorithms lecture 14...

53
CSE 202: Design and Analysis of Algorithms Lecture 14 Instructor: Kamalika Chaudhuri

Upload: phamhanh

Post on 10-Jul-2018

238 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: CSE 202: Design and Analysis of Algorithms · CSE 202: Design and Analysis of Algorithms Lecture 14 Instructor: Kamalika Chaudhuri. ... Wp 1 - 1/n, all processors succeed within 2en

CSE 202: Design and Analysis of Algorithms

Lecture 14

Instructor: Kamalika Chaudhuri

Page 2: CSE 202: Design and Analysis of Algorithms · CSE 202: Design and Analysis of Algorithms Lecture 14 Instructor: Kamalika Chaudhuri. ... Wp 1 - 1/n, all processors succeed within 2en

Algorithm Design Paradigms

• Exhaustive Search

• Greedy Algorithms: Build a solution incrementally piece by piece

• Divide and Conquer: Divide into parts, solve each part, combine results

• Dynamic Programming: Divide into subtasks, perform subtask by size. Combine smaller subtasks to larger ones

• Hill-climbing: Start with a solution, improve it

• Randomized Algorithms: Algorithm can make random choices

Page 3: CSE 202: Design and Analysis of Algorithms · CSE 202: Design and Analysis of Algorithms Lecture 14 Instructor: Kamalika Chaudhuri. ... Wp 1 - 1/n, all processors succeed within 2en

Randomized Algorithms

• Algorithm can make random decisions

• Why randomized algorithms? Simple and efficient

• Examples: Symmetry-breaking, graph algorithms, quicksort, hashing, load balancing, cryptography, etc

Page 4: CSE 202: Design and Analysis of Algorithms · CSE 202: Design and Analysis of Algorithms Lecture 14 Instructor: Kamalika Chaudhuri. ... Wp 1 - 1/n, all processors succeed within 2en

Contention Resolution

Given n processors and a resource which they all wish to access, design a symmetry breaking access protocol

Restriction: Processors can’t communicate Simultaneous access blocks the resource

Processors

1

2

3

4

5Object

Need symmetry-breaking!

Page 5: CSE 202: Design and Analysis of Algorithms · CSE 202: Design and Analysis of Algorithms Lecture 14 Instructor: Kamalika Chaudhuri. ... Wp 1 - 1/n, all processors succeed within 2en

Contention Resolution

Given n processors and a resource which they all wish to access, design a symmetry breaking access protocol

Restriction: Processors can’t communicate Simultaneous access blocks the resource

Processors

1

2

3

4

5Object

Need symmetry-breaking!

Protocol: At time t, each processor accesses resource w.p. p = 1/n

Page 6: CSE 202: Design and Analysis of Algorithms · CSE 202: Design and Analysis of Algorithms Lecture 14 Instructor: Kamalika Chaudhuri. ... Wp 1 - 1/n, all processors succeed within 2en

Contention Resolution

Given n processors and a resource which they all wish to access, design a symmetry breaking access protocol

Restriction: Processors can’t communicate Simultaneous access blocks the resource

Protocol: At time t, each processor accesses resource w.p. p = 1/n

Goals:- Low contention - Low waiting time for all processors

Page 7: CSE 202: Design and Analysis of Algorithms · CSE 202: Design and Analysis of Algorithms Lecture 14 Instructor: Kamalika Chaudhuri. ... Wp 1 - 1/n, all processors succeed within 2en

Contention Resolution

Given n processors and a resource which they all wish to access, design a symmetry breaking access protocol

Restriction: Processors can’t communicate Simultaneous access blocks the resource

Protocol: At time t, each processor accesses resource w.p. p = 1/n

Goals:- Low contention - Low waiting time for all processors

S(i, t) = Event that processor i succeeds at time t = At time t, only processor i accesses

Page 8: CSE 202: Design and Analysis of Algorithms · CSE 202: Design and Analysis of Algorithms Lecture 14 Instructor: Kamalika Chaudhuri. ... Wp 1 - 1/n, all processors succeed within 2en

Contention Resolution

Given n processors and a resource which they all wish to access, design a symmetry breaking access protocol

Restriction: Processors can’t communicate Simultaneous access blocks the resource

Protocol: At time t, each processor accesses resource w.p. p = 1/n

Goals:- Low contention - Low waiting time for all processors

Pr[S(i, t)] = p x (1 - p)n-1

processor iaccesses

no other processors access

= (1/n) x (1 - 1/n)n-1

S(i, t) = Event that processor i succeeds at time t = At time t, only processor i accesses

Page 9: CSE 202: Design and Analysis of Algorithms · CSE 202: Design and Analysis of Algorithms Lecture 14 Instructor: Kamalika Chaudhuri. ... Wp 1 - 1/n, all processors succeed within 2en

Contention Resolution

Given n processors and a resource which they all wish to access, design a symmetry breaking access protocol

Restriction: Processors can’t communicate Simultaneous access blocks the resource

Protocol: At time t, each processor accesses resource w.p. p = 1/n

Goals:- Low contention - Low waiting time for all processors

Independent Events A, B:Pr(A and B) = Pr(A) x Pr(B)

Pr[S(i, t)] = p x (1 - p)n-1

processor iaccesses

no other processors access

= (1/n) x (1 - 1/n)n-1

S(i, t) = Event that processor i succeeds at time t = At time t, only processor i accesses

Page 10: CSE 202: Design and Analysis of Algorithms · CSE 202: Design and Analysis of Algorithms Lecture 14 Instructor: Kamalika Chaudhuri. ... Wp 1 - 1/n, all processors succeed within 2en

Contention Resolution

Given n processors and a resource which they all wish to access, design a symmetry breaking access protocol

Restriction: Processors can’t communicate Simultaneous access blocks the resource

Protocol: At time t, each processor accesses resource w.p. p = 1/n

Pr[S(i, t)] = p x (1 - p)n-1

processor iaccesses

no other processors access

= (1/n) x (1 - 1/n)n-1

S(i, t) = Event that processor i succeeds at time t = At time t, only processor i accesses

Page 11: CSE 202: Design and Analysis of Algorithms · CSE 202: Design and Analysis of Algorithms Lecture 14 Instructor: Kamalika Chaudhuri. ... Wp 1 - 1/n, all processors succeed within 2en

Contention Resolution

Given n processors and a resource which they all wish to access, design a symmetry breaking access protocol

Restriction: Processors can’t communicate Simultaneous access blocks the resource

Protocol: At time t, each processor accesses resource w.p. p = 1/n

Pr[S(i, t)] = p x (1 - p)n-1

processor iaccesses

no other processors access

= (1/n) x (1 - 1/n)n-1

S(i, t) = Event that processor i succeeds at time t = At time t, only processor i accesses

2 4 6 8 10 12 14 16 18 200.25

0.3

0.35

0.4

0.45

0.5

Fact: As n increases,(1) (1 - 1/n)n grows monotonically up to 1/e (2) (1 - 1/n)n-1 decreases monotonically down to 1/e

Page 12: CSE 202: Design and Analysis of Algorithms · CSE 202: Design and Analysis of Algorithms Lecture 14 Instructor: Kamalika Chaudhuri. ... Wp 1 - 1/n, all processors succeed within 2en

Contention Resolution

Given n processors and a resource which they all wish to access, design a symmetry breaking access protocol

Restriction: Processors can’t communicate Simultaneous access blocks the resource

Protocol: At time t, each processor accesses resource w.p. p = 1/n

Pr[S(i, t)] = p x (1 - p)n-1

processor iaccesses

no other processors access

= (1/n) x (1 - 1/n)n-1

S(i, t) = Event that processor i succeeds at time t = At time t, only processor i accesses

>= 1/en

<= 1/2n

Fact: As n increases,(1) (1 - 1/n)n grows monotonically up to 1/e (2) (1 - 1/n)n-1 decreases monotonically down to 1/e

Page 13: CSE 202: Design and Analysis of Algorithms · CSE 202: Design and Analysis of Algorithms Lecture 14 Instructor: Kamalika Chaudhuri. ... Wp 1 - 1/n, all processors succeed within 2en

Contention Resolution

Given n processors and a resource which they all wish to access, design a symmetry breaking access protocol

Restriction: Processors can’t communicate Simultaneous access blocks the resource

Protocol: At time t, each processor accesses resource w.p. p = 1/n

S(i, t) = Event that processor i succeeds at time t = At time t, only processor i accesses

Pr[S(i, t)] = p x (1 - p)n-1

processor iaccesses

no other processors access

= (1/n) x (1 - 1/n)n-1

>= (1/en)

<= (1/2n)

Page 14: CSE 202: Design and Analysis of Algorithms · CSE 202: Design and Analysis of Algorithms Lecture 14 Instructor: Kamalika Chaudhuri. ... Wp 1 - 1/n, all processors succeed within 2en

Contention Resolution

Given n processors and a resource which they all wish to access, design a symmetry breaking access protocol

Restriction: Processors can’t communicate Simultaneous access blocks the resource

Protocol: At time t, each processor accesses resource w.p. p = 1/n

S(i, t) = Event that processor i succeeds at time t = At time t, only processor i accesses

F(i, t) = Event that processor i has not succeeded after t steps

Pr[S(i, t)] = p x (1 - p)n-1

processor iaccesses

no other processors access

= (1/n) x (1 - 1/n)n-1

>= (1/en)

<= (1/2n)

Page 15: CSE 202: Design and Analysis of Algorithms · CSE 202: Design and Analysis of Algorithms Lecture 14 Instructor: Kamalika Chaudhuri. ... Wp 1 - 1/n, all processors succeed within 2en

Contention Resolution

Given n processors and a resource which they all wish to access, design a symmetry breaking access protocol

Restriction: Processors can’t communicate Simultaneous access blocks the resource

Protocol: At time t, each processor accesses resource w.p. p = 1/n

S(i, t) = Event that processor i succeeds at time t = At time t, only processor i accesses

F(i, t) = Event that processor i has not succeeded after t steps

Pr[F(i, t)] = (1 - S(i, 1))(1 - S(i, 2))...(1 - S(i, t)) <= (1 - 1/en)t

processor ifails at time 1

Pr[S(i, t)] = p x (1 - p)n-1

processor iaccesses

no other processors access

= (1/n) x (1 - 1/n)n-1

>= (1/en)

<= (1/2n)

Page 16: CSE 202: Design and Analysis of Algorithms · CSE 202: Design and Analysis of Algorithms Lecture 14 Instructor: Kamalika Chaudhuri. ... Wp 1 - 1/n, all processors succeed within 2en

Contention Resolution

Given n processors and a resource which they all wish to access, design a symmetry breaking access protocol

Restriction: Processors can’t communicate Simultaneous access blocks the resource

Protocol: At time t, each processor accesses resource w.p. p = 1/n

S(i, t) = Event that processor i succeeds at time t = At time t, only processor i accesses

F(i, t) = Event that processor i has not succeeded after t steps

Pr[F(i, t)] = (1 - Pr[S(i, 1)])(1 - Pr[S(i, 2)])...(1 - Pr[S(i, t)]) <= (1 - 1/en)t

processor ifails at time 1

Picking t = en, Pr[F(i, t)] <= 1/e Picking t = c. en. ln n, Pr[F(i, t)] <= n-c

Pr[S(i, t)] = p x (1 - p)n-1

processor iaccesses

no other processors access

= (1/n) x (1 - 1/n)n-1

>= (1/en)

<= (1/2n)

Page 17: CSE 202: Design and Analysis of Algorithms · CSE 202: Design and Analysis of Algorithms Lecture 14 Instructor: Kamalika Chaudhuri. ... Wp 1 - 1/n, all processors succeed within 2en

Contention Resolution

Given n processors and a resource which they all wish to access, design a symmetry breaking access protocol

Restriction: Processors can’t communicate Simultaneous access blocks the resource

Protocol: At time t, each processor accesses resource w.p. p = 1/n

Properties:

F(i, t) = Event that processor i has not succeeded after t steps

Picking t = en, Pr[F(i, t)] <= 1/e

Picking t = c. en. ln n, Pr[F(i, t)] <= n-c

Page 18: CSE 202: Design and Analysis of Algorithms · CSE 202: Design and Analysis of Algorithms Lecture 14 Instructor: Kamalika Chaudhuri. ... Wp 1 - 1/n, all processors succeed within 2en

Contention Resolution

Given n processors and a resource which they all wish to access, design a symmetry breaking access protocol

Restriction: Processors can’t communicate Simultaneous access blocks the resource

Protocol: At time t, each processor accesses resource w.p. p = 1/n

Properties:

F(i, t) = Event that processor i has not succeeded after t steps

Picking t = en, Pr[F(i, t)] <= 1/e

Picking t = c. en. ln n, Pr[F(i, t)] <= n-c

Fact: W.p. 1 - 1/n, all the processors succeed within 2en. ln n rounds

Page 19: CSE 202: Design and Analysis of Algorithms · CSE 202: Design and Analysis of Algorithms Lecture 14 Instructor: Kamalika Chaudhuri. ... Wp 1 - 1/n, all processors succeed within 2en

Contention Resolution

Given n processors and a resource which they all wish to access, design a symmetry breaking access protocol

Restriction: Processors can’t communicate Simultaneous access blocks the resource

Protocol: At time t, each processor accesses resource w.p. p = 1/n

Properties:

F(i, t) = Event that processor i has not succeeded after t steps

Picking t = en, Pr[F(i, t)] <= 1/e

Picking t = c. en. ln n, Pr[F(i, t)] <= n-c

Fact: W.p. 1 - 1/n, all the processors succeed within 2en. ln n rounds

For t = 2en. ln n, Pr[F(i,t)] = n-2 for a fixed i

Page 20: CSE 202: Design and Analysis of Algorithms · CSE 202: Design and Analysis of Algorithms Lecture 14 Instructor: Kamalika Chaudhuri. ... Wp 1 - 1/n, all processors succeed within 2en

Contention Resolution

Given n processors and a resource which they all wish to access, design a symmetry breaking access protocol

Restriction: Processors can’t communicate Simultaneous access blocks the resource

Protocol: At time t, each processor accesses resource w.p. p = 1/n

Properties:

F(i, t) = Event that processor i has not succeeded after t steps

Picking t = en, Pr[F(i, t)] <= 1/e

Picking t = c. en. ln n, Pr[F(i, t)] <= n-c

Fact: W.p. 1 - 1/n, all the processors succeed within 2en. ln n rounds

For t = 2en. ln n, Pr[F(i,t)] = n-2 for a fixed iUnion Bound: Any A, BPr[A U B] <= Pr[A] + Pr[B]

Page 21: CSE 202: Design and Analysis of Algorithms · CSE 202: Design and Analysis of Algorithms Lecture 14 Instructor: Kamalika Chaudhuri. ... Wp 1 - 1/n, all processors succeed within 2en

Contention Resolution

Given n processors and a resource which they all wish to access, design a symmetry breaking access protocol

Restriction: Processors can’t communicate Simultaneous access blocks the resource

Protocol: At time t, each processor accesses resource w.p. p = 1/n

Properties:

F(i, t) = Event that processor i has not succeeded after t steps

Picking t = en, Pr[F(i, t)] <= 1/e

Picking t = c. en. ln n, Pr[F(i, t)] <= n-c

Fact: W.p. 1 - 1/n, all the processors succeed within 2en. ln n rounds

For t = 2en. ln n, Pr[F(i,t)] = n-2 for a fixed iUnion Bound: Any A, BPr[A U B] <= Pr[A] + Pr[B]

Pr[∪ni=1F (i, t)] ≤

n�

i=1

Pr[F (i, t)] ≤ n · n−2 ≤ 1/n

Therefore,

Page 22: CSE 202: Design and Analysis of Algorithms · CSE 202: Design and Analysis of Algorithms Lecture 14 Instructor: Kamalika Chaudhuri. ... Wp 1 - 1/n, all processors succeed within 2en

Summary: Contention Resolution

Given n processors and a resource which they all wish to access, design a symmetry breaking access protocol

Restriction: Processors can’t communicate Simultaneous access blocks the resource

Protocol: At time t, each processor accesses resource w.p. p = 1/nF(i, t) = Event that processor i has not succeeded after t steps

Facts:

Facts we learnt:

Independent Events A, B: Pr(A and B) = Pr(A) x Pr(B)

As n increases,(1) (1 - 1/n)n converges monotonically up to 1/e (2) (1 - 1/n)n-1 converges monotonically down to 1/e

Picking t = c. en. ln n, Pr[F(i, t)] <= n-c

Wp 1 - 1/n, all processors succeed within 2en ln n rounds

Union Bound: For any two events A and B, Pr[A U B] <= Pr[A] + Pr[B]

Page 23: CSE 202: Design and Analysis of Algorithms · CSE 202: Design and Analysis of Algorithms Lecture 14 Instructor: Kamalika Chaudhuri. ... Wp 1 - 1/n, all processors succeed within 2en

Randomized Algorithms

• Contention Resolution

• Some Facts about Random Variables

Page 24: CSE 202: Design and Analysis of Algorithms · CSE 202: Design and Analysis of Algorithms Lecture 14 Instructor: Kamalika Chaudhuri. ... Wp 1 - 1/n, all processors succeed within 2en

Expectation

Given discrete random variable X, which takes m values xi w.p. pi, the expectation E[X] is defined as:

E[X] =m�

i=1

xi · Pr[X = xi] =m�

i=1

xipi

Page 25: CSE 202: Design and Analysis of Algorithms · CSE 202: Design and Analysis of Algorithms Lecture 14 Instructor: Kamalika Chaudhuri. ... Wp 1 - 1/n, all processors succeed within 2en

Expectation

Given discrete random variable X, which takes m values xi w.p. pi, the expectation E[X] is defined as:

Examples:

1. Let X = 1 if a fair coin toss comes up heads, 0 ow. What is E[X]?

E[X] =m�

i=1

xi · Pr[X = xi] =m�

i=1

xipi

Page 26: CSE 202: Design and Analysis of Algorithms · CSE 202: Design and Analysis of Algorithms Lecture 14 Instructor: Kamalika Chaudhuri. ... Wp 1 - 1/n, all processors succeed within 2en

Expectation

Given discrete random variable X, which takes m values xi w.p. pi, the expectation E[X] is defined as:

Examples:

1. Let X = 1 if a fair coin toss comes up heads, 0 ow. What is E[X]?

2. We are tossing a coin with head probability p, tail probability 1 - p. Let X = #independent flips until first head. What is E[X]?

E[X] =m�

i=1

xi · Pr[X = xi] =m�

i=1

xipi

Page 27: CSE 202: Design and Analysis of Algorithms · CSE 202: Design and Analysis of Algorithms Lecture 14 Instructor: Kamalika Chaudhuri. ... Wp 1 - 1/n, all processors succeed within 2en

Expectation

Given discrete random variable X, which takes m values xi w.p. pi, the expectation E[X] is defined as:

Examples:

1. Let X = 1 if a fair coin toss comes up heads, 0 ow. What is E[X]?

2. We are tossing a coin with head probability p, tail probability 1 - p. Let X = #independent flips until first head. What is E[X]?

Pr[X = j] = p x (1 - p)j - 1

first j-1 tailshead on toss j

E[X] =m�

i=1

xi · Pr[X = xi] =m�

i=1

xipi

E[X] =∞�

j=1

j · p(1− p)j−1 =p

1− p

∞�

j=0

j(1− p)j =p

1− p· 1− p

p2=

1

p

Page 28: CSE 202: Design and Analysis of Algorithms · CSE 202: Design and Analysis of Algorithms Lecture 14 Instructor: Kamalika Chaudhuri. ... Wp 1 - 1/n, all processors succeed within 2en

Expectation

Given discrete random variable X, which takes m values xi w.p. pi, the expectation E[X] is defined as:

E[X] =m�

i=1

xi · Pr[X = xi] =m�

i=1

xipi

Linearity of Expectation: E[X + Y] = E[X] + E[Y]

Page 29: CSE 202: Design and Analysis of Algorithms · CSE 202: Design and Analysis of Algorithms Lecture 14 Instructor: Kamalika Chaudhuri. ... Wp 1 - 1/n, all processors succeed within 2en

Expectation

Given discrete random variable X, which takes m values xi w.p. pi, the expectation E[X] is defined as:

E[X] =m�

i=1

xi · Pr[X = xi] =m�

i=1

xipi

Linearity of Expectation: E[X + Y] = E[X] + E[Y]

Example: Guessing a card

Shuffle n cards, then turn them over one by one. Guess what the next card is.How many guesses are correct on expectation?

Page 30: CSE 202: Design and Analysis of Algorithms · CSE 202: Design and Analysis of Algorithms Lecture 14 Instructor: Kamalika Chaudhuri. ... Wp 1 - 1/n, all processors succeed within 2en

Expectation

Given discrete random variable X, which takes m values xi w.p. pi, the expectation E[X] is defined as:

E[X] =m�

i=1

xi · Pr[X = xi] =m�

i=1

xipi

Linearity of Expectation: E[X + Y] = E[X] + E[Y]

Example: Guessing a card

Shuffle n cards, then turn them over one by one. Guess what the next card is.How many guesses are correct on expectation?

Let Xi = 1 if guess i is correct, 0 otherwise

Page 31: CSE 202: Design and Analysis of Algorithms · CSE 202: Design and Analysis of Algorithms Lecture 14 Instructor: Kamalika Chaudhuri. ... Wp 1 - 1/n, all processors succeed within 2en

Expectation

Given discrete random variable X, which takes m values xi w.p. pi, the expectation E[X] is defined as:

E[X] =m�

i=1

xi · Pr[X = xi] =m�

i=1

xipi

Linearity of Expectation: E[X + Y] = E[X] + E[Y]

Example: Guessing a card

Shuffle n cards, then turn them over one by one. Guess what the next card is.How many guesses are correct on expectation?

Let Xi = 1 if guess i is correct, 0 otherwise

Pr[Xi = 1] =1

n− i+ 1

Page 32: CSE 202: Design and Analysis of Algorithms · CSE 202: Design and Analysis of Algorithms Lecture 14 Instructor: Kamalika Chaudhuri. ... Wp 1 - 1/n, all processors succeed within 2en

Expectation

Given discrete random variable X, which takes m values xi w.p. pi, the expectation E[X] is defined as:

E[X] =m�

i=1

xi · Pr[X = xi] =m�

i=1

xipi

Linearity of Expectation: E[X + Y] = E[X] + E[Y]

Example: Guessing a card

Shuffle n cards, then turn them over one by one. Guess what the next card is.How many guesses are correct on expectation?

Let Xi = 1 if guess i is correct, 0 otherwise

Pr[Xi = 1] =1

n− i+ 1E[Xi] =

1

n− i+ 1

Page 33: CSE 202: Design and Analysis of Algorithms · CSE 202: Design and Analysis of Algorithms Lecture 14 Instructor: Kamalika Chaudhuri. ... Wp 1 - 1/n, all processors succeed within 2en

Expectation

Given discrete random variable X, which takes m values xi w.p. pi, the expectation E[X] is defined as:

E[X] =m�

i=1

xi · Pr[X = xi] =m�

i=1

xipi

Linearity of Expectation: E[X + Y] = E[X] + E[Y]

Example: Guessing a card

Shuffle n cards, then turn them over one by one. Guess what the next card is.How many guesses are correct on expectation?

Let Xi = 1 if guess i is correct, 0 otherwise

Pr[Xi = 1] =1

n− i+ 1E[Xi] =

1

n− i+ 1

Expected # of correct guesses = E[n�

i=1

Xi] =n�

i=1

E[Xi] =n�

i=1

1

i= Θ(log n)

Page 34: CSE 202: Design and Analysis of Algorithms · CSE 202: Design and Analysis of Algorithms Lecture 14 Instructor: Kamalika Chaudhuri. ... Wp 1 - 1/n, all processors succeed within 2en

Expectation

Given discrete random variable X, which takes m values xi w.p. pi, the expectation E[X] is defined as:

E[X] =m�

i=1

xi · Pr[X = xi] =m�

i=1

xipi

Linearity of Expectation: E[X + Y] = E[X] + E[Y]

Example: Guessing a card

Shuffle n cards, then turn them over one by one. Guess what the next card is.How many guesses are correct on expectation?

Let Xi = 1 if guess i is correct, 0 otherwise

Pr[Xi = 1] =1

n− i+ 1E[Xi] =

1

n− i+ 1

Expected # of correct guesses = E[n�

i=1

Xi] =n�

i=1

E[Xi] =n�

i=1

1

i= Θ(log n)

What if we insert the selected card into the pile randomly and pull another ?

Page 35: CSE 202: Design and Analysis of Algorithms · CSE 202: Design and Analysis of Algorithms Lecture 14 Instructor: Kamalika Chaudhuri. ... Wp 1 - 1/n, all processors succeed within 2en

Expectation

Given discrete random variable X, which takes m values xi w.p. pi, the expectation E[X] is defined as:

E[X] =m�

i=1

xi · Pr[X = xi] =m�

i=1

xipi

Linearity of Expectation: E[X + Y] = E[X] + E[Y]

Example: Coupon Collector’s Problem

Balls tossed randomly into n bins. How many balls in expectation before each bin has a ball?

Page 36: CSE 202: Design and Analysis of Algorithms · CSE 202: Design and Analysis of Algorithms Lecture 14 Instructor: Kamalika Chaudhuri. ... Wp 1 - 1/n, all processors succeed within 2en

Expectation

Given discrete random variable X, which takes m values xi w.p. pi, the expectation E[X] is defined as:

E[X] =m�

i=1

xi · Pr[X = xi] =m�

i=1

xipi

Linearity of Expectation: E[X + Y] = E[X] + E[Y]

Example: Coupon Collector’s Problem

Balls tossed randomly into n bins. How many balls in expectation before each bin has a ball?

Let Xj = time spent when there are exactly j non-empty bins (Phase j)

Page 37: CSE 202: Design and Analysis of Algorithms · CSE 202: Design and Analysis of Algorithms Lecture 14 Instructor: Kamalika Chaudhuri. ... Wp 1 - 1/n, all processors succeed within 2en

Expectation

Given discrete random variable X, which takes m values xi w.p. pi, the expectation E[X] is defined as:

E[X] =m�

i=1

xi · Pr[X = xi] =m�

i=1

xipi

Linearity of Expectation: E[X + Y] = E[X] + E[Y]

Example: Coupon Collector’s Problem

Balls tossed randomly into n bins. How many balls in expectation before each bin has a ball?

Let Xj = time spent when there are exactly j non-empty bins (Phase j)

Let X = total #steps = X1 + X2 + ... + Xn-1

Page 38: CSE 202: Design and Analysis of Algorithms · CSE 202: Design and Analysis of Algorithms Lecture 14 Instructor: Kamalika Chaudhuri. ... Wp 1 - 1/n, all processors succeed within 2en

Expectation

Given discrete random variable X, which takes m values xi w.p. pi, the expectation E[X] is defined as:

E[X] =m�

i=1

xi · Pr[X = xi] =m�

i=1

xipi

Linearity of Expectation: E[X + Y] = E[X] + E[Y]

Example: Coupon Collector’s Problem

Balls tossed randomly into n bins. How many balls in expectation before each bin has a ball?

Let Xj = time spent when there are exactly j non-empty bins (Phase j)

Let X = total #steps = X1 + X2 + ... + Xn-1

We move from phase j to j+1 when a ball hits one of n-j bins, so w.p. (n-j) /n

Page 39: CSE 202: Design and Analysis of Algorithms · CSE 202: Design and Analysis of Algorithms Lecture 14 Instructor: Kamalika Chaudhuri. ... Wp 1 - 1/n, all processors succeed within 2en

Expectation

Given discrete random variable X, which takes m values xi w.p. pi, the expectation E[X] is defined as:

E[X] =m�

i=1

xi · Pr[X = xi] =m�

i=1

xipi

Linearity of Expectation: E[X + Y] = E[X] + E[Y]

Example: Coupon Collector’s Problem

Balls tossed randomly into n bins. How many balls in expectation before each bin has a ball?

Let Xj = time spent when there are exactly j non-empty bins (Phase j)

Let X = total #steps = X1 + X2 + ... + Xn-1

We move from phase j to j+1 when a ball hits one of n-j bins, so w.p. (n-j) /n

Therefore, E[Xj] = n/(n - j) [From previous slide on expected waiting times]

Page 40: CSE 202: Design and Analysis of Algorithms · CSE 202: Design and Analysis of Algorithms Lecture 14 Instructor: Kamalika Chaudhuri. ... Wp 1 - 1/n, all processors succeed within 2en

Expectation

Given discrete random variable X, which takes m values xi w.p. pi, the expectation E[X] is defined as:

E[X] =m�

i=1

xi · Pr[X = xi] =m�

i=1

xipi

Linearity of Expectation: E[X + Y] = E[X] + E[Y]

Example: Coupon Collector’s Problem

Balls tossed randomly into n bins. How many balls in expectation before each bin has a ball?

Let Xj = time spent when there are exactly j non-empty bins (Phase j)

Let X = total #steps = X1 + X2 + ... + Xn-1

We move from phase j to j+1 when a ball hits one of n-j bins, so w.p. (n-j) /n

Therefore, E[Xj] = n/(n - j) [From previous slide on expected waiting times]

E[X] = E[X1 + .. + Xn-1] = E[X1] + .. + E[Xn-1] = n + n/2 + .. + n/(n-1) = Θ(n log n)

Page 41: CSE 202: Design and Analysis of Algorithms · CSE 202: Design and Analysis of Algorithms Lecture 14 Instructor: Kamalika Chaudhuri. ... Wp 1 - 1/n, all processors succeed within 2en

Expectation

Given discrete random variable X, which takes m values xi w.p. pi, the expectation E[X] is defined as:

E[X] =m�

i=1

xi · Pr[X = xi] =m�

i=1

xipi

Linearity of Expectation: E[X + Y] = E[X] + E[Y]

Example: Birthday Paradox

m balls tossed randomly into n bins. What is the expected #collisions?

Page 42: CSE 202: Design and Analysis of Algorithms · CSE 202: Design and Analysis of Algorithms Lecture 14 Instructor: Kamalika Chaudhuri. ... Wp 1 - 1/n, all processors succeed within 2en

Expectation

Given discrete random variable X, which takes m values xi w.p. pi, the expectation E[X] is defined as:

E[X] =m�

i=1

xi · Pr[X = xi] =m�

i=1

xipi

Linearity of Expectation: E[X + Y] = E[X] + E[Y]

Example: Birthday Paradox

m balls tossed randomly into n bins. What is the expected #collisions?

For 1 <= i < j <= m, let Xij = 1 if balls i and j land in the same bin, 0 otherwise

Page 43: CSE 202: Design and Analysis of Algorithms · CSE 202: Design and Analysis of Algorithms Lecture 14 Instructor: Kamalika Chaudhuri. ... Wp 1 - 1/n, all processors succeed within 2en

Expectation

Given discrete random variable X, which takes m values xi w.p. pi, the expectation E[X] is defined as:

E[X] =m�

i=1

xi · Pr[X = xi] =m�

i=1

xipi

Linearity of Expectation: E[X + Y] = E[X] + E[Y]

Example: Birthday Paradox

m balls tossed randomly into n bins. What is the expected #collisions?

For 1 <= i < j <= m, let Xij = 1 if balls i and j land in the same bin, 0 otherwise

Pr[ Xij = 1 ] = 1/n, so E[Xij] = 1/n

Page 44: CSE 202: Design and Analysis of Algorithms · CSE 202: Design and Analysis of Algorithms Lecture 14 Instructor: Kamalika Chaudhuri. ... Wp 1 - 1/n, all processors succeed within 2en

Expectation

Given discrete random variable X, which takes m values xi w.p. pi, the expectation E[X] is defined as:

E[X] =m�

i=1

xi · Pr[X = xi] =m�

i=1

xipi

Linearity of Expectation: E[X + Y] = E[X] + E[Y]

Example: Birthday Paradox

m balls tossed randomly into n bins. What is the expected #collisions?

For 1 <= i < j <= m, let Xij = 1 if balls i and j land in the same bin, 0 otherwise

Pr[ Xij = 1 ] = 1/n, so E[Xij] = 1/n

So, expected number of collisions from tossing m balls = �

i,j

E[Xij ] =

�m2

n=

m(m− 1)

2n

So when m < sqrt(2n), expected #collisions < 1; otherwise, it’s more

Page 45: CSE 202: Design and Analysis of Algorithms · CSE 202: Design and Analysis of Algorithms Lecture 14 Instructor: Kamalika Chaudhuri. ... Wp 1 - 1/n, all processors succeed within 2en

Summary: Expectation and Linearity of Expectation

Given discrete random variable X, which takes m values xi w.p. pi, the expectation E[X] is defined as:

E[X] =m�

i=1

xi · Pr[X = xi] =m�

i=1

xipi

Linearity of Expectation: E[X + Y] = E[X] + E[Y]

Page 46: CSE 202: Design and Analysis of Algorithms · CSE 202: Design and Analysis of Algorithms Lecture 14 Instructor: Kamalika Chaudhuri. ... Wp 1 - 1/n, all processors succeed within 2en

Variance

Given a random variable X, its variance Var[X] is defined as: Var(X) = E[(X - E[X])2]

Variance of a random variable measures its “spread”

0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 10

20

40

60

80

100

120

Student Version of MATLAB

0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 10

100

200

300

400

500

600

Student Version of MATLAB

High Variance Distribution Low Variance Distribution

Page 47: CSE 202: Design and Analysis of Algorithms · CSE 202: Design and Analysis of Algorithms Lecture 14 Instructor: Kamalika Chaudhuri. ... Wp 1 - 1/n, all processors succeed within 2en

Variance

Given a random variable X, its variance Var[X] is defined as: Var(X) = E[(X - E[X])2]

Examples:

1. Let X = 1 if a fair coin toss comes up heads, 0 otherwise. What is Var(X)?

Variance of a random variable measures its “spread”

0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 10

20

40

60

80

100

120

Student Version of MATLAB

0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 10

100

200

300

400

500

600

Student Version of MATLAB

High Variance Distribution Low Variance Distribution

Page 48: CSE 202: Design and Analysis of Algorithms · CSE 202: Design and Analysis of Algorithms Lecture 14 Instructor: Kamalika Chaudhuri. ... Wp 1 - 1/n, all processors succeed within 2en

Variance

Given a random variable X, its variance Var[X] is defined as: Var(X) = E[(X - E[X])2]

Examples:

1. Let X = 1 if a fair coin toss comes up heads, 0 otherwise. What is Var(X)?

2. Let X = outcome of a fair dice throw. What is Var(X)?

Variance of a random variable measures its “spread”

0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 10

20

40

60

80

100

120

Student Version of MATLAB

0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 10

100

200

300

400

500

600

Student Version of MATLAB

High Variance Distribution Low Variance Distribution

Page 49: CSE 202: Design and Analysis of Algorithms · CSE 202: Design and Analysis of Algorithms Lecture 14 Instructor: Kamalika Chaudhuri. ... Wp 1 - 1/n, all processors succeed within 2en

Variance

Given a random variable X, its variance Var[X] is defined as: Var(X) = E[(X - E[X])2]

Properties of Variance:

1. Var(X) = E[X2] - (E[X])2

0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 10

20

40

60

80

100

120

Student Version of MATLAB

0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 10

100

200

300

400

500

600

Student Version of MATLAB

Variance of a random variable measures its “spread”

High Variance Distribution Low Variance Distribution

Page 50: CSE 202: Design and Analysis of Algorithms · CSE 202: Design and Analysis of Algorithms Lecture 14 Instructor: Kamalika Chaudhuri. ... Wp 1 - 1/n, all processors succeed within 2en

Variance

Given a random variable X, its variance Var[X] is defined as: Var(X) = E[(X - E[X])2]

Properties of Variance:

1. Var(X) = E[X2] - (E[X])2

2. If X and Y are independent random variables, then, Var(X + Y) = Var(X) + Var(Y)

0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 10

20

40

60

80

100

120

Student Version of MATLAB

0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 10

100

200

300

400

500

600

Student Version of MATLAB

Variance of a random variable measures its “spread”

High Variance Distribution Low Variance Distribution

Page 51: CSE 202: Design and Analysis of Algorithms · CSE 202: Design and Analysis of Algorithms Lecture 14 Instructor: Kamalika Chaudhuri. ... Wp 1 - 1/n, all processors succeed within 2en

Variance

Given a random variable X, its variance Var[X] is defined as: Var(X) = E[(X - E[X])2]

Properties of Variance:

1. Var(X) = E[X2] - (E[X])2

2. If X and Y are independent random variables, then, Var(X + Y) = Var(X) + Var(Y)

3. For any constants a and b, Var(aX + b) = a2 Var(X)

0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 10

20

40

60

80

100

120

Student Version of MATLAB

0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 10

100

200

300

400

500

600

Student Version of MATLAB

Variance of a random variable measures its “spread”

High Variance Distribution Low Variance Distribution

Page 52: CSE 202: Design and Analysis of Algorithms · CSE 202: Design and Analysis of Algorithms Lecture 14 Instructor: Kamalika Chaudhuri. ... Wp 1 - 1/n, all processors succeed within 2en

Randomized Algorithms

• Contention Resolution

• Some Facts about Random Variables

• Global Minimum Cut Algorithm

Page 53: CSE 202: Design and Analysis of Algorithms · CSE 202: Design and Analysis of Algorithms Lecture 14 Instructor: Kamalika Chaudhuri. ... Wp 1 - 1/n, all processors succeed within 2en

Global Min-Cut

Example:

G G

A

V - A

Note: A global min-cut is not the same as an s-t min cut

How can we find a global min-cut using n - 1 max-flows?

We can do better for the global min-cut

Problem: Given undirected, unweighted graph G = (V, E), find a cut (A, V - A) which has the minimum number of edges across it