Efficient string sorting algorithm

Piotr Turek picture Piotr Turek · Aug 7, 2011 · Viewed 23.8k times · Source

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?

Answer

phimuemue picture phimuemue · Aug 7, 2011

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.