cse 2331/5331 topic 5: prob. analysis randomized alg
TRANSCRIPT
![Page 1: CSE 2331/5331 Topic 5: Prob. Analysis Randomized Alg](https://reader036.vdocuments.site/reader036/viewer/2022062421/56649cfa5503460f949cbfbc/html5/thumbnails/1.jpg)
CSE 2331/5331
CSE 2331/5331
Topic 5:
Prob. Analysis
Randomized Alg.
![Page 2: CSE 2331/5331 Topic 5: Prob. Analysis Randomized Alg](https://reader036.vdocuments.site/reader036/viewer/2022062421/56649cfa5503460f949cbfbc/html5/thumbnails/2.jpg)
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](https://reader036.vdocuments.site/reader036/viewer/2022062421/56649cfa5503460f949cbfbc/html5/thumbnails/3.jpg)
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](https://reader036.vdocuments.site/reader036/viewer/2022062421/56649cfa5503460f949cbfbc/html5/thumbnails/4.jpg)
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](https://reader036.vdocuments.site/reader036/viewer/2022062421/56649cfa5503460f949cbfbc/html5/thumbnails/5.jpg)
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](https://reader036.vdocuments.site/reader036/viewer/2022062421/56649cfa5503460f949cbfbc/html5/thumbnails/6.jpg)
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](https://reader036.vdocuments.site/reader036/viewer/2022062421/56649cfa5503460f949cbfbc/html5/thumbnails/7.jpg)
Randomized Algorithms
CSE 2331/5331
![Page 8: CSE 2331/5331 Topic 5: Prob. Analysis Randomized Alg](https://reader036.vdocuments.site/reader036/viewer/2022062421/56649cfa5503460f949cbfbc/html5/thumbnails/8.jpg)
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](https://reader036.vdocuments.site/reader036/viewer/2022062421/56649cfa5503460f949cbfbc/html5/thumbnails/9.jpg)
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](https://reader036.vdocuments.site/reader036/viewer/2022062421/56649cfa5503460f949cbfbc/html5/thumbnails/10.jpg)
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](https://reader036.vdocuments.site/reader036/viewer/2022062421/56649cfa5503460f949cbfbc/html5/thumbnails/11.jpg)
A Randomized Example
CSE 2331/5331
Worst case complexity?Expected case?
![Page 12: CSE 2331/5331 Topic 5: Prob. Analysis Randomized Alg](https://reader036.vdocuments.site/reader036/viewer/2022062421/56649cfa5503460f949cbfbc/html5/thumbnails/12.jpg)
Running Time Analysis
Worst Case:
Expected running time:
CSE 2331/5331
![Page 13: CSE 2331/5331 Topic 5: Prob. Analysis Randomized Alg](https://reader036.vdocuments.site/reader036/viewer/2022062421/56649cfa5503460f949cbfbc/html5/thumbnails/13.jpg)
CSE 2331/5331
![Page 14: CSE 2331/5331 Topic 5: Prob. Analysis Randomized Alg](https://reader036.vdocuments.site/reader036/viewer/2022062421/56649cfa5503460f949cbfbc/html5/thumbnails/14.jpg)
Time Analysis
Worst case:
Expected running time:
CSE 2331/5331
![Page 15: CSE 2331/5331 Topic 5: Prob. Analysis Randomized Alg](https://reader036.vdocuments.site/reader036/viewer/2022062421/56649cfa5503460f949cbfbc/html5/thumbnails/15.jpg)
CSE 2331/5331
A more complicatedvariation.
![Page 16: CSE 2331/5331 Topic 5: Prob. Analysis Randomized Alg](https://reader036.vdocuments.site/reader036/viewer/2022062421/56649cfa5503460f949cbfbc/html5/thumbnails/16.jpg)
Analysis
Worst case:
Expected case:
CSE 2331/5331
![Page 17: CSE 2331/5331 Topic 5: Prob. Analysis Randomized Alg](https://reader036.vdocuments.site/reader036/viewer/2022062421/56649cfa5503460f949cbfbc/html5/thumbnails/17.jpg)
An Example with Recursion
CSE 2331/5331
![Page 18: CSE 2331/5331 Topic 5: Prob. Analysis Randomized Alg](https://reader036.vdocuments.site/reader036/viewer/2022062421/56649cfa5503460f949cbfbc/html5/thumbnails/18.jpg)
Worst case:
Expected running time
Solving this we have
CSE 2331/5331
![Page 19: CSE 2331/5331 Topic 5: Prob. Analysis Randomized Alg](https://reader036.vdocuments.site/reader036/viewer/2022062421/56649cfa5503460f949cbfbc/html5/thumbnails/19.jpg)
Another Example with Recursion
CSE 2331/5331
![Page 20: CSE 2331/5331 Topic 5: Prob. Analysis Randomized Alg](https://reader036.vdocuments.site/reader036/viewer/2022062421/56649cfa5503460f949cbfbc/html5/thumbnails/20.jpg)
Analysis
Worst case:
!
Expected running time:
!
CSE 2331/5331
![Page 21: CSE 2331/5331 Topic 5: Prob. Analysis Randomized Alg](https://reader036.vdocuments.site/reader036/viewer/2022062421/56649cfa5503460f949cbfbc/html5/thumbnails/21.jpg)
Another Example
CSE 2331/5331
![Page 22: CSE 2331/5331 Topic 5: Prob. Analysis Randomized Alg](https://reader036.vdocuments.site/reader036/viewer/2022062421/56649cfa5503460f949cbfbc/html5/thumbnails/22.jpg)
Analysis
Worst case:
Expected running time:
CSE 2331/5331