Abstract
This paper is a practical study of how to implement the Quicksort sorting algorithm and its best variants on real computers, including how to apply various code optimization techniques. A detailed implementation combining the most effective improvements to Quicksort is given, along with a discussion of how to implement it in assembly language. Analytic results describing the performance of the programs are summarized. A variety of special situations are considered from a practical standpoint to illustrate Quicksort's wide applicability as an internal sorting method which requires negligible extra storage.
- 1 Boothroyd, J. Sort of a section of the elements of an array by determining the rank of each element: Algorithm 25; and Ordering the subscripts of an array section according to the magnitudes of the elements: Algorithm 26. Comptr. J. 10 (Nov. 1967), 308-310. (See notes by R.S. Scowen in Comptr. J. 12 (Nov. 1969), 408-409, and by A.D. Woodall in Comptr. J. 13 (Aug. 1970.)Google Scholar
- 2 Brawn, B.S., Gustavson, F.G., and Mankin, E. Sorting in a paging environment. Comm. ACM 13, 8 (Aug. 1970), 483-494. Google ScholarDigital Library
- 3 Cocke, J., and Schwartz, J.T. Programming languages and their compilers. Preliminary Notes. Courant Inst. of Math. Sciences, New York U., New York, 1970. Google ScholarDigital Library
- 4 Frazer, W.D., and McKellar, A.C. Samplesort: A sampling approach to minimal storage tree sorting. J. ACM 17, 3 (July 1970), 496-507. Google ScholarDigital Library
- 5 Hoare, C.A.R. Partition: Algorithm 63; Quicksort: Algorithm 64; and Find: Algorithm 65. Comm. ACM 4, 7 (July 1961), 321-322. (See also certification by J.S. Hillmore in Comm. ACM 5, 8 (Aug. 1962), 439, and B. Randell and L.J. Russell in Comm. A CM 6, 8 (Aug. 1963), 446.) Google ScholarDigital Library
- 6 Hoare, C.A.R. Quicksort. Computer J. 5, 4 (April 1962), 10-15.Google ScholarCross Ref
- 7 Knuth, D.E. The Art of Computer Programming, VoL 1: Fundamental Algorithms. Addison-Wesley, Mass., 1968. Google ScholarDigital Library
- 8 Knuth, D.E. The Art of Computer Programming, Vol. 2: Seminumerical Algorithms. Addison-Wesley, Mass., 1969. Google ScholarDigital Library
- 9 Knuth, D.E. The Art of Computer Programming, Vol. 3: Sorting and Searching. Addison-Wesley, Mass., 1972. Google ScholarDigital Library
- 10 Knuth, D.E. Structured programming with go to statements. Computing Surveys 6, 4 (Dec. 1974), 261-301. Google ScholarDigital Library
- 11 Loeser, R. Some performance tests of "quicksort" and descendants. Comm. ACM 17, 3 (March 1974), 143-152. Google ScholarDigital Library
- 12 Morris, R. Some theorems on sorting. SlAM J. Appl. Math. 17, 1 (Jan. 1969), I-6.Google ScholarCross Ref
- 13 Rich, R.P. Internal Sorting Methods Illustrated with PL/I Progams. Prentice-Hall, Englewood Cliffs, N.J., 1972.Google Scholar
- 14 Scowen, R.S. Quickersort: Algorithm 271. Comm. ACM 8, 11 (Nov. 1965), 669-670. (See also certification by C.R. Blair in Comm. ACM 9, 5 (May 1966), 354.) Google ScholarDigital Library
- 15 Sedgewick, R. Quicksort. Ph.D. Th. Stanford Comptr. Sci. Rep. STAN-CS-75-492, Stanford U., Stanford, Calif., May 1975.Google Scholar
- 16 Sedgewick, R. Quicksort with equal keys. Siam J. Comput. 6, 2 (June 1977), 240-287.Google ScholarCross Ref
- 17 Sedgewick, R. The analysis of Quicksort programs. Acta Informatica 7 (1977), 327-355.Google ScholarDigital Library
- 18 Singleton, R.C. An efficient algorithm for sorting with minimal storage: Algorithm 347. Comm. ACM 12, 3 (March 1969), 185-187. (See also remarks by R. Griffin and K.A. Redish in Comm. ACM 13, l (Jan. 1970), 54 and by R. Peto, Comm. ACM 13, l0 (Oct. 1970), 624.) Google ScholarDigital Library
- 19 Stone, H.S. Sorting on STAR. IEEE Trans. Software Eng. SE-4, 2 (Mar. 1978), 138-146.Google Scholar
- 20 van Emaen, M.N. Increasing the efficiency of quicksort: Algorithm 402. Comm. ACM 13, 11 (Nov. 1970), 693-694. (See also the article by the same name in Comm. ACM 13, 9 (Sept. 1970), 563-567.) Google ScholarDigital Library
- 21 Wirth, N. Algorithms + Data Structures = Programs. Prentice- Hall, Englewood Cliffs, N.J., 1976. Google ScholarDigital Library
Index Terms
- Implementing Quicksort programs
Recommendations
GPU-Quicksort: A practical Quicksort algorithm for graphics processors
In this article, we describe GPU-Quicksort, an efficient Quicksort algorithm suitable for highly parallel multicore graphics processors. Quicksort has previously been considered an inefficient sorting solution for graphics processors, but we show that ...
Some performance tests of “quicksort” and descendants
Detailed performance evaluations are presented for six ACM algorithms: quicksort (No. 64), Shellsort (No. 201), stringsort (No. 207), “TREESORT3” (No. 245), quickersort (No. 271), and qsort (No. 402). Algorithms 271 and 402 are refinements of algorithm ...
Optimal Partitioning for Dual-Pivot Quicksort
Dual-pivot quicksort refers to variants of classical quicksort where in the partitioning step two pivots are used to split the input into three segments. This can be done in different ways, giving rise to different algorithms. Recently, a dual-pivot ...
Comments