Abstract
In this paper, we describe an algorithm to stably sort an array ofn elements using only a linear number of data movements and constant extra space, albeit in quadratic time. It was not known previously whether such an algorithm existed. When the input contains only a constant number of distinct values, we present a sequence ofin situ stable sorting algorithms makingO(n lg(k+1) n+kn) comparisons (lg(K) means lg iteratedk times and lg* the number of times the logarithm must be taken to give a result ≤ 0) andO(kn) data movements for any fixed valuek, culminating in one that makesO(n lg*n) comparisons and data movements. Stable versions of quicksort follow from these algorithms.
Similar content being viewed by others
References
S. Baase,Computer Algorithms: Introduction to Design and Analysis, Addison-Wesley (1988).
B. Ďurian,Quicksort without a stack, Math. Foundations of Computer Science,Lecture Notes in Computer Science 223,Springer Verlag (1986) 283–289.
D. Gries,Constant-space quicksort, Unpublished manuscript, March 1989.
T. Hoare,Quicksort, CACM 4 (7) (1961) 321.
D. E. Knuth,The Art of Computer Programming. Volume III: Sorting and Searching, Addison-Wesley (1973).
D. E. Knuth,Mathematical Analysis of Algorithms, Proceedings, I.F.I.P. Congress, ed. C.V. Frieman, North-Holland, Amsterdam (1972) 19–27.
M. A. Kronrod,Optimal ordering algorithm without operational field, Soviet Math. Dokl.10 (1969) 744–746.
I. D. G. Macleod,An algorithm for in-situ permutation, Australian Computing Journal2 (1970) 16–19.
J. I. Munro and V. Raman,Sorting with minimum data movement, Proceedings of Workshop on Algorithms and Data Structures, Ottawa,Lecture Notes in Computer Science 382,Springer Verlag (August 1989) 552–562.
L. Trabb Pardo,Stable sorting and merging with optimal space and time bounds, SIAM J. on Computing6 (1977) 351–372.
J. S. Salowe and W. L. Steiger,Stable unmerging in linear time and constant space, IPL25 (1987) 285–294.
J. S. Salowe and W. L. Steiger,Simplified stable merging tasks, J. Algorithms 8 (1987) 557–571.
L. M. Wegner,A generalized one way stackless quicksort, BIT27 (1987) 44–48.
P. F. Windley,Transposing matrices in a digital computer, The Computer Journal2 (1959) 47–48.
Author information
Authors and Affiliations
Additional information
Research supported by Natural Sciences and Engineering Research Council of Canada grant No.A-8237 and the Information Technology Research Centre of Ontario.
Supported in part by a Research Initiation Grant from the Virginia Engineering Foundation.