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

Post on 17-Dec-2015

224 views 3 download

transcript

CSE 2331/5331

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

First Example

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

CSE 2331/5331

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

SeqSearch Alg

Expected running time =

If we assume = 0 All permutations are equally likely

implies Then expected running time =

CSE 2331/5331

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

Randomized Algorithms

CSE 2331/5331

Expectation

X is a random variable The expectation of X is

E.g, coin flip

Linearity of expectation:

Conditional expectation:

CSE 2331/5331

Linearity of Expectation

= expected running time for func2 What is ?

CSE 2331/5331

+ cn

Conditional Expectation

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

CSE 2331/5331

A Randomized Example

CSE 2331/5331

Worst case complexity?Expected case?

Running Time Analysis

Worst Case:

Expected running time:

CSE 2331/5331

CSE 2331/5331

Time Analysis

Worst case:

Expected running time:

CSE 2331/5331

CSE 2331/5331

A more complicatedvariation.

Analysis

Worst case:

Expected case:

CSE 2331/5331

An Example with Recursion

CSE 2331/5331

Worst case:

Expected running time

Solving this we have

CSE 2331/5331

Another Example with Recursion

CSE 2331/5331

Analysis

Worst case:

!

Expected running time:

!

CSE 2331/5331

Another Example

CSE 2331/5331

Analysis

Worst case:

Expected running time:

CSE 2331/5331