是否有可能来计算数字列表更好的中位数比为O(n log n)的?中位数、有可能、比为、数字

2023-09-11 03:59:22 作者:奶味小仙女

我知道,这是可以计算的数字在O(n)的一个列表的平均值。但是,我们的中位数?有没有什么比排序更好的算法(为O(n log n)的)和查找中量元素(或平均两个中间元素,如果是偶数在列表中的项目)?

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 middle element (or mean of two middle elements if an even number of items in list)?

推荐答案

是的。您可以为O(n)这样做(确定性)。