摘要:
选择算法也就是求一个无序数组中第K大(小)的元素的值的算法,同通常的Top K等算法密切相关。在CLRS中提到了一种最坏情况线性运行时间的选择算法,在书中给出了如下的文字描述(没有直接给出伪代码)。1.Divide n elements into groups of 52.Find median of each group (How? How long?)3.Use Select() recursively to find median x of the n/5 medians4.Partition the n elements around x. Let k = rank(x)5.if .. 阅读全文