arXivDaily arXiv每日学术速递 周一至周五更新
arXiv 1304.0988cs.DSmath.PR
收藏

双枢轴快速排序的平均情况与分布分析

Average Case and Distributional Analysis of Dual-Pivot Quicksort

Sebastian Wild, Markus E. Nebel, Ralph Neininger

摘要:

在2009年,Oracle在其Java 7运行时库中替换了长期服务的排序算法,由Vladimir Yaroslavskiy提供了一个新的双枢轴Quicksort变体。这个决定是基于Yaroslavskiy的实现在运行时实验中惊人的良好性能。在那个时候,还没有对该算法的精确研究来解释其优越的性能-相反:以前对其他双枢轴快速排序变体的理论研究甚至不鼓励使用两个枢轴。仅在2012年,两位作者对雅罗斯拉夫斯基算法的简化版本进行了平均案例分析,证明节省比较次数是可能的。然而,Yaroslavskiy的算法需要更多的交换,这使得分析不确定。为了解决这个问题,我们在这里将我们的分析扩展到Knuth的完全详细的风格:我们确定执行的Java字节码指令的确切数量。令人惊讶的是,Yaroslavskiy的算法需要比经典快速排序的简单实现稍微多一点的字节码指令-与观察到的运行时间相矛盾。就像在Oracle的库实现中一样,我们在小的子问题上使用Insertionsort,并表明它确实在字节码方面加快了Yaroslavskiy的Quicksort;但即使有最佳Insertionsort阈值,新的Quicksort变体平均需要稍微多一点的字节码指令。最后,我们表明,(适当规范化)的成本Yaroslavskiy的算法收敛到一个随机变量,其分布特征在于由一个不动点方程。由此,我们计算了成本的方差,并表明对于大n,成本集中在其均值附近。

英文摘要:

In 2009, Oracle replaced the long-serving sorting algorithm in its Java 7 runtime library by a new dual-pivot Quicksort variant due to Vladimir Yaroslavskiy. The decision was based on the strikingly good performance of Yaroslavskiy's implementation in running time experiments. At that time, no precise investigations of the algorithm were available to explain its superior performance - on the contrary: Previous theoretical studies of other dual-pivot Quicksort variants even discouraged the use of two pivots. Only in 2012, two of the authors gave an average case analysis of a simplified version of Yaroslavskiy's algorithm, proving that savings in the number of comparisons are possible. However, Yaroslavskiy's algorithm needs more swaps, which renders the analysis inconclusive. To force the issue, we herein extend our analysis to the fully detailed style of Knuth: We determine the exact number of executed Java Bytecode instructions. Surprisingly, Yaroslavskiy's algorithm needs sightly more Bytecode instructions than a simple implementation of classic Quicksort - contradicting observed running times. Like in Oracle's library implementation we incorporate the use of Insertionsort on small subproblems and show that it indeed speeds up Yaroslavskiy's Quicksort in terms of Bytecodes; but even with optimal Insertionsort thresholds the new Quicksort variant needs slightly more Bytecode instructions on average. Finally, we show that the (suitably normalized) costs of Yaroslavskiy's algorithm converge to a random variable whose distribution is characterized by a fixed-point equation. From that, we compute variances of costs and show that for large n, costs are concentrated around their mean.

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

↑