Optimal Expected-Time Algorithms for Merging

Optimal expected-time algorithms for (2, n) and (3, n) merge problems are given. Let ƒm(k) denote the largest n such that two ordered lists of lengths m and n can be merged in k comparisons. Our methods explore the merge trees of (2, ƒ2(k)) and (3, ƒ3(k)) problems and narrow down the choices of pairwise comparisons to minimize the expected number of comparisons even when n is not equal to ƒ2(k) or ƒ3(k). The given methods are constructive and the computed values reveal that the optimal expected value differs from the optimal worst-case value by at most 1.