本文介绍了高效的字符串排序算法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
通过比较对字符串进行排序(例如,标准的QuickSort +类似strcmp的函数)可能会有点慢,尤其是对于共享公共前缀的长字符串(比较函数需要O(s)时间,其中s是字符串的长度),因此标准解决方案的复杂度为O(s * nlog n).有没有已知的更快算法?
Sorting strings by comparisons (e.g. standard QuickSort + strcmp-like function) may be a bit slow, especially for long strings sharing a common prefix (the comparison function takes O(s) time, where s is the length of string), thus a standard solution has the complexity of O(s * nlog n). Are there any known faster algorithms?
推荐答案如果您知道字符串仅包含某些字符(几乎总是这样),则可以使用BucketSort 或 RadixSort .
If you know that the string consist only of certain characters (which is almost always the case), you can use a variant of BucketSort or RadixSort.
更多推荐
高效的字符串排序算法
发布评论