擅长:python、mysql、java
<p>任何<code>O(nlogn)</code><a href="http://en.wikipedia.org/wiki/Sorting_algorithm#Comparison_of_algorithms" rel="nofollow">sorting algorithm</a>都可能比冒泡排序做得更好,但它们是<code>O(nlogn * |S|)</code></p>
<p>但是,可以在<code>O(n*|S|)</code>中对字符串进行排序,其中<code>|S|</code>是使用<a href="http://en.wikipedia.org/wiki/Trie" rel="nofollow">trie</a>和简单的<a href="http://en.wikipedia.org/wiki/Depth-first_search" rel="nofollow">DFS</a>的平均字符串长度。</p>
<p>高级伪码:</p>
<pre><code>1. create a trie from your collection.
2. do a DFS on the trie generated, and add each string
to the list when you reach terminal node.
</code></pre>