in Algorithms edited by
11,439 views
33 votes
33 votes

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$
in Algorithms edited by
11.4k views

4 Comments

What does cn indicates ?
0
0
It means any constant which is multiplied to $\mathbf n$.
0
0
In quick sort,

one thing to notice generally we don’t take pivot in recurrence relation but here we considered the pivot as well.
0
0

 

  • T(n-1): Time taken to recursively sort the sub array of size (n-1) when partitioning is performed.
  •  
  • T(1): Time taken to recursively sort the sub array of size 1 when partitioning is performed (base case).
  •  
  • cn: The time taken for the partitioning step, where "c" is a constant representing the time taken per element during partitioning, and "n" is the size of the array being partitioned.
0
0

3 Answers

42 votes
42 votes
Best answer

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

edited by
by

4 Comments

Option D means we are dividing the elements in half which is not the case for worst condition.
0
0
can't say the given is wrong because asymptotically they are the same.Is it?
0
0
For Worst Case correct Recurrences are:

$\mathbf{T(n) = T(0) + T(n-1) + \theta (n)}$

which is the same as:

$\mathbf{T(n) = T(n-1) + \theta (n)}$

The solution of this recurrence is $\mathbf{\theta (n)}$

Maybe the examiner have something to do with $\mathbf{n \ge 2}$ case. If this isn't the case, then the options are definitely wrong $\color{blue} {\text{According to Cormen and Wikipedia.}}$
0
0
0 votes
0 votes
Quick sort worst case time complexity is n^2, when the array is sorted or almost sorted then Quicksort algorithm runs in O(n^2) time.

The recurrence relation for Quick sort worst case time complexity is

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

Hence, B is Answer.
0 votes
0 votes
If the pivot is chosen as the last position then there is a left recursive of size (n-1) or right recursive call of size 0.

1.Partition function->O(n)

2.T(n-1) time in left recursive call

3.T(1) time in right recursive call

Recurrence relation: T(n-1)+T(1)+cn

Option B is correct
Answer:

Related questions