Algorithmica

, Volume 62, Issue 3–4, pp 879–905

# On Smoothed Analysis of Quicksort and Hoare’s Find

• Mahmoud Fouz
• Manfred Kufleitner
• Bodo Manthey
• Nima Zeini Jahromi
Open Access
Article

## 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.

## Keywords

Smoothed analysis Hoare’s find Quickselect Quicksort Median-of-three

## References

1. 1.
Aho, A.V., Hopcroft, J.E., Ullman, J.D.: The Design and Analysis of Computer Algorithms. Addison-Wesley, Reading (1974)
2. 2.
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)
3. 3.
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)
4. 4.
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) Google Scholar
5. 5.
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)
6. 6.
Beier, R., Vöcking, B.: Random knapsack in expected polynomial time. Journal of Computer and System Sciences 69(3), 306–329 (2004)
7. 7.
Beier, R., Vöcking, B.: Typical properties of winners and losers in discrete optimization. SIAM Journal on Computing 35(4), 855–881 (2006)
8. 8.
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) Google Scholar
9. 9.
Cederman, D., Tsigas, P.: GPU-quicksort: a practical quicksort algorithm for graphics processors. ACM J. Exp. Algorithms 14 (2009) Google Scholar
10. 10.
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) Google Scholar
11. 11.
Dubhashi, D., Panconesi, A.: Concentration of Measure for the Analysis of Randomized Algorithms. Cambridge University Press, Cambridge (2009)
12. 12.
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) Google Scholar
13. 13.
Erkiö, H.: The worst case permutation for median-of-three quicksort. The Computer Journal 27(3), 276–277 (1984)
14. 14.
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) Google Scholar
15. 15.
Hoare, C.A.R.: Algorithm 64: Quicksort. Communications of the ACM 4(7), 322 (1961)
16. 16.
Hoare, C.A.R.: Algorithm 65: Find. Communications of the ACM 4(7), 321–322 (1961)
17. 17.
Kirschenhofer, P., Prodinger, H.: Comparisons in Hoare’s find algorithm. Combinatorics, Probability and Computing 7(1), 111–120 (1998)
18. 18.
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)
19. 19.
Knuth, D.E.: Sorting and Searching, 2nd edn. The Art of Computer Programming, vol. 3. Addison-Wesley, Reading (1998) Google Scholar
20. 20.
Manthey, B., Reischuk, R.: Smoothed analysis of binary search trees. Theoretical Computer Science 378(3), 292–315 (2007)
21. 21.
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) Google Scholar
22. 22.
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) Google Scholar
23. 23.
Mitzenmacher, M., Upfal, E.: Probability and Computing: Randomized Algorithms and Probabilistic Analysis. Cambridge University Press, Cambridge (2005)
24. 24.
Neininger, R.: Limit laws for random recursive structures and algorithms. Ph.D. thesis, Universität Freiburg (1999) Google Scholar
25. 25.
Röglin, H., Vöcking, B.: Smoothed analysis of integer programming. Mathematical Programming 110(1), 21–56 (2007)
26. 26.
Schmidt, D.C.: qsort.c. C standard library stdlib within glibc 2.7, available at http://ftp.gnu.org/gnu/glibc/ (2007)
27. 27.
Sedgewick, R.: The analysis of quicksort programs. Acta Informatica 7(4), 327–355 (1977)
28. 28.
Sedgewick, R.: Implementing quicksort programs. Communications of the ACM 21(10), 847–857 (1978)
29. 29.
Singleton, R.C.: Algorithm 347: an efficient algorithm for sorting with minimal storage. Communications of the ACM 12(3), 185–186 (1969)
30. 30.
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)
31. 31.
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)

## Authors and Affiliations

• Mahmoud Fouz
• 1
• Manfred Kufleitner
• 2
• Bodo Manthey
• 3
• Nima Zeini Jahromi
• 1
1. 1.Department of Computer ScienceSaarland UniversitySaarbrückenGermany
2. 2.FMIUniversität StuttgartStuttgartGermany
3. 3.Department of Applied MathematicsUniversity of TwenteAE EnschedeThe Netherlands