I know that the time complexity of quick sort in the worst case is $\Theta(n^2)$ and in the average case is $\Theta(n \log n)$. Can it be $\Theta(n\sqrt n)$ for certain inputs?

  • 3
    $\begingroup$ In the average case it's $\Theta(n\log n)$. It can probably be $\Theta(n\sqrt{n})$ for certain inputs of a certain structure. I suggest looking up the best and worst cases for quicksort, and trying to combine them. $\endgroup$ Feb 7, 2018 at 13:08

1 Answer 1


Assume the array is sorted. If you always pick the element at n/2 as pivot then the time is O(n log n). If you always pick the first or last element it’s $O(n^2)$.

So which pivot gives you $O(n^{1.5})$?

  • $\begingroup$ The third quarter? $\endgroup$
    – Ahmad
    Feb 8, 2018 at 5:54
  • 1
    $\begingroup$ Can you give a formal proof? $\endgroup$
    – Mr. Sigma.
    Feb 8, 2018 at 12:37
  • $\begingroup$ This answer is very much incomplete. And misleading too, for any constant $c$, if you always pick the element at $cn$ as your pivot the complexity is $\Theta(n \log n)$, and never $\Theta(n\sqrt n)$. $\endgroup$
    – orlp
    Sep 28, 2019 at 8:17
  • $\begingroup$ orlp, how is this misleading? Obviously picking the element at index cn for fixed 0 < c < n will not lead to Theta(n^(3/2)). So that is not the answer. But there is a simple answer. And finding that simple answers helps you understanding how likely / unlikely this case is. $\endgroup$
    – gnasher729
    Jun 16, 2022 at 15:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.