arXivDaily arXiv每日学术速递 周一至周五更新
感恩节,周五至周末无更新,大家顺遂。周一再来吧
arXiv 1805.08612cs.DS
收藏

关于TimSort的最坏情况复杂性

On the Worst-Case Complexity of TimSort

Nicolas Auger, Vincent Jugé, Cyril Nicaud, Carine Pivoteau

摘要:

TimSort是2002年为Python设计的一个有趣的排序算法,它的最坏情况复杂度被宣布,但直到我们最近的预印本才被证明。实际上,TimSort有两个稍微不同的版本,目前分别在Python和Java中实现。我们提出了一个教学和有见地的证明,Python版本运行在$\mathcal{O}(n\log n)$。我们在分析中使用的方法也适用于Java版本,尽管并非没有非常复杂的技术细节。作为我们研究的副产品,我们发现了Java实现中的一个错误,该错误可能导致排序方法在执行过程中失败。我们还证明了Python的TimSort运行时间是$\mathcal{O}(n + n\log ρ)$,其中$ρ$是运行次数(即最大单调序列),这是一个很自然的参数,也是TimSort在部分排序输入上表现良好的部分解释。

英文摘要:

TimSort is an intriguing sorting algorithm designed in 2002 for Python, whose worst-case complexity was announced, but not proved until our recent preprint. In fact, there are two slightly different versions of TimSort that are currently implemented in Python and in Java respectively. We propose a pedagogical and insightful proof that the Python version runs in $\mathcal{O}(n\log n)$. The approach we use in the analysis also applies to the Java version, although not without very involved technical details. As a byproduct of our study, we uncover a bug in the Java implementation that can cause the sorting method to fail during the execution. We also give a proof that Python's TimSort running time is in $\mathcal{O}(n + n\log ρ)$, where $ρ$ is the number of runs (i.e. maximal monotonic sequences), which is quite a natural parameter here and part of the explanation for the good behavior of TimSort on partially sorted inputs.

机构、总结、中文摘要均由AI分析而来,可能存在错误,请以论文正文为准。

↑