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 s ≤n 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))\).
Access this chapter
Tax calculation will be finalised at checkout
Purchases are for personal use only
Preview
Unable to display preview. Download preview PDF.
References
Franceschini, G., Geffert, V.: An In-Place Sorting with O(nlogn) Comparisons and O(n) Moves. Journal of the ACM 52, 515–537 (2005)
Kronrod, M.A.: Optimal ordering algorithm without operational field. Soviet Math. Dokl. 10, 744–746 (1969)
Levcopoulos, C., Overmars, M.H.: A balanced search tree with O(1) worst-case update time. Acta Informatica 26(3), 269–277 (1988)
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)
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)
Katajainen, J., Pasanen, T.: In-place sorting with fewer moves. Inform. Process. Lett. 70, 31–37 (1999)
Horvath, E.C.: Stable sorting in asymptotically optimal time and extra space. Journal of the ACM 25(2), 177–199 (1978)
Pardo, L.T.: Stable sorting and merging with optimal space and time bounds. SIAM Journal on Computing 6(2), 351–372 (1977)
Salowe, J., Steiger, W.: Simplified stable merging tasks. Journal of Algorithms 8(4), 557–571 (1987)
Huang, B.C., Langston, M.A.: Practical in-place merging. Communications of the ACM, CACM 31(3), 348–352 (1988)
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)
Symvonis, A.: Optimal stable merging. Comput. J. 38, 681–690 (1995)
Geffert, V., Katajainen, J., Pasanen, T.: Asymptotically efficient in-place merging. Theoret. Comput. Sci. 237, 159–181 (2000)
Chen, J.: Optimizing stable in-place merging. Theor. Comput. Sci. 1-3(302), 191–210 (2003)
Estivill-Castro, V., Wood, D.: A survey of adaptive sorting algorithms. ACM Comp. Surveys 24(4), 441–476 (1992)
Munro, J.: An implicit data structure supporting insertion, deletion, and search in O(log2 n) time. J. Comput. System Sci. 33, 66–74 (1986)
Cormen, T.H., Leiserson, C.E., Rivest, R.L., Stein, C.: Introduction to Algorithms. MIT Press, Cambridge (2001)
Author information
Authors and Affiliations
Editor information
Editors and Affiliations
Rights 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)