Is it possible to calculate median of a list of numbers better than O(n log n)?

前端 未结 7 917
攒了一身酷
攒了一身酷 2021-02-14 04:30

I know that it is possible to calculate the mean of a list of numbers in O(n). But what about the median? Is there any better algorithm than sort (O(n log n)) and lookup middl

7条回答
  •  遇见更好的自我
    2021-02-14 04:56

    This link has popped up recently on calculating median: http://matpalm.com/median/question.html .

    In general I think you can't go beyond O(n log n) time, but I don't have any proof on that :). No matter how much you make it parallel, aggregating the results into a single value takes at least log n levels of execution.

提交回复
热议问题