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

前端 未结 7 862
轻奢々
轻奢々 2021-02-14 04:24

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:36

    Try the randomized algorithm, the sampling size (e.g. 2000) is independent from the data size n, still be able to get sufficiently high (99%) accuracy. If you need higher accuracy, just increase sampling size. Using Chernoff bound can proof the probability under a certain sampling size. I've write some JavaScript Code to implement the algorithm, feel free to take it. http://www.sfu.ca/~wpa10

提交回复
热议问题