Presentation is loading. Please wait.

Presentation is loading. Please wait.

CS 312: Algorithm Design & Analysis Lecture #12: Average Case Analysis of Quicksort This work is licensed under a Creative Commons Attribution-Share Alike.

Similar presentations


Presentation on theme: "CS 312: Algorithm Design & Analysis Lecture #12: Average Case Analysis of Quicksort This work is licensed under a Creative Commons Attribution-Share Alike."— Presentation transcript:

1 CS 312: Algorithm Design & Analysis Lecture #12: Average Case Analysis of Quicksort This work is licensed under a Creative Commons Attribution-Share Alike 3.0 Unported License.Creative Commons Attribution-Share Alike 3.0 Unported License Slides by: Eric Ringger, with contributions from Mike Jones, Eric Mercer, Sean Warnick

2 Announcements  Due now: HW #8  Project #7: TSP  Early: Wednesday  Due: next Friday  Sent: link for Leaderboard  Coming up: Google survey for One-time Competition Set

3 Objectives  Sketch the proof of the average case analysis of Quicksort  Apply ideas from probability theory

4 Average Case Analysis

5 Quicksort: Average Case Analysis  What is the Sample Space? 123 132 213 231 312 321

6 Quicksort: Average Case Analysis  What is the probability distribution? Probability 123 132 213 231 312 321 1/n! Uniform

7 Quicksort: Average Case Analysis  Without loss of generality, Choose first element as pivot Probability Pivot Value 123 132 213 231 312 321 1/n! 112233112233 Why does this choice not bias the proof?

8 Quicksort: Average Case Analysis  Do the pivot Probability Pivot Location 123 132 123 123 123 213 1/n! 1st 2nd 3rd

9 Quicksort: Average Case Analysis Probability Pivot Location 1/n! t(0)+t(2) + 2 t(1)+t(1) + 2 t(2)+t(0) + 2 1st 2nd 3rd 123 132 123 123 123 213 Value of Random Variable  What is the Random Variable?Runtime on given input

10 Quicksort: Average Case Analysis  How many of each unique value of the RV are there? Probability Pivot Location 1/n! t(0)+t(2) + 2 t(1)+t(1) + 2 t(2)+t(0) + 2 1st 2nd 3rd 123 132 123 123 123 213 (n-1)! Value of Random Variable

11 Quicksort: Average Case Analysis  Group similar samples into events. Probability (n-1)!/n! = 1/n t(0)+t(2) + 2 t(1)+t(1) + 2 t(2)+t(0) + 2 123 123 123 Value of Random Variable Exemplar

12 Probability Mass Function 1/n …… (a worst case)(best case)(a worst case)

13 Quicksort: Average Case Analysis Running time of each possible pivot selection

14 Quicksort: Average Case Analysis Next goal: Simplify

15 Quicksort: Average Case Analysis Probability 1/n t(0)+t(2) + 2 t(1)+t(1) + 2 t(2)+t(0) + 2 123 123 123 Value of Random Variable

16 Quicksort: Average Case Analysis Next goal: Eliminate some of the t() terms

17 Quicksort: Average Case Analysis Next goal: Simplify

18 Quicksort: Average Case Analysis Next goal: Solve the recurrence

19 Quicksort: Average Case Analysis

20 Summary: Average Case Analysis  We have walked through the process for conducting an average case analysis: 1.Characterize the input  Sample space  Probability distribution 2.Expected value  Define your random variable: running time of algorithm  Derive the probability mass function over possible running times  Compute the expected value of your random variable 3.Algebra & Limit  Requires cleverness with algebra, incl. recurrence relations!  Non-trivial limit 4.Conclusion: Asymptotic Order of Growth

21 Probability theory  I expect you to know and be able to apply the definitions for our terms from probability theory:  Sample space  Sample  Event  Probability distribution  Probability space  Random variable  Value of a random variable  Probability mass function over values of a random variable  Expected value of a random variable (with respect to the probability mass function)

22 Assignment Homework: HW #8.5  A simple average case analysis!


Download ppt "CS 312: Algorithm Design & Analysis Lecture #12: Average Case Analysis of Quicksort This work is licensed under a Creative Commons Attribution-Share Alike."

Similar presentations


Ads by Google