Open In App

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

Like Article
Like
Save
Share
Report

You have an array of n elements. Suppose you implement quick sort 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(n*log(n))

(C)

Theta(n*log(n))

(D)

O(n3)



Answer: (A)

Explanation:

For any input, there are some permutations for which worst case will be O(n2).  In some cases, 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(n2) since 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
Please comment below if you find anything wrong in the above post


Last Updated : 10 Nov, 2017
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads