Skip to main content
QUICK REVIEW

[Paper Review] Partitioning schemes for quicksort and quickselect

Krzysztof C. Kiwiel|ArXiv.org|Dec 23, 2003
Algorithms and Data CompressionComputer Science19 references5 citations
TL;DR

This paper introduces optimized partitioning schemes for quicksort and quickselect, focusing on ternary partitioning to efficiently isolate all elements equal to the pivot. It proposes modifications to classic schemes that reduce swaps while maintaining low comparison counts, with computational results showing ternary schemes incur only mild overhead and enable quickselect to identify all equal keys at minimal extra cost.

ABSTRACT

We introduce several modifications of the partitioning schemes used in Hoare's quicksort and quickselect algorithms, including ternary schemes which identify keys less or greater than the pivot. We give estimates for the numbers of swaps made by each scheme. Our computational experiments indicate that ternary schemes allow quickselect to identify all keys equal to the selected key at little additional cost.

Motivation & Objective

  • To improve partitioning schemes in quicksort and quickselect by reducing the number of swaps, especially in the presence of equal keys.
  • To develop efficient ternary partitioning schemes that separate elements less than, equal to, and greater than the pivot, enabling quickselect to identify all elements equal to the selected key.
  • To analyze and compare the average-case swap counts of various partitioning schemes under different pivot selection strategies.
  • To evaluate the practical performance of modified schemes, particularly the impact of pointer tests and vacuous swaps in inner loops on modern architectures.

Proposed method

  • Proposes a safeguarded binary partitioning scheme that eliminates the need for artificial sentinels by exchanging the first and last elements when necessary.
  • Introduces a modified Sedgewick scheme that efficiently handles equal keys with minimal comparisons and swaps, achieving optimal performance for distinct keys.
  • Designs a ternary partitioning scheme that makes exactly $ n-1 $ comparisons and minimizes swaps, with inner loops avoiding pointer tests for speed.
  • Develops hybrid two-phase partitioning schemes that eliminate vacuous swaps in the first phase and remove pointer tests in the second, improving efficiency on inputs with many equal keys.
  • Employs median-of-$ 2t+1 $ and ninther pivot selection to improve average-case performance, particularly for large inputs.
  • Conducts extensive computational experiments across diverse input types (random, sorted, organpipe, etc.) to measure comparisons, swaps, and execution time.

Experimental results

Research questions

  • RQ1How do different partitioning schemes compare in terms of average number of swaps when elements are distinct and in random order?
  • RQ2What is the performance impact of including pointer tests in the key comparison loops, especially on modern architectures?
  • RQ3Can ternary partitioning schemes be made efficient enough to identify all elements equal to the pivot with only a mild performance penalty compared to binary schemes?
  • RQ4How do the proposed schemes perform on inputs with many equal keys, particularly in comparison to Lomuto’s scheme, which degrades to $ O(n^2) $ time?
  • RQ5To what extent do hybrid two-phase schemes reduce vacuous swaps and improve performance on inputs with repeated keys?

Key findings

  • The proposed ternary partitioning schemes make only a mild performance penalty—around 10% slower than binary schemes—on inputs with distinct keys, making them a fair trade-off for identifying all equal keys.
  • Lomuto’s scheme performs poorly on inputs with many equal keys, with running time potentially degrading to $ O(n^2) $, as each partition removes only two elements when all are equal to the pivot.
  • The hybrid two-phase schemes eliminate vacuous swaps and reduce pointer tests, making them significantly faster than standard ternary schemes like the Bentley-McIlroy version on inputs with repeated keys.
  • On average, the best binary schemes (e.g., scheme A) make at most $ n/4 $ swaps, while Lomuto’s scheme can make up to $ n-1 $ swaps, making it inefficient for large inputs with duplicates.
  • For pivot selection via median-of-three, the new schemes make asymptotically $ n/5 $ swaps, compared to $ (n-1)/2 $ for Lomuto’s scheme, showing a substantial improvement.
  • Computational results show that including pointer tests in loops does not significantly slow down execution on modern machines, contradicting traditional advice based on older cost models.

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.