桶分类算法 [英] Algorithms for bucket sort

查看:109
本文介绍了桶分类算法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何对包含负数的整数数组进行存储桶排序?
而且,存储桶排序和计数排序之间有什么区别?

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆