码迷,mamicode.com
首页 > 其他好文 > 详细

Kth order statistcs

时间:2014-08-19 04:50:43      阅读:200      评论:0      收藏:0      [点我收藏+]

标签:io   for   ar   art   cti   size   ef   on   

Selection:

selection is a trivial problem if the input numbers are sorted. If we use a sorting algorithm having O(nlgn) worst case running time, then the selection problem can be solved in O(nlgn) time. But using a sorting is more like using a cannon to shoot a fly since only one number needs to computed.

O(n) expected-time selection using the randomized partition.

Idea: In order to find the k-th order statistics in a region of size n, use the randomized partition to split the region into two subarrays. Let s-1 and n-s be the size of the left subarray and the size of the right subarray. If k=s, the pivot is the key that‘s looked for. If k<= s-1, look for the k-th element in the left subarray. Otherwise, look for the (k-s)-th one in the right subarray.

Kth order statistcs,布布扣,bubuko.com

Kth order statistcs

标签:io   for   ar   art   cti   size   ef   on   

原文地址:http://www.cnblogs.com/miaoz/p/3921120.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!