What is the worst case time complexity of median of medians quicksort ( pivot is determined by the median of medians which take O(n) time to find )?
Asked
Active
Viewed 1,932 times
0
-
If I remember my algorithms correctly, I think it's `O(n^2)`. – Peter Olson Nov 22 '14 at 13:43
-
Why ? Median of medians ensures good partitions in each case . – Naman Jain Nov 22 '14 at 13:47
1 Answers
2
The approximate median-selection algorithm can also be used as a pivot strategy in quicksort, yielding an optimal algorithm, with worst-case complexity O(n log n).
This is because the median of medians algorithm prevents the bad partitioning that would occur in naive quicksort on an already sorted array.
![](../../users/profiles/546661.webp)
Peter Olson
- 121,487
- 47
- 188
- 235