6,074 views
4 votes
4 votes
In quick sort , for sorting n elements , the (n/4)th smallest element is selected as pivot using an O(n) time algorithm. What will be the time complexity?

it is  $\Theta (n^{2})$ , right ?

2 Answers

Best answer
11 votes
11 votes
It would be $\Theta \left(n\log{n} \right)$.

At each level, the array of size n is getting divided in to 2 sub arrays of size (n/4) and (3n/4) along with an extra work for choosing pivot which requires $O \left( n \right)$ time.

So recurrence will be of the form: $T(n) = T\left(\frac{n}{4}\right) + T\left(\frac{3n}{4}\right) + O\left(n\right)$

This can be solved using recursion tree.

Lower bound for this recurrence will be $\Omega \left(n\log_{4}n \right)$, & upper bound will be $O \left(n\log_{\frac{4}{3}}n \right)$,

which gives $T(n) = \Theta \left(n\log{n} \right)$.
2 votes
2 votes
T(n)=T(n/4)+T(3n/4)+O(n)

Solving this using recurrence tree we get

T(n)=O(nlogn)

Related questions

3 votes
3 votes
2 answers
1
0 votes
0 votes
1 answer
2
sh!va asked Jul 13, 2016
5,898 views
A desirable choice for the partitioning element in quick sort is(A) First element of the list(B) Last element of the list(C) Randomly chosen element of the list(D) Median...
8 votes
8 votes
2 answers
3