Exams › GATE › Technical
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
- O(n²)
- O(n log n)
- Θ(n log n)
- O(n³)
Correct answer: O(n²)
Solution
Choosing the central element as the pivot in quicksort can lead to unbalanced partitions, especially if the array is already sorted or nearly sorted, resulting in a worst-case scenario where the algorithm behaves like selection sort, thus having a time complexity of O(n²).
Related GATE Technical questions
⚔️ Practice GATE Technical free + battle 1v1 →