Efficient string sorting algorithm

后端 未结 3 1669
伪装坚强ぢ
伪装坚强ぢ 2021-02-13 18:44

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 t

相关标签:
3条回答
  • 2021-02-13 19:33

    Please search for "Sedgewick Multikey quick sort" (Sedgewick wrote famous algorithms textbooks in C and Java). His algorithm is relatively easy to implement and quite fast. It avoids the problem you are talking above. There is the burst sort algorithm which claims to be faster, but I don't know of any implementation.

    There is an article Fast String Sort in C# and F# that describes the algorithm and has a reference to Sedgewick's code as well as to C# code. (disclosure: it's an article and code that I wrote based on Sedgewick's paper).

    0 讨论(0)
  • 2021-02-13 19:38

    You could build a trie, which should be O(s*n), I believe.

    0 讨论(0)
  • 2021-02-13 19:51

    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.

    0 讨论(0)
提交回复
热议问题