首页 > 其他 > 详细

Kth order statistcs

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

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

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

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!