简体   繁体   中英

What is the time complexity of a modified quick sort algorithm?

We use the regular quicksort algorithm. The pivot chosen is the median, but in order to find the median it takes Theta(n^{2006/2005}) Worst case.

Why is the worst case of the algorithm equal Theta(n^{2006/2005}) and not Theta(n^{2006/2005} * logn) ?

First, you need to understand that each "iteration" does NOT take N^2006/2005 where N is the size of the ORIGINAL array, in fact - since this is a superlinear function, finding the median in 2 halves of the array is easier than finding it in the big array.

To formally prove it, we will first, define the recursive complexity formula: (for simplicity we assume the median takes exactly n^2006/2005 , but it is easy to modify this for upper bound of C*n^2006/2005 .)

T(n) = n^2006/2005 + 2T(n/2)

Now, we can show it by induction by proving

T(n) <= 2* n^2006/2005

The base clause here is trivial for small enough value of n .
Assume for each k<n , the assumption T(k) <= 2*(n/2)^2006/2005 holds.

T(n) = n^2006/2005 + 2T(n/2) <= (i.h.) 
     <= n^2006/2005 + 2*(2*(n/2)^2006/2005) =
     = n^2006/2005 + 4 * (n/2)^2006/2005 =
     = (*) 2^(2004/2005) *n^(2006/2005) + n^(2006/2005)
     <= 2*n^(2006/2005)

The (*) equality comes from wolfram alpha , and you can derive it as well using some algebra on the formula.


Also note, this does not contradict the fact that sorting is Omega(nlogn) , since n^(1+epsilon) > nlogn for every epsilon>0 , and for large enough values of n .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM