1,057 views

1 Answer

Best answer
5 5 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}$

• selected by
Position:
Show:

Related questions

1 1 vote
1 1 answer
819
819 views
meethunjadhav asked Jul 30, 2018
819 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.
1 1 vote
1 1 answer
932
932 views
chetan raghav asked Sep 3, 2017
932 views
Given an unsorted array. The array has this property that every element in array is at most k distance from its position in sorted array where k is a positive integer sma...
0 0 votes
1 1 answer
663
663 views
Shailendra Patel asked Nov 1, 2016
663 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 0 votes
1 answers 1 answer
1.2k
1.2k views
ajit asked Sep 7, 2015
1,177 views
given a sorted array of distinct integers A[1........n], you want to find out whether there is an index i for which A[i]=i.if this problem is solved using divide and conq...