GATE | GATE-CS-2014-(Set-3) | Question 24

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
(A) O(n2)
(B) O(nLogn)
(C) Theta(nLogn)
(D) O(n3)


Answer: (A)

Explanation: For any input, there are some permutations for which worst case will be O(n2).  In some case, choosing the middle element minimizes the chances of encountering O(n2), but in worst case it can go to O(n2). Whichever element we take as Pivot, either first or middle, worst case will be O(n2since Pivot is fixed in position. While choosing a random pivot minimizes the chances of encountering worst case i.e. O(n2).

Refer this article on Quick Sort.

Quiz of this Question



My Personal Notes arrow_drop_up