简体   繁体   English

使用二进制的基数排序

[英]Radix Sort Using Binary

I want to know if it is more efficient to use a Radix sort with Integer values or to convert the values to Binary and then sort them. 我想知道使用带有整数值的基数排序或将值转换为二进制然后对它们进行排序是否更有效。

Can someone explain to me the pro's and con's of sorting values using a Radix sort with Binary numbers instead of just using Integers? 有人可以向我解释使用带有二进制数的Radix排序而不是仅使用整数的排序值的优缺点吗?

For example, I want to sort 5 values. 例如,我要对5个值进行排序。 (170, 2, 19, 40, 100) (170、2、19、40、100)

Using a radix sort what would the Pro's and Con's be of using their binary representations? 如果使用基数排序,那么Pro和Con的二进制表示形式会是什么? (010101010, 0010, 010011, 0101000, 01100100) (010101010、0010、010011、0101000、01100100)

Radix sort is all about sorting binary numbers. 基数排序就是关于二进制数的排序。 Luckily for us, integers are binary numbers too (amongst the best binary numbers actually). 对我们来说幸运的是,整数也是二进制数(实际上是最好的二进制数)。

Another advantage of using the binary form is that we can group on 10 bits instead of 8 bits if we want. 使用二进制形式的另一个优点是,如果需要,我们可以将10位而不是8位分组。 For example, for numbers ranging from 0 - 1000000, 2 x 10 bits could be used for grouping/sorting. 例如,对于范围为0-1000000的数字,可以将2 x 10位用于分组/排序。

Check this for an interesting read, and this for a cool animation. 检查对于一个有趣的阅读,并且对于一个很酷的动画。

With a Radix sort, when using Binary, it will require you to take more passes however you will use less queues. 对于Radix排序,在使用Binary时,它将要求您进行更多遍,但是您将使用更少的队列。

When using Integers, you will use less passes, but will require more queues. 使用Integers时,您将使用较少的通道,但需要更多的队列。

I'm not quite sure what this means in terms of Big O. 我不太确定这对Big O意味着什么。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM