【发布时间】:2017-02-13 09:16:32
【问题描述】:
如何设计一种算法来对 O(dn) 中的 n 个字符串进行排序,其中 d 是最长字符串中的#of 个字符?
【问题讨论】:
标签: algorithm sorting array-algorithms
如何设计一种算法来对 O(dn) 中的 n 个字符串进行排序,其中 d 是最长字符串中的#of 个字符?
【问题讨论】:
标签: algorithm sorting array-algorithms
您可以使用trie。
创建一个空树。
遍历所有字符串,并将它们放入其中。
按顺序遍历所有 trie 的值,然后输出它们(参见下面 Jean-Baptiste Yunès 建议的 Trie complexity and searching)。
1 的复杂度是恒定的。 2 和 3 的复杂度分别为 O(dn)。
【讨论】: