algorithm - 为什么不应该从 MSD 开始实现基数排序?

标签 algorithm sorting

我正在阅读 Cormen 等人的《算法简介》。等人。在他们描述基数排序的部分,他们说:

Intuitively you might sort numbers on their most significant digit, sort each of the resulting bins recursively and then combine the decks in order. Unfortunately since the cards in 9 of the 10 bins must be put aside to sort each of the bins, this procedure generates many intermediate piles of cards that you'd have to keep a track of.

这是什么意思? 我不明白按 MSB 排序会出现问题吗?

最佳答案

考虑以下示例列表进行排序: 170、045、075、090、002、024、802、066、182、332、140、144

  • 按最高有效数字(百位)排序得出:

    • 零百桶:045、075、090、002、024、066

    • 一百个桶:170、182、140、144

    • 三百桶:332

    • 八百桶:802

  • 现在需要对零和百存储桶中的数字按下一位进行排序(其他两个存储桶各只包含一项):

    • 零十:002
    • 二十岁:024
    • 四十岁:045
    • 六十年代:066
    • 七十年代:075
    • 九十年代:090
  • 不需要按最低有效数字(1 位)排序,因为不存在包含多个数字的十位桶。不过,一百个桶的情况并非如此(练习:自己递归排序)。因此,现在已排序的零百桶将按顺序连接起来,与一、三和八百桶相连接,得到:

    002、024、045、066、075、090、140、144、170、182、332、801

您可以看到作者指的是中间递归排序步骤,这在 LSD 基数排序中不是必需的。

关于algorithm - 为什么不应该从 MSD 开始实现基数排序?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12889588/

相关文章:

algorithm - 在可能的情况下,将一组任意间隔转换为一组连续间隔

algorithm - 重新平衡任意 BST?

Linux 命令 : how to sort a file based on differences between columns?

algorithm - 如何以编程方式检测 CV 中的漏洞/个人信息(通过语法分析/解析等...)

c# - RNGCryptoServiceProvider 无法对大随机数进行卡方检验

regex - 将字符集转换为 nfa/dfa 的高效算法

python - 对 Pandas 系列进行排序

tsql - SQL 中的排序

file - 按批处理文件中的名称排序

python - 使用 python 根据卡片的套件和值对卡片进行排序