arXivDaily arXiv每日学术速递 周一至周五更新
arXiv 1811.00833cs.DS
收藏

使用QuickMergesort的最坏情况有效排序

Worst-Case Efficient Sorting with QuickMergesort

Stefan Edelkamp, Armin Weiß

摘要:

排序问题的两个最突出的解决方案是Quicksort和Mergesort。虽然快速排序平均速度非常快,但合并排序还提供了最坏情况的保证,但需要额外的空间来存储线性数量的元素。然而,最坏情况下的有效就地排序仍然是一个挑战:标准解决方案Heapsort存在缓存行为不佳的问题,并且对于缓存内实例来说也不是太快。在这项工作中,我们提出了中位数的中位数QuickMergesort(MoMQuickMergesort),QuickMergesort的一个新的变种,它结合了Quicksort与Mergesort允许后者实施到位。我们的新变体应用中位数的中位数算法选择枢轴,以规避二次最坏的情况。事实上,我们表明,它最多使用$n \log n + 1.6n$比较$n$足够大。我们通过实验证实了理论估计,并表明新算法的性能优于堆排序,并且仅比Introsort(stdlibc++的std::sort实现)慢10%左右,这对最坏情况的保证相当差。我们还模拟了最坏的情况,它只比平均情况慢10%左右。特别是,新算法是一个自然的候选人,以取代堆排序作为一个最坏情况下的塞子在Introsort。

英文摘要:

The two most prominent solutions for the sorting problem are Quicksort and Mergesort. While Quicksort is very fast on average, Mergesort additionally gives worst-case guarantees, but needs extra space for a linear number of elements. Worst-case efficient in-place sorting, however, remains a challenge: the standard solution, Heapsort, suffers from a bad cache behavior and is also not overly fast for in-cache instances. In this work we present median-of-medians QuickMergesort (MoMQuickMergesort), a new variant of QuickMergesort, which combines Quicksort with Mergesort allowing the latter to be implemented in place. Our new variant applies the median-of-medians algorithm for selecting pivots in order to circumvent the quadratic worst case. Indeed, we show that it uses at most $n \log n + 1.6n$ comparisons for $n$ large enough. We experimentally confirm the theoretical estimates and show that the new algorithm outperforms Heapsort by far and is only around 10% slower than Introsort (std::sort implementation of stdlibc++), which has a rather poor guarantee for the worst case. We also simulate the worst case, which is only around 10% slower than the average case. In particular, the new algorithm is a natural candidate to replace Heapsort as a worst-case stopper in Introsort.

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

↑