© 1995 by British Computer Society
| ||||||||||||||||||||||||||||||||||||||||||||||||||
Optimal Stable Merging
Basser Department of Computer Science, University of Sydney, Sydney, NSW 2006, Australia, symvonis{at}cs.su.oz.au
This paper shows how to stably merge two sequences A and B of sizes m and n, m
n, respectively, with O(m+n) assignments, O(mlog(n/m+1)) comparisons and using only a constant amount of additional space. This result matches all known lower bounds and closes an open problem posed by Dudzinski and Dydek in 1981. Our algorithm is based on the unstable algorithm of Mannila and Ukkonen. All techniques we use have appeared in the literature in more complicated forms but were never combined together. They are powerful enough to make stable all the existing linear in-place unstable algorithms we are aware of. We also present a stable algorithm that requires a linear number of comparisons and assignments which we consider to be the simplest algorithm for in-place merging.
Revised November 6 1994.
* Basser Department of Computer Science, University of Sydney, Sydney, NSW 2006, Australia, symvonis{at}cs.su.oz.au