Abstract
We verify the correctness of a recursive version of Tony Hoareās \(\texttt {quicksort}\) algorithm using the Hoare-logic based verification tool Dafny. We then develop a non-standard, iterative version which is based on a stack of pivot-locations rather than the standard stack of ranges. We outline an incomplete Dafny proof for the latter.
Access this chapter
Tax calculation will be finalised at checkout
Purchases are for personal use only
Notes
- 1.
The sorting task can actually be defined for an array of any type that has a less-then-or-equal relation \(\le \).
- 2.
The careful reader will notice that the array look-up is not always defined. Nevertheless, the assertion is well-formed, because it stands for \(\forall i \in [\texttt {top}..|\texttt {a}|).\forall j \in [0.. \texttt {pivs[}i\texttt {]}).\forall k \in [\texttt {pivs[}i\texttt {]+1..|a|}).\, \texttt {a[}j\texttt {]} < \texttt {a[pivs[}i\texttt {]]} \le \texttt {a[}k\texttt {]}\).
References
Apt, K., Boer, F., Olderog, E.: Verification of Sequential and Concurrent Programs. Springer, Dordrecht (2009)
Beckert, B., HƤhnle, R., Schmitt, P.H. (eds.): Verification of Object-Oriented Software. The KeY Approach. LNCS (LNAI), vol. 4334. Springer, Heidelberg (2007)
Certezeanu, R., Drossopoulou, S., Egelund-Muller, B., Sivarajan, S., Wheelhouse, M., Leino, K.: Dafny Code for Variations on Quicksort. http://www.doc.ic.ac.uk/~mjw03/research/quicksort.html
Certezeanu, R., Drossopoulou, S., Egelund-Muller, B., Sivarajan, S., Wheelhouse, M., Leino, K.:Apollo: An interactive Program and Proof development tool for Java and Haskell, based on Dafny (to appear)
Foley, M., Hoare, C.: Proof of a recursive program: quicksort. Comput. J. 14, 391ā395 (1971)
de Gouw, S., Rot, J., de Boer, F.S., Bubel, R., HƤhnle, R.: OpenJDKās Java.utils.Collection.sort() is broken: the good, the bad and the worst case. In: Kroening, D., PÄsÄreanu, C.S. (eds.) CAV 2015. LNCS, vol. 9206, pp. 273ā289. Springer, Heidelberg (2015)
Hoare, C.: Algorithm 64: quicksort. Commun. ACM 4, 321 (1961)
Hoare, C.: An axiomatic basis for computer programming. Commun. ACM 12, 576ā580 (1969)
Lamort, L.:Thinking Above the Code. https://www.youtube.com/watch?v=-4Yp3j_jk8Q
Leino, K.R.M.: Dafny: an automatic program verifier for functional correctness. In: Clarke, E.M., Voronkov, A. (eds.) LPAR-16 2010. LNCS, vol. 6355, pp. 348ā370. Springer, Heidelberg (2010)
Leino, K.: Dafny: An Automatic Program Verifier for Functional Correctness. http://dafny.codeplex.com
Manna, Z.: Mathematical Theory of Computation. McGraw-Hill, New York (1974)
Oracle Documentation: Arrays (Java Platform SE 7). http://docs.oracle.com/javase/7/docs/api/java/util/Arrays.html
The Verification Corner - Microsoft Research. http://research.microsoft.com/en-us/projects/verificationcorner
Wikipedia: Quicksort. https://en.wikipedia.org/wiki/Quicksort
YouTube: Quick-sort with Hungarian (Kkllmenti legnyes) folk dance. https://www.youtube.com/watch?v=ywWBy6J5gz8
Acknowledgments
We thank Krysia Broda for showing us the recursive, non-standard version of quicksort, and the anonymous reviewers of this volume for valuable suggestions and pointers.
Razvan Certezeanu, Benjamin Egelund-Muller and Sinduran Sivarajan thank the Department of Computing at Imperial College for funding their Undergraduate Research Opportunities Programme (UROP) Placements, undertaken under Mark Wheelhouseās supervision, which they spent working on Apollo, and this paper.
Sophia Drossopoulou thanks Microsoft Research and Judith Bishop for a research gift and her very warm hospitality at Microsoft Research, and the EU project Upscale, FP7-612985, for supporting part of this work, and for the opportunity to collaborate with Frank S. de Boer, the recipient of this Festschrift.
Author information
Authors and Affiliations
Corresponding author
Editor information
Editors and Affiliations
Rights and permissions
Copyright information
Ā© 2016 Springer International Publishing Switzerland
About this chapter
Cite this chapter
Certezeanu, R., Drossopoulou, S., Egelund-Muller, B., Leino, K.R.M., Sivarajan, S., Wheelhouse, M. (2016). Quicksort Revisited. In: ĆbrahĆ”m, E., Bonsangue, M., Johnsen, E. (eds) Theory and Practice of Formal Methods. Lecture Notes in Computer Science(), vol 9660. Springer, Cham. https://doi.org/10.1007/978-3-319-30734-3_27
Download citation
DOI: https://doi.org/10.1007/978-3-319-30734-3_27
Published:
Publisher Name: Springer, Cham
Print ISBN: 978-3-319-30733-6
Online ISBN: 978-3-319-30734-3
eBook Packages: Computer ScienceComputer Science (R0)