On Smoothed Analysis of Quicksort and Hoare’s Find

  • Mahmoud Fouz
  • Manfred Kufleitner
  • Bodo Manthey
  • Nima Zeini Jahromi
Part of the Lecture Notes in Computer Science book series (LNCS, volume 5609)

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 – 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 Θ(n2), the average-case number is Θ(n). We analyze what happens between these two extremes by providing a smoothed analysis of the algorithm in terms of two different perturbation models: additive noise and partial permutations.

In the first model, an adversary specifies a sequence of n numbers of [0,1], and then each number is perturbed by adding a random number drawn 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 element that we would like to find. Furthermore, we show that Hoare’s find needs fewer comparisons for finding the median.

In the second model, each element is marked with probability 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 in \(\Omega\big((1\,{-}\,p) \frac np \log n\big)\), which is again tight.

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: the lower bounds for the classic rule carry over to median-of-three.

Preview

Unable to display preview. Download preview PDF.

Unable to display preview. Download preview PDF.

References

  1. 1.
    Banderier, C., Beier, R., Mehlhorn, K.: Smoothed Analysis of Three Combinatorial Problems. In: Rovan, B., Vojtáš, P. (eds.) MFCS 2003. LNCS, vol. 2747, pp. 198–207. Springer, Heidelberg (2003)CrossRefGoogle Scholar
  2. 2.
    Cederman, D., Tsigas, P.: A Practical Quicksort Algorithm for Graphics Processors. In: Halperin, D., Mehlhorn, K. (eds.) Esa 2008. LNCS, vol. 5193, pp. 246–258. Springer, Heidelberg (2008)CrossRefGoogle Scholar
  3. 3.
    Damerow, V.: Meyer auf der Heide, F., Räcke, H., Scheideler, C., Sohler, C.: Smoothed Motion Complexity. In: Di Battista, G., Zwick, U. (eds.) ESA 2003. LNCS, vol. 2832, pp. 161–171. Springer, Heidelberg (2003)CrossRefGoogle Scholar
  4. 4.
    Erkiö, H.: The worst case permutation for median-of-three quicksort. The Computer Journal 27(3), 276–277 (1984)CrossRefMATHGoogle Scholar
  5. 5.
    Fouz, M., Kufleitner, M., Manthey, B., Zeini Jahromi, N.: On smoothed analysis of quicksort and Hoare’s find. Computing Research Repository, arXiv:0904.3898 [cs.DS] (2009)Google Scholar
  6. 6.
    Hoare, C.A.R.: Algorithm 64: Quicksort. Comm. ACM 4(7), 322 (1961)CrossRefGoogle Scholar
  7. 7.
    Hoare, C.A.R.: Algorithm 65: Find. Comm. ACM 4(7), 321–322 (1961)CrossRefGoogle Scholar
  8. 8.
    Kirschenhofer, P., Prodinger, H.: Comparisons in Hoare’s find algorithm. Combin. Probab. Comput. 7(1), 111–120 (1998)MathSciNetCrossRefMATHGoogle Scholar
  9. 9.
    Kirschenhofer, P., Prodinger, H., Martinez, C.: Analysis of Hoare’s find algorithm with median-of-three partition. Random Structures Algorithms 10(1-2), 143–156 (1997)MathSciNetCrossRefMATHGoogle Scholar
  10. 10.
    Knuth, D.E.: Sorting and Searching, 2nd edn. The Art of Computer Programming, vol. 3. Addison-Wesley, Reading (1998)Google Scholar
  11. 11.
    Manthey, B., Reischuk, R.: Smoothed analysis of binary search trees. Theoret. Comput. Sci. 378(3), 292–315 (2007)MathSciNetCrossRefMATHGoogle Scholar
  12. 12.
    Manthey, B., Tantau, T.: Smoothed analysis of binary search trees and quicksort under additive noise. In: Ochmański, E., Tyszkiewicz, J. (eds.) MFCS 2008. LNCS, vol. 5162, pp. 467–478. Springer, Heidelberg (2008)CrossRefGoogle Scholar
  13. 13.
    Schmidt, D.C.: qsort.c. C standard library stdlib within glibc 2.7 (2007), http://ftp.gnu.org/gnu/glibc/
  14. 14.
    Sedgewick, R.: The analysis of quicksort programs. Acta Inform. 7(4), 327–355 (1977)MathSciNetCrossRefMATHGoogle Scholar
  15. 15.
    Sedgewick, R.: Implementing quicksort programs. Comm. ACM 21(10), 847–857 (1978)CrossRefMATHGoogle Scholar
  16. 16.
    Singleton, R.C.: Algorithm 347: An efficient algorithm for sorting with minimal storage. Comm. ACM 12(3), 185–186 (1969)CrossRefGoogle Scholar
  17. 17.
    Spielman, D.A., Teng, S.-H.: Smoothed analysis of algorithms: Why the simplex algorithm usually takes polynomial time. J. ACM 51(3), 385–463 (2004)MathSciNetCrossRefMATHGoogle Scholar
  18. 18.
    Spielman, D.A., Teng, S.-H.: Smoothed analysis of algorithms and heuristics: Progress and open questions. In: Foundations of Computational Mathematics, Santander 2005, pp. 274–342. Cambridge University Press, Cambridge (2006)CrossRefGoogle Scholar

Copyright information

© Springer-Verlag Berlin Heidelberg 2009

Authors and Affiliations

  • Mahmoud Fouz
    • 1
  • Manfred Kufleitner
    • 2
  • Bodo Manthey
    • 1
  • Nima Zeini Jahromi
    • 1
  1. 1.Department of Computer Science, Postfach 151150Saarland UniversitySaarbrückenGermany
  2. 2.Universität Stuttgart, FMIStuttgartGermany

Personalised recommendations