<p>We present a simple linear time algorithm for the following sorting problem: Given <i>n</i> words <InlineEquation ID="IEq1"> <EquationSource Format="TEX">\(A_1,\ldots ,A_n\)</EquationSource> </InlineEquation>, find a permutation <InlineEquation ID="IEq2"> <EquationSource Format="TEX">\(\{\pi _1,\ldots ,\pi _n\}\)</EquationSource> </InlineEquation> of <InlineEquation ID="IEq3"> <EquationSource Format="TEX">\(1,\ldots ,n\)</EquationSource> </InlineEquation> so that <InlineEquation ID="IEq4"> <EquationSource Format="TEX">\((A_{\pi _1})^\omega \le \ldots \le (A_{\pi _n})^\omega\)</EquationSource> </InlineEquation>, where <InlineEquation ID="IEq5"> <EquationSource Format="TEX">\((A)^\omega\)</EquationSource> </InlineEquation> denotes the infinitely repeating string <InlineEquation ID="IEq6"> <EquationSource Format="TEX">\(AAA\ldots\)</EquationSource> </InlineEquation>. Let <i>L</i> denote the total length of the given strings. We note that the running time of our algorithm is <i>O</i>(<i>L</i>) even if the size of alphabet is beyond <i>O</i>(1). We also present an <InlineEquation ID="IEq7"> <EquationSource Format="TEX">\(O(L+n \log n)\)</EquationSource> </InlineEquation> time algorithm for the restricted model where we are only allowed to compare symbols. In other words, the main result of this paper is that the time complexity of sorting <InlineEquation ID="IEq3000"> <EquationSource Format="TEX">\(A_1,\ldots, A_n\)</EquationSource> </InlineEquation> in omega-order is the same as that of sorting them in lexicographic order under all common models (bounded alphabet, unbounded alphabet, compare-based model). Our main results find applications in related problems such as rearranging and concatenating given words so that the result is lexicographically smallest or largest.</p>

错误:搜索内容不能为空,请输入英文关键词
错误:关键词超出字数限制,请精简
高级检索

Simple linear time algorithm for sorting strings in omega-order with applications

  • Ruixi Luo,
  • Taikun Zhu,
  • Kai Jin

摘要

We present a simple linear time algorithm for the following sorting problem: Given n words \(A_1,\ldots ,A_n\) , find a permutation \(\{\pi _1,\ldots ,\pi _n\}\) of \(1,\ldots ,n\) so that \((A_{\pi _1})^\omega \le \ldots \le (A_{\pi _n})^\omega\) , where \((A)^\omega\) denotes the infinitely repeating string \(AAA\ldots\) . Let L denote the total length of the given strings. We note that the running time of our algorithm is O(L) even if the size of alphabet is beyond O(1). We also present an \(O(L+n \log n)\) time algorithm for the restricted model where we are only allowed to compare symbols. In other words, the main result of this paper is that the time complexity of sorting \(A_1,\ldots, A_n\) in omega-order is the same as that of sorting them in lexicographic order under all common models (bounded alphabet, unbounded alphabet, compare-based model). Our main results find applications in related problems such as rearranging and concatenating given words so that the result is lexicographically smallest or largest.