桶分类算法 [英] Algorithms for bucket sort
问题描述
如何对包含负数的整数数组进行存储桶排序?
而且,存储桶排序和计数排序之间有什么区别?
How can I bucket sort an array of integers that contains negative numbers?
And, what's the difference between bucket sort and counting sort?
推荐答案
这基本上是仅链接的答案,但它为您提供了提出一个好的问题所需的信息.
This is basically a link only answer but it gives you the information you need to formulate a good question.
Wikipedia的第1步(其中设置最初为空的存储桶阵列")将需要包含用于负数的存储桶.
Wikipedia's step 1, where you "Set up an array of initially empty buckets", will need to include buckets for negative numbers.
与计数排序相比,存储桶排序需要链表,动态数组或大量预分配的内存来保存每个存储桶中的项目集,而计数排序则每个存储桶仅存储一个数字(项目计数) ."
"Compared to counting sort, bucket sort requires linked lists, dynamic arrays or a large amount of preallocated memory to hold the sets of items within each bucket, whereas counting sort instead stores a single number (the count of items) per bucket."
这篇关于桶分类算法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!