1.7k views

Which one of the following is the recurrence equation for the worst case time complexity of the quick sort algorithm for sorting $n$ ( $\geq$ 2) numbers? In the recurrence equations given in the options below, $c$ is a constant.

1. $T(n) = 2 T (n/2) + cn$
2. $T(n) = T ( n - 1) + T(1) + cn$
3. $T(n) = 2T ( n - 1) + cn$
4. $T(n) = T (n/2) + cn$
edited | 1.7k views

B.
Worst case for quick sort happens when $1$ element is on one list and $n-1$ elements on another list.

edited by
+6

But according to Cormen, worst case for Quicksort algo occurs when the partitioning produces one subproblem with n-1 elements and another with zero elements ( the nth element is the pivot which gets added to the end of the first subproblem). In fact, it states that even a partition with a 9:1 proportional split also runs in O(n lg n) time.

+3
Yes. n-1 elements on one list- 0 on other list is because 'pivot' is ignored- which is anyway placed.
+5

So option B should really be

T(n)=T(n-1)+T(0) +cn

+3
Yes. But can't say the given is wrong either.
+5
Yes sir. Asymptotically they are the same.
0
Isn't it option D for quick sort?
0
Option D means we are dividing the elements in half which is not the case for worst condition.
0
can't say the given is wrong because asymptotically they are the same.Is it?

1
2