edited by
30,887 views
61 votes
61 votes

You have an array of $n$ elements. Suppose you implement quicksort by always choosing the central element of the array as the pivot. Then the tightest upper bound for the worst case performance is

  1. $O(n^2)$
  2. $O(n \log n)$
  3. $\Theta(n\log n)$
  4. $O(n^3)$
edited by

10 Answers

1 votes
1 votes

I think the simplest way to solve this question is if we consider an array of n elements where all the elements are the same since it is not mentioned in the question that the elements need to be distinct. In this case Quick Sort will take $O(n^{2})$ time. Therefore the option will be A.

1 votes
1 votes

The tightest upper bound for the worst case performance of quicksort when always choosing the central element of the array as the pivot is O(n^2).

This is because if the input array is already sorted or if the array is sorted in the reverse order and the pivot is always the central element, the partition will always result in one side having n-1 elements and the other side having 0 elements, leading to a worst-case scenario where each partition takes O(n) time and the overall quicksort takes O(n^2) time.

It's important to note that this is an worst-case scenario, and in practice, the average case performance of quicksort is O(n*log(n)) which makes it a good choice for sorting large data sets in most cases.

Also, this worst case is not so likely to happen if the pivot is chosen randomly, rather than always using the central element as pivot.

0 votes
0 votes

So here, we choose central element as pivot element.

We need to evaluate the worst case performance.

We, know that Quicksort will perform worst when the pivot element is either maximum or minimum.

So, my central element can be maximum or minimum. Central element does not mean the median element.

So my worst case performance would be O($n^{2}$)

Answer:

Related questions

37 votes
37 votes
11 answers
4