问题
I need help interpreting the formulas from the Quicksort algorithm description in the Clrs book, page 157
My questions are overlayed in the page screenshot. This formula is about QiuckSort Algorithm.
- what is behind(logic) E[X] ... I mean what is happening in quickstart that the authors wrote this formula?
- given n=3, the result is 8, ok, but what does 8 mean semanitcally in quicksort?
回答1:
In order to understand the analysis in the book you cited, you need to understand some concepts from probability theory.
We want to determine the average number of comparisons made by quicksort.
We define some random variables. X_ij = 1 if z_i and z_j are compared, and 0 otherwise. X is a random variable for the total number of comparisons made. Thus X = sum over i and j of X_ij.
E[X] is the expected value of X, i.e. the value "on average". Expectation is linear, so the expectation of a sum is equal to the sum of expectations. That's how the book concludes that the average number of comparisons is equal to the sum over i and j of E[X_ij]. Since X_ij is either 0 or 1, its expected value is the same as the probability of making a comparison between z_i and z_j.
If you're still have trouble following this, you'll need to read up on probability, random variables, and expected values.
来源:https://stackoverflow.com/questions/58683766/what-is-meaning-expected-valuemath-and-what-reason-behind-it-in-quicksort