8,999 views
6 6 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
18 18 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)$.
• edited by
2 2 votes
T(n)=T(n/4)+T(3n/4)+O(n)

Solving this using recurrence tree we get

T(n)=O(nlogn)
Position:
Show:

Related questions

3 3 votes
2 2 answers
3.4k
3.4k views
rahuldb asked May 10, 2017
3,376 views
Please show the workingConsider a Quick-sort algorithm that always selects $(n / 5)^{\text {th }}$ smallest as the pivot element using $\mathrm{O}(\mathrm{n})$ time algor...
0 0 votes
1 1 answer
6.7k
6.7k views
sh!va asked Jul 13, 2016
6,739 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...
9 9 votes
2 answers 2 answers
23.4k
23.4k views