Skip to main content

Sorting by Merging or Merging by Sorting?

  • Conference paper
Algorithm Theory – SWAT 2006 (SWAT 2006)

Part of the book series: Lecture Notes in Computer Science ((LNTCS,volume 4059))

Included in the following conference series:

  • 977 Accesses

Abstract

In the comparison model the only operations allowed on input elements are comparisons and moves to empty cells of memory. We prove the existence of an algorithm that, for any set of sn sorted sequences containing a total of n elements, computes the whole sorted sequence using O(nlogs) comparisons, O(n) data moves and O(1) auxiliary cells of memory besides the ones necessary for the n input elements. The best known algorithms with these same bounds are limited to the particular case s = O (1). From a more intuitive point of view, our result shows that it is possible to pass from merging to sorting in a seamless fashion, without losing the optimality with respect to any of the three main complexity measures of the comparison model. Our main statement has an implication in the field of adaptive sorting algorithms and improves [Franceschini and Geffert, Journal of the ACM, 52], showing that it is possible to exploit some form of pre-sortedness to lower the number of comparisons while still maintaining the optimality for space and data moves. More precisely, let us denote with Opt M (X) the cost for sorting a sequence X with an algorithm that is optimal with respect to a pre-sortedness measure M. To the best of our knowledge, so far, for any pre-sortedness measure M, no full-optimal adaptive sorting algorithms were known (see [Estivill-Castro and Wood, ACM Comp. Surveys, 24], page 472). The best that could be obtained were algorithms sorting a sequence X using O(1) space, O(Opt M (X)) comparisons and O(Opt M (X)) moves. Hence, the move complexity seemed bound to be a function of M(X) (as for the comparison complexity). We prove that there exists a pre-sortedness measure for which that is false: the pre-sortedness measure Runs, defined as the number of ascending contiguous subsequences in a sequence. That follows directly from our main statement, since \({Opt}_{M}(X)=O(\left\vert{X}\right\vert \log Runs(X))\).

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

Access this chapter

Chapter
USD 29.95
Price excludes VAT (USA)
  • Available as PDF
  • Read on any device
  • Instant download
  • Own it forever
eBook
USD 39.99
Price excludes VAT (USA)
  • Available as PDF
  • Read on any device
  • Instant download
  • Own it forever
Softcover Book
USD 54.99
Price excludes VAT (USA)
  • Compact, lightweight edition
  • Dispatched in 3 to 5 business days
  • Free shipping worldwide - see info

Tax calculation will be finalised at checkout

Purchases are for personal use only

Institutional subscriptions

Preview

Unable to display preview. Download preview PDF.

Unable to display preview. Download preview PDF.

References

  1. Franceschini, G., Geffert, V.: An In-Place Sorting with O(nlogn) Comparisons and O(n) Moves. Journal of the ACM 52, 515–537 (2005)

    Article  MathSciNet  Google Scholar 

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

    MATH  Google Scholar 

  3. Levcopoulos, C., Overmars, M.H.: A balanced search tree with O(1) worst-case update time. Acta Informatica 26(3), 269–277 (1988)

    Article  MATH  MathSciNet  Google Scholar 

  4. Andersson, A., Lai, T.W.: Comparison–efficient and write–optimal searching and sorting. In: Hsu, W.-L., Lee, R.C.T. (eds.) ISA 1991. LNCS, vol. 557, pp. 273–282. Springer, Heidelberg (1991)

    Google Scholar 

  5. Fleischer, R.: A simple balanced search tree with O(1) worst-case update time. In: Ng, K.W., Balasubramanian, N.V., Raghavan, P., Chin, F.Y.L. (eds.) ISAAC 1993. LNCS, vol. 762, pp. 138–146. Springer, Heidelberg (1993)

    Google Scholar 

  6. Katajainen, J., Pasanen, T.: In-place sorting with fewer moves. Inform. Process. Lett. 70, 31–37 (1999)

    Article  MATH  MathSciNet  Google Scholar 

  7. Horvath, E.C.: Stable sorting in asymptotically optimal time and extra space. Journal of the ACM 25(2), 177–199 (1978)

    Article  MATH  Google Scholar 

  8. Pardo, L.T.: Stable sorting and merging with optimal space and time bounds. SIAM Journal on Computing 6(2), 351–372 (1977)

    Article  MATH  MathSciNet  Google Scholar 

  9. Salowe, J., Steiger, W.: Simplified stable merging tasks. Journal of Algorithms 8(4), 557–571 (1987)

    Article  MATH  MathSciNet  Google Scholar 

  10. Huang, B.C., Langston, M.A.: Practical in-place merging. Communications of the ACM, CACM 31(3), 348–352 (1988)

    Article  Google Scholar 

  11. Huang, B.C., Langston, M.A.: Stable set and multiset operations in optimal time and space. In: ACM (ed.) PODS 1988. Proceedings of the Seventh ACM SIGACT-SIGMOD-SIGART Symposium on Principles of Database Systems, pp. 288–293. ACM Press, New York (1988)

    Chapter  Google Scholar 

  12. Symvonis, A.: Optimal stable merging. Comput. J. 38, 681–690 (1995)

    Google Scholar 

  13. Geffert, V., Katajainen, J., Pasanen, T.: Asymptotically efficient in-place merging. Theoret. Comput. Sci. 237, 159–181 (2000)

    Article  MATH  MathSciNet  Google Scholar 

  14. Chen, J.: Optimizing stable in-place merging. Theor. Comput. Sci. 1-3(302), 191–210 (2003)

    Article  Google Scholar 

  15. Estivill-Castro, V., Wood, D.: A survey of adaptive sorting algorithms. ACM Comp. Surveys 24(4), 441–476 (1992)

    Article  Google Scholar 

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

    Article  MATH  MathSciNet  Google Scholar 

  17. Cormen, T.H., Leiserson, C.E., Rivest, R.L., Stein, C.: Introduction to Algorithms. MIT Press, Cambridge (2001)

    MATH  Google Scholar 

Download references

Author information

Authors and Affiliations

Authors

Editor information

Editors and Affiliations

Rights and permissions

Reprints and permissions

Copyright information

© 2006 Springer-Verlag Berlin Heidelberg

About this paper

Cite this paper

Franceschini, G. (2006). Sorting by Merging or Merging by Sorting?. In: Arge, L., Freivalds, R. (eds) Algorithm Theory – SWAT 2006. SWAT 2006. Lecture Notes in Computer Science, vol 4059. Springer, Berlin, Heidelberg. https://doi.org/10.1007/11785293_10

Download citation

  • DOI: https://doi.org/10.1007/11785293_10

  • Publisher Name: Springer, Berlin, Heidelberg

  • Print ISBN: 978-3-540-35753-7

  • Online ISBN: 978-3-540-35755-1

  • eBook Packages: Computer ScienceComputer Science (R0)

Publish with us

Policies and ethics