Skip to main content
Log in

Sorting multisets stably in minimum space

  • Published:
Acta Informatica Aims and scope Submit manuscript

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.

This is a preview of subscription content, log in via an institution to check access.

Access this article

Price excludes VAT (USA)
Tax calculation will be finalised during checkout.

Instant access to the full article PDF.

Similar content being viewed by others

References

  1. 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)

    Google Scholar 

  2. 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

    Google Scholar 

  3. Ď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

    Google Scholar 

  4. Gonzalez, T.F., Johnson, D.B.: Sorting numbers in linear expected time and optimal extra space. Inf. Process. Lett. 15, 119–124 (1982)

    Google Scholar 

  5. Horowitz, E., Sahni, S.: Fundamentals of computer algorithms. Oxford: Computer Science Press 1978

    Google Scholar 

  6. Horvath, E.C.: Stable sorting in asymptotically optimal time and extra space. J. ACM 25, 177–199 (1978)

    Google Scholar 

  7. Huang, B.-C., Langston, M.A.: Practical in-place merging. Commun. ACM 31, 348–352 (1988)

    Google Scholar 

  8. 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

  9. Huang, B.-C., Langston, M.A.: Stable dublicate-key extraction with optimal time and space bounds. Acta Inf. 26, 473–484 (1989)

    Google Scholar 

  10. Katajainen, J., Levcopoulos, C., Petersson, O.: Space-efficient parallel merging. Inf. Théor. Appl. 27, 295–310 (1993)

    Google Scholar 

  11. Katajainen, J., Pasanen, T.: Stable minimum space partitioning in linear time. BIT 32, 580–585 (1992)

    Google Scholar 

  12. Knuth, D.E.: The art of computer programming, vol. 3: Sorting and searching. Reading, MA: Addison-Wesley 1973

    Google Scholar 

  13. Kronrod, M.A.: Optimal ordering algorithm without operational field. Sov. Math. 10, 744–746 (1969)

    Google Scholar 

  14. 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

    Google Scholar 

  15. 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

    Google Scholar 

  16. Levcopoulos, C., Petersson, O.: Sorting shuffled monotone sequences. Inf. Comput. (to appear)

  17. Moffat, A.M., Petersson, O.: An overview of adaptive sorting. Aust. Comput. J. 24, 70–77 (1992)

    Google Scholar 

  18. Munro, J.I.: An implicit data structure supporting insertion, deletion, and search inO(log2 n) time. J. Comput. System Sci. 33, 66–74 (1986)

    Google Scholar 

  19. 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

    Google Scholar 

  20. Munro, J.I., Raman, V., Salowe, J.S.: Stable in situ sorting and minimum data movement. BIT 30, 220–234 (1990)

    Google Scholar 

  21. Munro, J.I., Spira, P.M.: Sorting and searching in multisets. SIAM J. Comput 5, 1–8 (1976)

    Google Scholar 

  22. Salowe, J.S., Steiger, W.L.: Simplified stable merging tasks. J. Algorithms 8, 557–571 (1987)

    Google Scholar 

  23. Salowe, J.S., Steiger, W.L.: Stable unmerging in linear time and constant space. Inf. Process. Lett. 25, 285–294 (1987)

    Google Scholar 

  24. Wegner, L.M.: Quicksort for equal keys. IEEE Trans. Comput. C34, 362–367 (1985)

    Google Scholar 

Download references

Author information

Authors and Affiliations

Authors

Rights and permissions

Reprints 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

Download citation

  • Received:

  • Issue Date:

  • DOI: https://doi.org/10.1007/BF01178508

Keywords

Navigation