Skip to main content
QUICK REVIEW

[论文解读] Optimal Partitioning for Dual-Pivot Quicksort

Martin Aumüller, Martin Dietzfelbinger|arXiv (Cornell University)|Mar 21, 2013
Algorithms and Data Compression参考文献 15被引用 7
一句话总结

本文提出了一种统一的双枢纽快速排序算法模型,并确定了一种最优分割策略,将平均关键比较次数最小化至 $1.8n\ln n + O(n)$,优于 Yaroslavskiy 算法所使用的 $1.9n\ln n + O(n)$ 次比较。该方法基于枢纽选择与元素分布,系统分析了各种分割方案,推导出双枢纽排序中比较效率的理论下界。

ABSTRACT

Dual-pivot quicksort refers to variants of classical quicksort where in the partitioning step two pivots are used to split the input into three segments. This can be done in different ways, giving rise to different algorithms. Recently, a dual-pivot algorithm proposed by Yaroslavskiy received much attention, because a variant of it replaced the well-engineered quicksort algorithm in Sun's Java 7 runtime library. Nebel and Wild (ESA 2012) analyzed this algorithm and showed that on average it uses 1.9n ln n + O(n) comparisons to sort an input of size n, beating standard quicksort, which uses 2n ln n + O(n) comparisons. We introduce a model that captures all dual-pivot algorithms, give a unified analysis, and identify new dual-pivot algorithms that minimize the average number of key comparisons among all possible algorithms up to a linear term. This minimum is 1.8n ln n + O(n). For the case that the pivots are chosen from a small sample, we include a comparison of dual-pivot quicksort and classical quicksort. Specifically, we show that dual-pivot quicksort benefits from a skewed choice of pivots. We experimentally evaluate our algorithms and compare them to Yaroslavskiy's algorithm and the recently described three-pivot quicksort algorithm of Kushagra et al. (ALENEX 2014).

研究动机与目标

  • 将双枢纽快速排序算法的设计空间形式化并统一,以实现对各种分割策略的系统性比较。
  • 识别出在所有可能的双枢纽算法中,能将平均关键比较次数最小化的最优分割方法。
  • 为双枢纽快速排序建立理论下界,即比较次数为 $1.8n\ln n + O(n)$,优于已知算法(如 Yaroslavskiy 的算法)。
  • 通过实验评估所提出的最优算法在实际性能上与现有变体(包括 Yaroslavskiy 算法和三枢纽快速排序)的对比表现,使用真实硬件环境进行测试。
  • 探究标准成本度量(如比较次数、交换次数、缓存未命中次数或指令计数)是否能完全解释双枢纽快速排序变体之间的实际运行时间差异。

提出的方法

  • 作者开发了一个通用模型,通过基于枢纽选择与元素排序方式的参数化,捕捉所有双枢纽快速排序算法。
  • 他们推导出比较次数期望值的闭式表达式,该表达式基于两个枢纽的相对顺序以及输入元素的分布。
  • 利用解析组合学与生成函数方法,计算每种分割策略的期望比较成本,并在设计空间中进行最小化。
  • 通过求解一个变分问题,推导出最优策略,以平衡分割过程中形成的三个子数组的大小。
  • 作者在现代硬件上使用 Java 8 实现并实验评估了最优算法,同时对比了 Yaroslavskiy 算法、经典快速排序以及 Kushagra 等人的三枢纽算法。
  • 他们在多个成本度量下测量性能:比较次数、交换次数、缓存未命中次数(L1 和 L2)、指令计数以及实际运行时间。

实验结果

研究问题

  • RQ1任何双枢纽快速排序算法所能实现的最小平均比较次数是多少?
  • RQ2哪种分割策略能实现这一最小比较次数?它与 Yaroslavskiy 等现有算法有何不同?
  • RQ3标准成本度量(如比较次数、交换次数或缓存未命中次数)在多大程度上能预测双枢纽快速排序变体的实际运行时间差异?
  • RQ4在实际应用中,该最优算法与 Yaroslavskiy 算法及三枢纽快速排序相比,其真实世界性能表现如何?
  • RQ5理论上可达到的比较次数下界 $1.8n\ln n + O(n)$ 是否能在稳定且高效的实现中实际达成?

主要发现

  • 最优双枢纽快速排序算法的平均比较次数为 $1.8n\ln n + O(n)$,低于 Yaroslavskiy 算法的 $1.9n\ln n + O(n)$。
  • 最优策略源于一个统一模型,该模型基于枢纽顺序与元素分布对分割过程进行参数化。
  • 实验结果表明,该最优算法在 Java 8 中比三枢纽算法慢约 37%,而后者在基准测试中速度最快。
  • 尽管理论比较次数更高,Yaroslavskiy 算法在实际应用中表现几乎与最优算法相当。
  • 仅靠比较次数或交换次数无法完全解释观察到的运行时间差异;缓存未命中次数和指令计数也起作用,但没有任何单一指标能完全预测性能表现。
  • 本研究证实,比较次数中的低阶项为 $O(n)$,而非以往假设的 $o(n\ln n)$。

更好的研究,从现在开始

从阅读论文到最终审阅,大幅缩短您的研究时间。

无需绑定信用卡

本解读由 AI 生成,并经人工编辑审核。