114 views
0 votes
0 votes
In quick sort, n numbers the (n/10)th element is selected as pivot using n^2 sortimng time complexity what will be the time complexity of quick sort is.....

a)O(nlogn)

b)O(n^2)

c)O(n^3)

d)O(n)

1 Answer

4 votes
4 votes

In quick sort, $\frac{n}{10}$ element is chosen as pivot using an algorithm which take time as $n^{2}$.

In worst case the $\frac{n}{10}$ element is either smallest or larget element in the input, then in 

that case it will get placed at exteme end.

Then, 

$T(n) = T(n-1) + n + n^{2}$ 

(Here, n is for PARTITION algorithm and $n^{2}$ is for the algorithm used for selection of pivot element)

As $n^{2}$ > $n$, then we can neglect it.

So,  $T(n) = T(n-1) + n^{2}$

By substitution, we get,

$T(n) = 1^{2} + 2^{2} +3^{2} + - - - - - - + (n-1)^{2} + n^{2}$

T(n) = $\frac{n(n+1)(2n+1)}{6}$

T(n) = O($n^{3}$)

 

Hence, Option C is Correct Answer.


NOTE : Here, we have to be careful because question is saying $\frac{n}{10}$ element is chosen as pivot.

If question says $\frac{n}{10}$ smallest or $\frac{n}{10}$ largest element is chosen as pivot then our equation

will change to T(n) = $T(\frac{n}{10}) + T(\frac{9n}{10}) + n + n^{2}$

ago edited ago by

Related questions

1 votes
1 votes
1 answer
1
meethunjadhav asked Jul 30, 2018
454 views
suppose merge sort takes 2 sec to sort a set of 64 keys then how much time will take to sort a set of 512 keys?here, ans is 24 sec how it is plz explain me.
0 votes
0 votes
1 answer
3
Shailendra Patel asked Nov 1, 2016
392 views
Merging K sorted list each of size n/k into one sorted list of n-elements using Heap Sort will take how much time?
0 votes
0 votes
1 answer
4