高效的字符串排序算法 [英] Efficient string sorting algorithm

查看:69
本文介绍了高效的字符串排序算法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

通过比较对字符串进行排序(例如,标准的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.

这篇关于高效的字符串排序算法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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