12
$\begingroup$

I am trying to refresh my knowledge (and hopefully learn more) about Algorithm Analysis. I took a course on this two years ago but I am trying to catch up on what I had learned back then.

The way I am going about it is by doing exercises from the classic text Introduction to Algorithms, 2nd Edition - CLRS.

The problem that I am trying to solve is this:


Exercise 7.2-2
What is the running time of QUICKSORT when all elements of array A have the same value?

My Solution
The running time of QUICKSORT when all elements of array A have the same value will be equivalent to the worst case running of QUICKSORT since no matter what pivot is picked, QUICKSORT will have to go through all the values in A. And since all values are the same, each recursive call will lead to unbalanced partitioning.

Thus the recurrence will be:

$$T(n) = T(n-1) + \Theta(n)$$

The above recurrence has the solution (I will prove this later):

$$T(n) = \Theta(n^2)$$

Hence the running time of QUICKSORT in this case is $$\Theta(n^2)$$


Please verify if I have answered the question appropriately :)

Please let me know if this question should be posted elsewhere in the SE network.

Thanks!

Jake Clawson

  • 5
    That is correct.2011-02-18
  • 0
    In the future you might want to visit http://cstheory.stackexchange.com/2011-06-30
  • 8
    @Emre: This is not a good suggestion. cstheory.SE is intended for *research level* questions, which this one definitely isn't, so it would be downvoted and closed in a blow. This doesn't make it a bad question, of course, far from it!2011-06-30
  • 1
    It is more common (AFAIK) to use uppercase $\Theta$ rather than lowercase $\theta$ for "big-Theta" notation.2011-11-02
  • 0
    The Problems 7-1 on CLRS gives a Hoare's implement of quicksort. The running time of Hoare's is $\Theta(n\log n)$ when all elements have same value.2012-06-28
  • 0
    Absolutely fine.2012-06-28

3 Answers 3