Abstract
We consider the problem of sorting a multiset of sizen containingm distinct elements, where theith distinct element appearsn i times. Under the assumption that our model of computation allows only the operations of comparing elements and moving elements in the memory,Ω(n logn − ∑ m i=1 n i logn i +n) is known to be a lower bound for the computational complexity of the sorting problem. In this paper we present aminimum space algorithm that sortsstably a multiset in asymptoticallyOptimal worst-case time. A Quicksort type approach is used, where at each recursive step the median is chosen as the partitioning element. To obtain a stable minimum space implementation, we develop linear-time in-place algorithms for the following problems, which have interest of their own:
Stable unpartitioning: Assume that ann-element arrayA is stably partitioned into two subarraysA 0 andA 1. The problem is to recoverA from its constitutentsA 0 andA 1. The information available is the partitioning element used and a bit array of sizen indicating whether an element ofA 0 orA 1 was originally in the corresponding position ofA.
Stable selection: The task is to find thekth smallest element in a multiset ofn elements such that the relative order of identical elements is retained.
Similar content being viewed by others
References
Blum, M., Floyd, R.W., Pratt, V., Rivest, R.L., Tarjan, R.E.: Time bounds for selection. J. Comput. System Sci. 7, 448–461 (1973)
Carlsson, S., Munro, J.I., Poblete, P.V.: An implicit binomial queue with constant insertion time. Proceedings of the 1st Scandinavian Workshop on Algorithm Theory (Lect. Notes Comput. Sci., vol. 318, pp. 1–13) Berlin, Heidelberg, New York: Springer 1988
Ďurian, B.: Quicksort without a stack. Proceedings of the 12the Symposium on Mathematical Foundations of Computer Science (Lect. Notes Comput. Sci., vol. 233, pp. 283–289) Berlin, Heidelberg, New York: Springer 1986
Gonzalez, T.F., Johnson, D.B.: Sorting numbers in linear expected time and optimal extra space. Inf. Process. Lett. 15, 119–124 (1982)
Horowitz, E., Sahni, S.: Fundamentals of computer algorithms. Oxford: Computer Science Press 1978
Horvath, E.C.: Stable sorting in asymptotically optimal time and extra space. J. ACM 25, 177–199 (1978)
Huang, B.-C., Langston, M.A.: Practical in-place merging. Commun. ACM 31, 348–352 (1988)
Huang, B.-C., Langston, M.A.: Fast stable merging and sorting in constant extra space. Proceedings of the 1st International Conference on Computing and Information, 1989, pp. 71–80
Huang, B.-C., Langston, M.A.: Stable dublicate-key extraction with optimal time and space bounds. Acta Inf. 26, 473–484 (1989)
Katajainen, J., Levcopoulos, C., Petersson, O.: Space-efficient parallel merging. Inf. Théor. Appl. 27, 295–310 (1993)
Katajainen, J., Pasanen, T.: Stable minimum space partitioning in linear time. BIT 32, 580–585 (1992)
Knuth, D.E.: The art of computer programming, vol. 3: Sorting and searching. Reading, MA: Addison-Wesley 1973
Kronrod, M.A.: Optimal ordering algorithm without operational field. Sov. Math. 10, 744–746 (1969)
Lai, T.W., Wood, D.: Implicit selection. Proceedings of the 1st Scandinavian Workshop on Algorithm Theory (Lect. Notes Comput. Sci., vol. 318, pp. 14–23) Berlin, Heidelberg, New York: Springer 1988
Levcopoulos, C., Petersson, O.: An optimal adaptive in-place sorting algorithm. Proceedings of the 8th International Conference on Fundamentals of Computation Theory (Lect. Notes Comput. Sci., vol. 529, pp. 329–338) Berlin, Heidelberg, New York: Springer 1991
Levcopoulos, C., Petersson, O.: Sorting shuffled monotone sequences. Inf. Comput. (to appear)
Moffat, A.M., Petersson, O.: An overview of adaptive sorting. Aust. Comput. J. 24, 70–77 (1992)
Munro, J.I.: An implicit data structure supporting insertion, deletion, and search inO(log2 n) time. J. Comput. System Sci. 33, 66–74 (1986)
Munro, J.I., Raman, V.: Sorting multisets and vectors in-place, Proceedings of the 2nd Workshop on Algorithms and Data Structures (Lect. Notes Comput. Sci., vol. 519, p. 473–480) Berlin, Heidelberg, New York: Springer 1991
Munro, J.I., Raman, V., Salowe, J.S.: Stable in situ sorting and minimum data movement. BIT 30, 220–234 (1990)
Munro, J.I., Spira, P.M.: Sorting and searching in multisets. SIAM J. Comput 5, 1–8 (1976)
Salowe, J.S., Steiger, W.L.: Simplified stable merging tasks. J. Algorithms 8, 557–571 (1987)
Salowe, J.S., Steiger, W.L.: Stable unmerging in linear time and constant space. Inf. Process. Lett. 25, 285–294 (1987)
Wegner, L.M.: Quicksort for equal keys. IEEE Trans. Comput. C34, 362–367 (1985)
Author information
Authors and Affiliations
Rights and permissions
About this article
Cite this article
Katajainen, J., Pasanen, T. Sorting multisets stably in minimum space. Acta Informatica 31, 301–313 (1994). https://doi.org/10.1007/BF01178508
Received:
Issue Date:
DOI: https://doi.org/10.1007/BF01178508