cse 2331/5331 topic 5: prob. analysis randomized alg

22
CSE 2331/5331 CSE 2331/5331 Topic 5: Prob. Analysis Randomized Alg.

Upload: emerald-park

Post on 17-Dec-2015

226 views

Category:

Documents


3 download

TRANSCRIPT

Page 1: CSE 2331/5331 Topic 5: Prob. Analysis Randomized Alg

CSE 2331/5331

CSE 2331/5331

Topic 5:

Prob. Analysis

Randomized Alg.

Page 2: CSE 2331/5331 Topic 5: Prob. Analysis Randomized Alg

Expected Complexity

CSE 2331/5331

Probabilistic method: Given a distribution for all possible inputs Derive expected time based on distribution

Randomized algorithm: Add randomness in the algorithm Analyze the expected behavior of the algorithm

Page 3: CSE 2331/5331 Topic 5: Prob. Analysis Randomized Alg

First Example

What is worst case time complexity? What is expected / average time complexity?

CSE 2331/5331

Page 4: CSE 2331/5331 Topic 5: Prob. Analysis Randomized Alg

Expected Running Time

Expected / average running time

= probability of event I = running time given event I

To analyze, need to assume a probabilistic distribution for all inputs

CSE 2331/5331

Page 5: CSE 2331/5331 Topic 5: Prob. Analysis Randomized Alg

SeqSearch Alg

Expected running time =

If we assume = 0 All permutations are equally likely

implies Then expected running time =

CSE 2331/5331

Page 6: CSE 2331/5331 Topic 5: Prob. Analysis Randomized Alg

Remarks

For probabilistic analysis An input probabilistic distribution input model has be assumed! For a fixed input, the running time is fixed. The average / expected time complexity is for if we consider

running it for a range of inputs, what the average behavior is.

Randomized algorithm No assumption in input distribution! Randomness is added in the algorithm

For a fixed input, the running time is NOT fixed. The expected time is what we can expect when we run the

algorithm on ANY SINGLE input.

CSE 2331/5331

Page 7: CSE 2331/5331 Topic 5: Prob. Analysis Randomized Alg

Randomized Algorithms

CSE 2331/5331

Page 8: CSE 2331/5331 Topic 5: Prob. Analysis Randomized Alg

Expectation

X is a random variable The expectation of X is

E.g, coin flip

Linearity of expectation:

Conditional expectation:

CSE 2331/5331

Page 9: CSE 2331/5331 Topic 5: Prob. Analysis Randomized Alg

Linearity of Expectation

= expected running time for func2 What is ?

CSE 2331/5331

+ cn

Page 10: CSE 2331/5331 Topic 5: Prob. Analysis Randomized Alg

Conditional Expectation

= expected running time of func2 = expected running time of func3 What is the expected running time of func1?

CSE 2331/5331

Page 11: CSE 2331/5331 Topic 5: Prob. Analysis Randomized Alg

A Randomized Example

CSE 2331/5331

Worst case complexity?Expected case?

Page 12: CSE 2331/5331 Topic 5: Prob. Analysis Randomized Alg

Running Time Analysis

Worst Case:

Expected running time:

CSE 2331/5331

Page 13: CSE 2331/5331 Topic 5: Prob. Analysis Randomized Alg

CSE 2331/5331

Page 14: CSE 2331/5331 Topic 5: Prob. Analysis Randomized Alg

Time Analysis

Worst case:

Expected running time:

CSE 2331/5331

Page 15: CSE 2331/5331 Topic 5: Prob. Analysis Randomized Alg

CSE 2331/5331

A more complicatedvariation.

Page 16: CSE 2331/5331 Topic 5: Prob. Analysis Randomized Alg

Analysis

Worst case:

Expected case:

CSE 2331/5331

Page 17: CSE 2331/5331 Topic 5: Prob. Analysis Randomized Alg

An Example with Recursion

CSE 2331/5331

Page 18: CSE 2331/5331 Topic 5: Prob. Analysis Randomized Alg

Worst case:

Expected running time

Solving this we have

CSE 2331/5331

Page 19: CSE 2331/5331 Topic 5: Prob. Analysis Randomized Alg

Another Example with Recursion

CSE 2331/5331

Page 20: CSE 2331/5331 Topic 5: Prob. Analysis Randomized Alg

Analysis

Worst case:

!

Expected running time:

!

CSE 2331/5331

Page 21: CSE 2331/5331 Topic 5: Prob. Analysis Randomized Alg

Another Example

CSE 2331/5331

Page 22: CSE 2331/5331 Topic 5: Prob. Analysis Randomized Alg

Analysis

Worst case:

Expected running time:

CSE 2331/5331