Skip to main content
QUICK REVIEW

[Paper Review] Why Is Dual-Pivot Quicksort Fast?

Sebastian Wild|arXiv (Cornell University)|Nov 3, 2015
Algorithms and Data CompressionComputer Science15 references4 citations
TL;DR

This paper explains why Yaroslavskiy's dual-pivot Quicksort outperforms classic Quicksort in practice by introducing a new cost model based on 'scanned elements'—the total number of array accesses during partitioning. The model shows dual-pivot Quicksort reduces data movement by 12% compared to classic Quicksort, aligning with observed 10% speedups in Java 7, due to more efficient memory access patterns in modern systems with growing CPU-memory performance gaps.

ABSTRACT

I discuss the new dual-pivot Quicksort that is nowadays used to sort arrays of primitive types in Java. I sketch theoretical analyses of this algorithm that offer a possible, and in my opinion plausible, explanation why (a) dual-pivot Quicksort is faster than the previously used (classic) Quicksort and (b) why this improvement was not already found much earlier.

Motivation & Objective

  • To explain the practical superiority of Yaroslavskiy's dual-pivot Quicksort over classic Quicksort, despite decades of prior research.
  • To address why such a significant optimization was not discovered earlier, despite extensive study of Quicksort.
  • To propose a new algorithmic cost model that better reflects real-world performance by focusing on memory access patterns.
  • To demonstrate that the performance gain stems from reduced data movement, not just fewer comparisons.

Proposed method

  • Introduces a new cost model based on counting 'scanned elements'—each array access via an index variable is counted as one scan, regardless of read or write.
  • Analyzes classic and dual-pivot Quicksort under this model, showing that dual-pivot scans 4/3 of the array elements on average per partitioning step, versus 1 for classic Quicksort.
  • Derives asymptotic bounds on scanned elements: 1.5697n ln n for classic Quicksort and 1.4035n ln n for dual-pivot Quicksort.
  • Uses the scanned elements metric to explain the 12% reduction in data movement, which correlates with the 10% speedup observed in Java 7.
  • Revisits classical Quicksort analysis under the new model, showing that prior theoretical models failed to capture memory wall effects.
  • Applies the model to Yaroslavskiy’s partitioning algorithm, accounting for multiple index traversals (k, g, ℓ) and their overlapping ranges.

Experimental results

Research questions

  • RQ1Why does dual-pivot Quicksort perform significantly better in practice than classic Quicksort, despite both having similar comparison counts?
  • RQ2Why was this improvement not discovered earlier, given the extensive research on Quicksort over 50 years?
  • RQ3To what extent do memory access patterns, rather than comparison counts, determine the real-world performance of sorting algorithms?
  • RQ4Can a new cost model based on scanned elements better predict performance on modern hardware with memory wall effects?

Key findings

  • Dual-pivot Quicksort reduces the number of scanned elements from 1.5697n ln n (classic Quicksort) to 1.4035n ln n, a 12% improvement.
  • The reduction in scanned elements correlates with the 10% speedup observed in Java 7’s implementation compared to Java 6’s classic Quicksort.
  • The performance gain is primarily due to reduced data movement, not fewer comparisons, as the new model emphasizes memory access over comparison count.
  • The classical comparison-based model fails to explain the performance difference because it does not account for memory wall effects in modern processors.
  • The scanned elements model provides a more accurate predictor of real-world performance for algorithms relying on sequential array scans.
  • The model explains why dual-pivot Quicksort was overlooked earlier: it was not cost-effective in systems where memory bandwidth was not a bottleneck.

Read this paper

Open the full text in the Nubint reader and ask about any passage as you read.

Read this paper on Nubint

This review was generated by AI from the original paper. Please check the paper before citing it.