0

Personally, I think the median of medians is not the real median. Correct?
So if the above statement is true, why using the median of medians as the pivot to partition the array to find the Kth min elem's time complexity worst case is O(n)? The "n" is the num of elems.

zproject89
  • 205
  • 5
  • 18

1 Answers1

2

Median of medians is indeed only an approximation, not necessarily the actual median.

It is used as an optimization, to calculate the pivot for a partition of the array in algorithms like Quicksort or Quickselect, such that the worst case complexity of O(n^2) is avoided.

Wikipedia article about it, saying:

Although this approach optimizes quite well, it is typically outperformed in practice by instead choosing random pivots, which has average linear time for selection and average linearithmic time for sorting, and avoids the overhead of computing the pivot.

chrk
  • 3,551
  • 2
  • 35
  • 43