[WPI] [cs2223] [cs2223 text] [News] [Syllabus] [Classes] [Class 15]
This is the detailed calculation of the average complexity of the quicksort algorithm, as mentioned on the Class 15 page. The goal is to calculate the solution of this recurrence relation:
Write out some of the terms in the summation:
The two columns are the same but reversed, so we can simplify the summation:
The last transformation just uses an important propery of averages: the average of average values is the same as the average of the original values. Thus we can get rid of the expected value notation and remember that our symbols refer to the average values.
We also multiplied both sides of the equation by N.
To solve the summation, we use a form of the perturbation method introduced in Class 11. We change the limits on the summation in the usual way.
The previous term in the sequence is:
Using a transformation of the variable K to change the limits on the summation, this becomes:
We now have two equations with the same summation. Subtract the equations:
This recurrence relation is first-order and linear but the coefficients are not constant, so we use the Method of Summing Factors in the Recurrence Notes with these values:
The initial condition says that an empty array takes no time to sort. We will need the products of the ,bn
Now we can use the general form of the summing factor to find the solution:
The first summation can be solved using the usual change of variables and the definition of the Harmonic sequence:
The second summation is even smaller than this so the above equation represents an upper bound on the part of the solution in square brackets. We can continue further by using partial fraction expansion:
Combining everything, we obtain the solution:
To find the order of this solution, use the approximation for the harmonic series which we introduced in Class 4:
[cs2223 text] [News] [Syllabus] [Classes] [Class 15] |