Optimal sampling strategies in quicksort

4Citations
Citations of this article
15Readers
Mendeley users who have this article in their library.
Get full text

Abstract

It is well known that the performance of quicksort can be substantially improved by selecting the median of a sample of three elements as the pivot of each partitioning stage. This variant is easily generalized to samples of size s = 2k + 1. For large samples the partitions are better as the median of the sample makes a more accurate estimate of the median of the array to be sorted, but the amount of additional comparisons and exchanges to find the median of the sample also increases. We show that the optimal sample size to minimize the average total cost of quicksort (which includes both comparisons and exchanges) is s = a · √n + o(√n). We also give a closed expression for the constant factor a, which depends on the median-finding algorithm and the costs of elementary comparisons and exchanges. The result above holds in most situations, unless the cost of an exchange exceeds by far the cost of a comparison. In that particular case, it is better to select not the median of the samples, but the (p+1)th element. The value of p can be precisely determined as a function of the ratio between the cost of an exchange and the cost of a comparison.

Cite

CITATION STYLE

APA

Martinez, C., & Roura, S. (1998). Optimal sampling strategies in quicksort. In Lecture Notes in Computer Science (including subseries Lecture Notes in Artificial Intelligence and Lecture Notes in Bioinformatics) (Vol. 1443 LNCS, pp. 327–338). Springer Verlag. https://doi.org/10.1007/bfb0055064

Register to see more suggestions

Mendeley helps you to discover research relevant for your work.

Already have an account?

Save time finding and organizing research with Mendeley

Sign up for free