Abstract
We provide a smoothed analysis of Hoare’s find algorithm, and we revisit the smoothed analysis of quicksort. Hoare’s find algorithm—often called quickselect or one-sided quicksort—is an easy-to-implement algorithm for finding the k-th smallest element of a sequence. While the worst-case number of comparisons that Hoare’s find needs is Θ(n 2), the average-case number is Θ(n). We analyze what happens between these two extremes by providing a smoothed analysis.
In the first perturbation model, an adversary specifies a sequence of n numbers of [0,1], and then, to each number of the sequence, we add a random number drawn independently from the interval [0,d]. We prove that Hoare’s find needs \(\Theta(\frac{n}{d+1} \sqrt{n/d} + n)\) comparisons in expectation if the adversary may also specify the target element (even after seeing the perturbed sequence) and slightly fewer comparisons for finding the median.
In the second perturbation model, each element is marked with a probability of p, and then a random permutation is applied to the marked elements. We prove that the expected number of comparisons to find the median is \(\Omega((1-p) \frac{n}{p} \log n)\).
Finally, we provide lower bounds for the smoothed number of comparisons of quicksort and Hoare’s find for the median-of-three pivot rule, which usually yields faster algorithms than always selecting the first element: The pivot is the median of the first, middle, and last element of the sequence. We show that median-of-three does not yield a significant improvement over the classic rule.
Article PDF
Similar content being viewed by others
Avoid common mistakes on your manuscript.
References
Aho, A.V., Hopcroft, J.E., Ullman, J.D.: The Design and Analysis of Computer Algorithms. Addison-Wesley, Reading (1974)
Arthur, D., Vassilvitskii, S.: Worst-case and smoothed analysis of the ICP algorithm, with an application to the k-means method. SIAM Journal on Computing 39(2), 766–782 (2009)
Arthur, D., Manthey, B., Röglin, H.: k-means has polynomial smoothed complexity. In: Proceedings of the 50th Annual IEEE Symp. on Foundations of Computer Science (FOCS), pp. 405–414. IEEE Computer Society, New York (2009)
Banderier, C., Beier, R., Mehlhorn, K.: Smoothed analysis of three combinatorial problems. In: Rovan, B., Vojtás, P. (eds.) Proceedings of the 28th International Symposium on Mathematical Foundations of Computer Science (MFCS). Lecture Notes in Computer Science, vol. 2747, pp. 198–207. Springer, Berlin (2003)
Becchetti, L., Leonardi, S., Marchetti-Spaccamela, A., Schäfer, G., Vredeveld, T.: Average case and smoothed competitive analysis of the multilevel feedback algorithm. Mathematics of Operations Research 31(1), 85–108 (2006)
Beier, R., Vöcking, B.: Random knapsack in expected polynomial time. Journal of Computer and System Sciences 69(3), 306–329 (2004)
Beier, R., Vöcking, B.: Typical properties of winners and losers in discrete optimization. SIAM Journal on Computing 35(4), 855–881 (2006)
Beier, R., Röglin, H., Vöcking, B.: The smoothed number of Pareto optimal solutions in bicriteria integer optimization. In: Fischetti, M., Williamson, D.P. (eds.) Proceedings of the 12th International Conference on Integer Programming and Combinatorial Optimization (IPCO). Lecture Notes in Computer Science, vol. 4513, pp. 53–67. Springer, Berlin (2007)
Cederman, D., Tsigas, P.: GPU-quicksort: a practical quicksort algorithm for graphics processors. ACM J. Exp. Algorithms 14 (2009)
Damerow, V., Manthey, B., auf der Heide, F.M., Räcke, H., Scheideler, C., Sohler, C., Tantau, T.: Smoothed analysis of left-to-right maxima with applications. ACM Trans. Algorithms (to appear)
Dubhashi, D., Panconesi, A.: Concentration of Measure for the Analysis of Randomized Algorithms. Cambridge University Press, Cambridge (2009)
Englert, M., Röglin, H., Vöcking, B.: Worst case and probabilistic analysis of the 2-Opt algorithm for the TSP. In: Proceedings of the 18th Annual ACM-SIAM Symposium on Discrete Algorithms (SODA), pp. 1295–1304. SIAM, Philadelphia (2007)
Erkiö, H.: The worst case permutation for median-of-three quicksort. The Computer Journal 27(3), 276–277 (1984)
Fouz, M., Kufleitner, M., Manthey, B., Zeini Jahromi, N.: Smoothed analysis of quicksort and Hoare’s find. In: Ngo, H.Q. (ed.) Proceedings of the 15th Annual International Computing and Combinatorics Conference (COCOON). Lecture Notes in Computer Science, vol. 5609, pp. 158–167. Springer, Berlin (2009)
Hoare, C.A.R.: Algorithm 64: Quicksort. Communications of the ACM 4(7), 322 (1961)
Hoare, C.A.R.: Algorithm 65: Find. Communications of the ACM 4(7), 321–322 (1961)
Kirschenhofer, P., Prodinger, H.: Comparisons in Hoare’s find algorithm. Combinatorics, Probability and Computing 7(1), 111–120 (1998)
Kirschenhofer, P., Prodinger, H., Martinez, C.: Analysis of Hoare’s find algorithm with median-of-three partition. Random Structures and Algorithms 10(1–2), 143–156 (1997)
Knuth, D.E.: Sorting and Searching, 2nd edn. The Art of Computer Programming, vol. 3. Addison-Wesley, Reading (1998)
Manthey, B., Reischuk, R.: Smoothed analysis of binary search trees. Theoretical Computer Science 378(3), 292–315 (2007)
Manthey, B., Röglin, H.: Improved smoothed analysis of k-means clustering. In: Proceedings of the 20th Annual ACM-SIAM Symposium on Discrete Algorithms (SODA), pp. 461–470. SIAM, Philadelphia (2009)
Manthey, B., Röglin, H.: Worst-case and smoothed analysis of k-means clustering with Bregman divergences. In: Dong, Y., Du, D.-Z., Ibarra, O. (eds.) Proceedings of the 20th Annual International Symposium on Algorithms and Computation (ISAAC). Lecture Notes in Computer Science, vol. 5878, pp. 1024–1033. Springer, Berlin (2009)
Mitzenmacher, M., Upfal, E.: Probability and Computing: Randomized Algorithms and Probabilistic Analysis. Cambridge University Press, Cambridge (2005)
Neininger, R.: Limit laws for random recursive structures and algorithms. Ph.D. thesis, Universität Freiburg (1999)
Röglin, H., Vöcking, B.: Smoothed analysis of integer programming. Mathematical Programming 110(1), 21–56 (2007)
Schmidt, D.C.: qsort.c. C standard library stdlib within glibc 2.7, available at http://ftp.gnu.org/gnu/glibc/ (2007)
Sedgewick, R.: The analysis of quicksort programs. Acta Informatica 7(4), 327–355 (1977)
Sedgewick, R.: Implementing quicksort programs. Communications of the ACM 21(10), 847–857 (1978)
Singleton, R.C.: Algorithm 347: an efficient algorithm for sorting with minimal storage. Communications of the ACM 12(3), 185–186 (1969)
Spielman, D.A., Teng, S.-H.: Smoothed analysis of algorithms: why the simplex algorithm usually takes polynomial time. Journal of the ACM 51(3), 385–463 (2004)
Spielman, D.A., Teng, S.-H.: Smoothed analysis: an attempt to explain the behavior of algorithms in practice. Communications of the ACM 52(10), 76–84 (2009)
Author information
Authors and Affiliations
Corresponding author
Additional information
An extended abstract of this paper has appeared in the Proceedings of the 15th International Computing and Combinatorics Conference (COCOON 2009) [14].
Rights and permissions
Open Access This is an open access article distributed under the terms of the Creative Commons Attribution Noncommercial License (https://creativecommons.org/licenses/by-nc/2.0), which permits any noncommercial use, distribution, and reproduction in any medium, provided the original author(s) and source are credited.
About this article
Cite this article
Fouz, M., Kufleitner, M., Manthey, B. et al. On Smoothed Analysis of Quicksort and Hoare’s Find. Algorithmica 62, 879–905 (2012). https://doi.org/10.1007/s00453-011-9490-9
Received:
Accepted:
Published:
Issue Date:
DOI: https://doi.org/10.1007/s00453-011-9490-9