Pseudocode:
function bucketSort(array, n) is
buckets <- new array of n empty lists
for i=0 to (length(array)-1) do
insert array[i] into buckets[msbits(array[i], k)]
for i=0 to n-1 do
nextSort(buckets[i])
return the concatenation of buckets[0], ..., buckets[n-1]

Worst case performance: O(n2)
average case performance : O(n+k)
桶排序算法详解
本文介绍了一种名为桶排序的算法,该算法通过将输入数组分配到有限数量的桶中来进行排序,每个桶再分别进行排序。桶排序在平均情况下的时间复杂度为O(n+k),最坏情况为O(n²)。

被折叠的 条评论
为什么被折叠?



