摘要: 在一组随机排列的数中找出第k小的,这个元素称为k-th Order Statistic。能想到的最直观的算法肯定是先把这些数排序然后取第k个,时间复杂度和排序算法相同,可以是Θ(nlgn),但它也有平均情况下时间复杂度是Θ(n)的算法,将快速排序算法稍加修改就可以解决这个问题: 1 /* 2 **Find out the K-th small number of a set of random numbers with O(n) 3 **2011.10.25 4 **By LYLtim 5 */ 6 7 #include<stdio.h> 8 #include<stdlib. 阅读全文
posted @ 2011-10-29 08:15 LYLtim 阅读(421) 评论(0) 推荐(0) 编辑