Abstract
The problem of merging sorted lists in the least number of pairwise comparisons has been solved completely only for a few special cases. Graham and Karp (Sorting Search 3:197–207, 1999) independently discovered that the tape merge algorithm is optimal in the worst case when the two lists have the same size. In their seminal papers, Stockmeyer and Yao (SIAM J Comput 9(1):85–90, 1980), Murphy and Paull (Inf Control 42(1):87–96, 1979), and Christen (On the optimality of the straight merging algorithm, 1978) independently showed when the lists to be merged are of size m and n satisfying \(m\le n\le \lfloor \frac{3}{2}m\rfloor +1\), the tape merge algorithm is optimal in the worst case. This paper extends this result by showing that the tape merge algorithm is optimal in the worst case whenever the size of one list is no larger than 1.52 times the size of the other. The main tool we use to prove the lower bound is Knuth’s (1999) adversary methods. In addition, we show that the lower bound cannot be improved to 1.8 via Knuth’s adversary methods. Moreover, we design a simple procedure, and by invoking this procedure recursively until the remaining subproblem can be solved efficiently by another known algorithm, we achieve constant improvement of the upper bound for \(2m-2\le n\le 3m \).
Similar content being viewed by others
Notes
As we just mentioned in the Abstract, though the concrete algorithm is not specified in this paper, it can be easily obtained by invoking our procedure recursively.
References
Ajtai, M., Feldman, V., Hassidim, A., Nelson, J.: Sorting and selection with imprecise comparisons. In: Proceedings of the 36th International Colloquium on Automata, Languages and Programming: Part I, ICALP’09, pp. 37–48 (2009)
Brown, M.R., Tarjan, R.E.: A fast merging algorithm. J. ACM 26(2), 211–226 (1979)
Cardinal, J., Fiorini, S.: On Generalized Comparison-Based Sorting Problems, pp. 164–175. Springer, Berlin (2013)
Cheng, Y., Sun, X., Yin, Y.L.: Searching monotone multi-dimensional arrays. Discrete Math. 308(11), 2213–2221 (2008)
Christen, C.: Improving the bounds on optimal merging. In: Proceedings of 19th IEEE Conference on the Foundations of Computer Science, pp. 259–266 (1978)
Christen, C.: On the optimality of the straight merging algorithm (1978) (unpublished)
de la Vega, W.F., Frieze, M.A., Santha, M.: Average-case analysis of the merging algorithm of hwang and lin. Algorithmica 22(4), 483–489 (1998)
de la Vega, W.F., Kannan, S., Santha, M.: Two probabilistic results on merging. SIAM J. Comput. 22(2), 261–271 (1993)
Gavril, F.: Merging with parallel processors. Commun. ACM 18(10), 588–591 (1975)
Gupta, A., Kumar, A.: Sorting and selection with structured costs. In: Proceedings of the 42nd IEEE Symposium on Foundations of Computer Science, p. 416 (2001)
Huang, Z., Kannan, S., Khanna, S.: Algorithms for the generalized sorting problem. In: Proceedings of the 52nd IEEE Symposium on Foundations of Computer Science, pp. 738–747 (2011)
Hwang, F.K., Deutsch, D.N.: A class of merging algorithms. J. ACM 20(1), 148–159 (1973)
Hwang, F., Lin, S.: A simple algorithm for merging two disjoint linearly ordered sets. SIAM J. Comput. 1(1), 31–39 (1972)
Hwang, F.K.: Optimal merging of 3 elements with \(n\) elements. SIAM J. Comput. 9(2), 298–320 (1980)
Hwang, F.K., Lin, S.: Optimal merging of 2 elements with \(n\) elements. Acta Inf. 1(2), 145–158 (1971)
Kannan, S., Khanna, S.: Selection with monotone comparison costs. In: Proceedings of the Fourteenth Annual ACM-SIAM Symposium on Discrete Algorithms, SODA’03, pp. 10–17 (2003)
Knuth, D.: The art of computer programming. Sorting Search. 3, 197–207 (1999)
Li, Q., Sun, X., Zhang, J.: Tables of \(\lambda \)m\(\rho \) and the program. http://theory.ict.ac.cn/liqian (2016)
Linial, N., Saks, M.: Searching ordered structures. J. Algorithms 6(1), 86–103 (1985)
Linial, N.: The information-theoretic bound is good for merging. SIAM J. Comput. 13(4), 795–801 (1984)
Manacher, G.K., Bui, T.D., Mai, T.: Optimum combinations of sorting and merging. J. ACM 36(2), 290–334 (1989)
Manacher, G.K.: Significant improvements to the Hwang–Lin merging algorithm. J. ACM 26(3), 434–440 (1979)
Murphy, P.E.: A problem in optimal meging. Technical Report DCS-TR-69, Rutgers University, Department of Computer Sciences (1978)
Murphy, P.E., Paull, M.C.: Minimum comparison merging of sets of approximately equal size. Inf. Control 42(1), 87–96 (1979)
Mönting, J.S.: Merging of 4 or 5 elements with \(n\) elements. Theor. Comput. Sci. 14(1), 19–37 (1981)
Smith, W.D., Lang, K.J.: Values of the merging function and algorithm design as a game (1994). https://core.ac.uk/display/24326238(unpublished)
Stockmeyer, P.K., Yao, F.F.: On the optimality of linear merge. SIAM J. Comput. 9(1), 85–90 (1980)
Tanner, R.M.: Minimean merging and sorting: an algorithm. SIAM J. Comput. 7(1), 18–38 (1978)
Thanh, M., Alagar, V.S., Bui, T.D.: Optimal expected-time algorithms for merging. J. Algorithms 7(3), 341–357 (1986)
Thanh, M., Bui, T.D.: An improvement of the binary merge algorithm. BIT Numer. Math. 22(4), 454–462 (1982)
Acknowledgements
This work was supported by the 973 Program of China Grant No. 2016YFB1000201, the National Natural Science Foundation of China Grants Nos. 61832003, 61761136014, 61872334, 61433014, and K.C.Wong Education Foundation.
Author information
Authors and Affiliations
Corresponding author
Additional information
Publisher's Note
Springer Nature remains neutral with regard to jurisdictional claims in published maps and institutional affiliations.
Appendix: Proof of Lemma 4
Appendix: Proof of Lemma 4
Proof
We apply induction on m and n. The cases for \(1\le m+n \le 10\) are given in [17]. Now suppose that \(m+n\ge 11\) and the lemma is already established for any \((m',n')\) satisfying \(m'+n'<m+n\).
Part (b)Case 1\(m=1\).
The algorithm begins by comparing \(a_1\) and \(b_n+1\). Suppose the adversary claims \(a_1>b_{n+1}\), then the algorithm is done with only one comparison! Otherwise, the adversary claims \(a_1<b_{n+1}\), then it reduces to the case (1, n). Thus
Case 2\(m\ge 2\).
The algorith begins by comparing \(a_m\) and \(b_{n+1}\). Suppose the adversary claims \(a_m>b_{n+1}\), then it reduces to the case \((m-1,n+1)\). Otherwise, the adversary claims \(a_m<b_{n+1}\), then it reduces to the case (m, n). Thus
By two applications of the induction hypothesis, \(/M. (m, n)\ge /M. (m-1, n)+1\ge /M.(m-1, n+1)\), thus \(/M.(m, n+1)\le /M.(m, n)+1\).
Part (c)Case 1\(m=n\).
According to Part (a), \(/M.(m+1,m)\ge /M.(m,m-1)+2\ge /M.(m-1,m-2)+4\ge \cdots \ge /M.(5,4)+2m-8=2m\), thus \(/M.(m+1,m)\ge /M.(m,m)+1\), since \(/M.(m,m)\le 2m-1\).
Case 2\(m<n\), we have
The first inequality is due to Part(a), and the second one is by the induction hypothesis. \(\square \)
Rights and permissions
About this article
Cite this article
Li, Q., Sun, X. & Zhang, J. On the Optimality of Tape Merge of Two Lists with Similar Size. Algorithmica 82, 2107–2132 (2020). https://doi.org/10.1007/s00453-020-00690-x
Received:
Accepted:
Published:
Issue Date:
DOI: https://doi.org/10.1007/s00453-020-00690-x