17

Click here to load reader

Optimal expected-time algorithms for merging

Embed Size (px)

Citation preview

Page 1: Optimal expected-time algorithms for merging

JOURNAL OF ALGORITHMS 7, 341-357 (1986)

Optimal Expected-Time Algorithms for Merging

MAITHANH, V. S.ALAGAR,AND T.D. BUI

Department of Computer Science, Concordia University, Montreal, Quebec H3G 1 M8, Canada

Received June 8,1984

Optimal expected-time algorithms for (2, n) and (3, n) merge problems are given. Let f,(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, fi (k)) and (3, f3(k)) problems and narrow down the choices of pairwise comparisons to minimize the expected number of comparisons even when n is not equal to h(k) or f,(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. 0 19R6 Academic f’ress. Inc.

1. INTRODUCTION

Several problems arising in data analysis and information management frequently deal with two closely related concepts: sorting and merging. Merging algorithms have been studied with great interest because of their inherent complexity and potential applications. The merging problem as- sumes that two ordered sets of distinct objects from a set S are given in

and

x(1 : m) : x, < x2 * * * < x,

Y(l:n):Y,< Y,< **a <Y”

and requests the m + n values of their union in ascending order. Our interest is in those algorithms that merge two lists solely by malting painvise comparisons between objects. In this paper we discuss optimal expected-time algorithms for merging two ordered lists of distinct objects.

Suppose A is any algorithm for merging X(1 : m) and Y(l: n) (hereafter referred to as (m, n) merge problem). Let iU,(m, n) denote the maximum number of comparisons required and ii?,( m, n ) the average number of

341 0196-6774/86$3.00

Copyright B 1986 by Academic Press. Inc. All ri&ts of reproduction in any form reserved.

Page 2: Optimal expected-time algorithms for merging

342 THANH, ALAGAR, AND BUI

comparisons required by the algorithm A, where the maximum is over all possible inputs of sixes m and n and the average is computed assuming a uniform distribution of sequences in X U Y. By uniform distribution we mean that each of the (“: n, outcomes is equiprobable. We define

M(m, n) = 4” { MA(m, n)},

M(m, n) = yjn { Il?,(m, n)},

where the minimum is taken over all algorithms. An algorithm A is M-o@nal if Mim, n) = M,(m, n). Similarly an algorithm B is G-optimal if M(m, n) = M,(m, n).

The determination of M(m, n) for arbitrary values of m, n is still an open problem. Hence, if f,(k) denotes the largest n such that two linearly ordered lists of lengths m and n can be merged in exactly k comparisons then finding f,(k) for general m and k is also still open. See [3,4] for results on f*(k) a_nd f,(k) and [l, 2,7] for results on f4(k) and fs(k).

The function M(m, n) has not been completely determined for m > 1. Hwang and Lin [3] throw some light on the expected time behavior of their M-optimal algorithm for the (2, n) merge problem. This paper extends the results of Hwang and Lin to obtain exact values for ii;l<2, n), n # f,(k) and good bounds for E(3, n), n # f,(k). Our methods may be generalized to values m 2 4.

2. THEORETICAL BACKGROUND AND BASIC RESULTS

Historically, linear merging, known also as tape linear merge, is the first merge algorithm. It is well known that the average number of comparisons for linear merge can be shown to be m + n - m/( n + 1) - n/(m + l), which is very close to the worst-case bound m + n - 1.

The binary merge algorithm HL of Hwang and Lin [3] improves the tape linear merge by adapting a split-merge strategy. Informally stated, this algorithm first splits the large list into m blocks, each of size 2’, t = ]log(n/m)J; the element X, of the shorter list is compared with Y,,- *t+ i and if X,,, is found smaller, then the last 2’ elements are removed from the larger list; otherwise, X, is inserted into the last group of 21 elements. The same process is repeated until all the elements of X are completely merged with Y. It can be shown that the expected cost - M,,(m, n) satisfies the recurrence

M,,(m, n) = p@,,(m, n - 2’) + Cp,M,,(m - 1, n - r),

Page 3: Optimal expected-time algorithms for merging

OPTIMAL EXPECTED-TIME MERGING 343

where

p = Prob[X, < Y”-$+ij

= m+n-2 (

m+n m )I ) m

and

p, = Prob[Y, < X,,, < K+,l, n-f’+llrln

= n--r+m-1 i m-l

Manacher [6], Mai Thanh and Bui [5], and Tanner [S] have improved the binary merge algorithm by lowering either the worst-case bound or the average cost. In [3], Hwang and Lin provided an M-optimal algorithm for the (2, n) merge problem and also showed that it is M-optimal for infinitely many_values of n. In particular for n = f2(k), their algorithm is both M- and M-optimal.

We believe that the results in thii paper are not only new but also significant. The computed results, M(2, n) and M(2, n), are shown in Table I and %(3, n) and M(3, n) are shown in Table III. M(2, n) and M(3, n) are given in [3] and [4], respectively:

M(2, n) = [log$n + 1)1 + [log&(n + 1)1 (1)

M(3, n) = [log%( n + 2)j + [log$$( n + 2)] + flog&( n + +)I. (2)

From Tables I and III, we note that the difference M - 2 is at most 1 for those cases. We expect this difference to grow substantially for values m 2 4.

Continuing with the conventions in [l, 2,4], we present a merge algorithm in the form of a rooted binary tree where each internal node is associated with a comparison of two elements: the first is an element from X and the second is an element from Y. If the first element is smaller than the second, then we follow the left branch. Otherwise, we follow the right branch. These two branches lead to further comparisons which are represented by internal nodes at the lower levels of the tree. The leaf nodes are the final configura- tions which can be readily analyzed. See, for example, Fig. 3. The number of comparisons in the worst case is the depth of the tree and in the average case it is the average external path length of the tree. Hence, for an (m, n) merge problem, finding an algorithm which minimizes the average number of comparisons is equivalent to finding a corresponding merge tree which has a minimum average external path length. Since the number of outcomes (leaf nodes) is a constant for a given n, it is sufficient to look for a merge tree for which the external path length is minimum.

Page 4: Optimal expected-time algorithms for merging

344 THANH, ALAGAR, AND BUI

An (m, n) merge problem produces one outcome out of a possible (“,’ n, merge sequence. It can be shown that the information theoretic lower bound for the expected number of comparisons is

ITM( m, n) = x + 2 - 2x+*/y,

where

y = (“,‘“), x = [logy].

A comparison at an internal node c of a merge tree is said to satisfy the “balanced criteria” if

2”-’ I {n,, n,} I 2”,

where s = llog t 1, t is the number of outcomes under this internal node, and n, and n, are the number of outcomes in the left and right subtrees of node c. Clearly, when the expected number of comparisons on a merge (m, n) tree is equal to F!FX( M, n), every comparison on the tree must satisfy the balanced criteria.

Suppose a list Y for size n, f,(k) < n < f,(k + 1) for some integer k > 4 is given. We remark that it is not always possible to find a sequence of comparisons which splits the merge tree satisfying the balanced criteria. The following example illustrates this point.

EXAMPLE 1. Consider merging X, < X, with Y, < Y, c Y, < Y,. There are 15 possible outcomes and there are only 4 possible choices of compari- sons (due to symmetry) at the root. These are:

Choice of comparison “i nr x,: Y* W4) 14(l) x2 : .Y* 302) 12(3) x,: Y, b(9) 96) x2 : Y4 W) w9

But we must have 4 I {n,, n,} s 8 for balanced criteria to hold. Thus, we conclude that 17X4(2,4) bound cannot be achieved.

Given an (m, n) merge problF, in general, the ITM(m, n) is not achievable. Assuming we have an M-optimal merge tree with the number of unbalanced nodes equal to a,, for the case of m = 1,2, and 3 we are unable to find a non-%-optimal merge tree with the number of unbalanced nodes less than ~1~. This leads us to conjecture that among all the %-optimal trees, there must be at least one with a minimum number of unbalanced nodes.

Page 5: Optimal expected-time algorithms for merging

OPTIMAL EXPECTED-TIME MERGING 345

At some stage in the process of merging we may encounter independent situations. For example, the figure below shows the independent situations where Xi can be merged into Y(l: s) and X, can be merged into Y(t : n) where 1 c s < t -c n:

In such situations, it is important to realize that the order of doing these independent tasks (e.g., merging a subset of X into Y) will not affect either the worst-case or the average-case bounds of the entire problem. We prove the following lemma.

LEMMA 1. In the process of merging, if more than one task can be done independently, then the order of doing these tasks does not affect neither the worst-case bouna!s nor the average-case bouna5 of the whole algorithm. In particular, for any two independent tasks a, b if A, B denote the corresponding merge trees, EA, E, their external path lengths, and L,, L, the set of leaf nodes in A and B, then the external path length E of the tree which contains these two independent tasks is

E = EhLl + &IL,I. (4)

Proof Consider two independent tasks a and b. If we perform task a first, the resulting tree will be as shown in Fig. 1. If we perform task b first, the resulting tree will be as shown in Fig. 2.

From the two situations shown above, it is easy to see that d, + d, is the depth of both trees. From Fig. 1 we find the external path length of that

FIGURE I

Page 6: Optimal expected-time algorithms for merging

346 THANH, ALAGAR, AND BUI

FIGURE 2

tree to be

c c (ey+eJ XCL” YEL,

From Fig. 2 the external path length of that tree can be seen to be

C C (e,+e,)- YEL, XCL”

Hence the external path lengths are equal. Clearly, the external path length of a tree that combines the independent tasks is

When there are several independent tasks on a merge tree, we may do the above computation repeatedly.

3. %&OPTIMAL ALGORITHMS AND EXPECTED-TIME BOUNDS

Hwang and Lin [3] have given an M-optimal algorithm for the (2, n) merge problem. This algorithm asserts that there is a unique choice (but for symmetry) of pairwise comparisons on the merge tree which merges two elements in an fi( k) element set using exactly k comparisons. Moreover this algorithm is also M-optimal for solving the (2, n) merge problem for n = f*(k); the choice of painvise comparisons that forced M-optimality achieves the information theoretic lower bound ITM(2, n).

For values n f f*(k), the Hwang-Lin algorithm is not E-optimal. As they remark [3], the determination of the value 1 5 s I n such that the comparison (X, : Y,) at the root of the merge tree will minimize the expected number of comparisons required, even assuming that we can

Page 7: Optimal expected-time algorithms for merging

OPTIMAL EXPECTED-TIME MERGING 347

proceed optimally thereafter, is a difficult problem. Moreover, it seems that for me= 2, n # f,(k), and m 2 Land for all n, an M-optimal algorithm is not M-optimal; for m 2 3 an M-optimal algorithm need not be M-opti- mal; however, for n = 1,2 an %&optimal algorithm can be M-optimal.

We can systematically and algorithmically determine the expected worst- case values for m = 2,3 and for all values of m. As we prove below, the number of choices of pairwise comparisons at all levels of a merge tree is polynomially bounded for the (2, n) and (3, n) merge problems. Thus one procedure described below determines an il?-algorithm as well as the a-value. For the (m, n), m 2 4, merge problem we do not have any conclusive results; however, we conjecture that the number of choices to be considered at all levels of a merge tree may not be polynomially bounded.

LEMMA 2. Asymptotically, the maximum number of choices for an 11?(2, n) algorithm is 4.53(10e4n5) and the maximum number of choices for an E(3, n) algorithm is 2.547 (10V7n”).

Proof: Let f*(k) < n < f,(k + l), for some integer k > 1. Consider m = 2 first. In order to balance the number of outcomes, the comparison at the root should be (X, : Y,), where

f& - 1) < t <f&J.

Thus, there are f*(k) - f,(k - 1) possible choices at the root. Since, f2(k) = 1.2132 (2“i2), we conclude that there are at most 0.355 (zk12) choices at the root. This quantity can once again be approximated to 0.246n, if we write

n = Jf2Wf2@ + 1).

When k is even the merge tree has five levels and when k is odd the merge tree has two levels. See [3]. In either case the number of choices per level is decreased by a factor of 1.2132. Thus, in the former case, the number of choices is roughly bounded by 4.5(10e4n5) and in the latter case by 0.0499n2.

Next consider m = 3 and f3(k) < n < f3(k + 1). We consider only the case k = 0 mod 3, for this has the maximum number of choices. At the root of the merge tree either X2 or Xi may be compared. In the former case an appropriate choice Y, is for t in the range [ f,(k - l), f2(k)]; in the latter case (by symmetry this holds for X, as well) an appropriate choice Y, is for s in the range [ f3( k - l), f3( k)]. Thus there are a maximum of 0.36(2k/3) choices for t and 0.315(2k/3) choices for s. Once again approximating n and noting that there are five levels [4] we conclude that roughly there are 6.8(10V4n5) total choices in the first case and 3.7(10P4n5) total choices in

Page 8: Optimal expected-time algorithms for merging

348 THANH, ALAGAR, AND BUI

the second strategy. Thus the maximum number of choices is their product. Next consider computing a(2, n) and a(3, n). In the diagrams to

follow, a comparison Xi : ‘; is shown as i : j at a node of the merge tree. Suppose the first comparison is (2 : t), 1 I 1 I n. Let T(m) denote the

merge tree for the (2, m) problem and E(T(m)) denote its external path length. Let H(t, n) denote the merge tree for the (2, n) problem in which X, > Y is known. Now we write from the situation:

E(T(n)) I E(T(t - 1)) + E(H(t, Fr)) + in ; 2).

Hence we write

Emin( T( ~)) = min 15t<n

(E(T(t - 1)) + E(H(t, n)) + (’ ; ‘)I. (5)

However, we need not consider all possible values of t to compute E,,,(T(n)); it is sufficient to consider those cases for which the difference between the number of outcomes of the left subtree of the root and that of the right subtree of the root is as small as possible according to the balanced criteria. Since f,(k - 1) -E n -C f2(k), the merge tree has to be adapted to the merge tree of either (2, f2(k - 1)) or (2, f2(k)). Recall from [3] that the first comparison in the merge tree of the (2, f,(k - 1)) problem is (X, : Y,), a = f2(k - 2) + 1, and in the case of the (2, f*(k)) problem the first comparison is (X, : Y,), b = f2( k - 1) + 1. Hence for our analysis we must choose t such that a I t I b. Beyond these limits either the left or the right subtree is too large (its depth exceeds the M-optimal bound, hence its external path length is large). Hence, in computing E&( T(n)) it is sufficient to compute the minimum of the right side in (5) for a I t I b.

Next consider computing the optimal external path length for the tree H(t, n). There are two ways in which this merge can proceed.

Page 9: Optimal expected-time algorithms for merging

OPTlMAL EXPECTED-TIME MERGING 349

Case 1. We compare X,: Y,, 1 I s I t.

So we have

E,(W, 4) = min { E(T,(s - 1, n - t)) + E( H( t - s, n - s))}, (6) lSS<f

where T,(s - 1, n - t) is the expression (4) for the independent tasks of inserting XI in Y(l: s - 1) and X, in Y(t + 1: n).

Case 2. We compare (X, : Y,), t I u I n.

Clearly, the external path length for this configuration is

E,(H(t, n)) = mi;n{E(H(U, n)) + E(NtTu))l+ (7)

From (6) and (7), we have I&,( H(t, n)) rmin{ E,, E2}. Substituting this in (5), we have an algorithm to compute M(2, n).

Page 10: Optimal expected-time algorithms for merging

350 THANH, ALAGAR, AND BUI

Algorithm Compute (2, n)

(*Returns &(2, n) as the expected value bound *) If n = f2( k ) for some k E N then

Et n;2 *ITit4(2,n) ( I-

else begin

a + fdk - 21, b + fdk - 1) for t := a to b do

begin G + compute (2, t - 1) + H(t, n) if E < G then E + G

end

end

M(2,n)tE n;2 ic )

Procedure Wt, n)

(* Returns E as the external path length of the tree H( t, n)*) Et00 for i := 1 to t do

begin j + IND(i - 1, t) + H(n - i, t - i) ifE<jthenE+j.

end for u := t to n do

begin G + H(t, u) + H(u, n) ifE<GthenE+G

end Return E.

Note that IND(a, b) uses the results of Lemma 1. The computed values for a(2, n), 1 I n s 100, are given in Table I.

Next we discuss the average-case analysis for the merge (3, n) problem. Four cases are to be considered; the first three are for n = f3(k) and the last case applies to n # f3(k). See Hwang [4] and Table II for definitions of symbols used in Figs. 3-5.

Case 1. k = 3r, r 2 1. The merge tree is given in Fig. 3. This is Fig. 2 in [4] but adapted to our conventions. This merge tree does not achieve ITM(3, n) bound. This can be verified by considering the terminal nodes B

Page 11: Optimal expected-time algorithms for merging

n

1 1.6667 2 51 10.5138 11 2 2.6667 3 52 10.5688 11 3 3.4000 4 53 10.6209 11 4 4.0000 5 54 10.6701 12 5 4.4762 5 55 10.7168 12 6 4.8929 6 56 10.7610 12 7 5.2500 6 57 10.8030 12 8 5.5778 6 58 10.8429 12 9 5.8545 7 59 10.8809 12

10 6.1061 7 60 10.9170 12 11 6.3590 7 61 10.9514 12 12 6.5934 7 62 10.9886 12 13 6.7810 8 63 11.0365 12 14 6.9500 8 64 11.0904 12 15 7.1397 8 65 11.1474 12 16 7.3268 8 66 11.2019 12 17 7.5029 8 67 11.2540 12 18 7.6526 8 68 11.3039 12 19 7.7810 9 69 11.3517 12 20 7.8918 9 70 11.3975 12 21 8.0158 9 71 11.4414 12 22 8.1558 9 72 11.4835 12 23 8.2933 9 73 11.5240 12 24 8.4246 9 74 11.5628 12 25 8.5413 9 75 11.6001 12 26 8.6455 9 76 11.6360 12 27 8.7389 10 77 11.6706 13 28 8.8230 10 78 11.7038 13 29 8.8989 10 79 11.7358 13 30 8.9819 10 80 11.7666 13 31 9.0739 10 81 11.7964 13 32 9.1747 10 82 11.8250 13 33 9.2790 10 83 11.8527 13 34 9.3746 10 84 11.8793 13 35 9.4625 10 85 11.9051 13 36 9.5434 10 86 11.9300 13 37 9.6181 10 87 11.9540 13 38 9.6872 11 88 11.9783 13 39 9.7512 11 89 12.0095 13 40 9.8107 11 90 12.0447 13 41 9.8660 11 91 12.0851 13 42 9.9175 11 92 12.1258 13 43 9.9729 11 93 12.1653 13 44 10.0329 11 94 12.2035 13 45 10.1055 11 95 12.2405 13 L6 10.1844 11 96 12.2765 13 47 10.2585 11 97 12.3113 13 48 10.3282 11 98 12.3451 13 49 10.3937 11 99 12.3778 13 50 10.4555 11 100 12.4096 13

OPTIMAL EXPECTED-TIME! MERGING

TABLE I &~,~):OPTIMALE~PECTEDVAL~ES

351

M(2.n) ” M(2,l-l) M(2.n)

and C in which the task of merge (2, ct - c1 - 1) is done independently and c2 - c1 - 1 # f(2r), for any r.

If we use the strategy of computing the external path length for all possible comparisons, then the computations grow exponentially. There- fore, instead of computing the optimal average bounds by examining all

Page 12: Optimal expected-time algorithms for merging

352 THANH, ALAGAR, AND BUI

TABLE II DEFINITIONS OF SYMBOLS USED IN FIGS. 3-5

Definitions of $vmbols used in Fig. 3 co = f,(3r) = 2 + f*(2r - 3) + f*(21. - 7) + 1 = [$w2] - 2

~~=jl.(3;)tij_[43.2~3-4i

c2 = 2’-’ + 2r-2 +f,(3r - 4) + 1 = I’“‘/‘-“1

c, =f,(3r) - 2r+4 + 1 = /9-41

c4 = 2’--’ + 2’-2 + f2(2r - 3) + 1 = [y2’-2 J

:’ 6

I 1: . 1 :‘I’ r 4 = = [9-31 [?2’-41

c; = c; = y-1 c; = & = 2r-1 + 2r-2 = 3 . 2r-2

Definitions of symbols wed in Fig. 4 co =f3(3r + 1) = 2’-2 + 2’-3 +f,(3r) = pyzr-31 - 2

c, =f,(3r) + 1 = 1$2’-2] - 1 c2 2 = Cl + 2’- = [?2r-21 - 1

C) =f*(2r) + 1 = [+-‘J

c4 = c, + 2’-2 = 19-‘j c5 = c4 + 2’-3 = 19-31

Definitions of symbols wed in Fig. 5

~~=~(3r+2)=2/7(2r)+l=[~~‘;-~j-l

possible outcomes, we compute the upper bound and the lower bound of the merge tree as follows:

At the nodes where the problem is reduced to one of the previous cases (i.e., merge(1, n) or merge (2, n)) and the tasks can be performed indepen- dently, we obtain the external path length from the previous cases and by using Lemma 1. These nodes are B, C, F, G, H, and I.

As for nodes D, E,.J, K the external path length is not computed directly. We compute the lower bound and the upper bound for the external path length as follows: the lower bound is the theoretical lower bound and the upper bound is the worst-case optimal merge tree (which is the product of the number of worst-case comparisons and the number of outcomes).

Page 13: Optimal expected-time algorithms for merging

OPTIMAL EXPECTED-TIME MERGING

c; Ck c1c4 c2 c3 'k c1c4c2c3c0 I \

w -nT,, c2!6c3co l6 c3 G H --3x717 J K

FIGURE 3

Node A (left subtree) is symmetrical to the right subtree, hence it is not necessary to analyze A.

Hence, for the whole tree, we can compute the lower bound as well as the upper bound for the external path length.

Case 2. K = 3r + 1, t 2 0. The merge tree for this case is given in Fig. 4. (See Fig. 3 of [4].)

Page 14: Optimal expected-time algorithms for merging

354 THANH, ALAGAR, AND BUI

C3 ClC2 co

/V

I3

FIGURE 4

C D

FIGURE 5

Page 15: Optimal expected-time algorithms for merging

OPTIMAL EXPECTED-TIME MERGING 355

Node A can be analyzed as in Case 1. Since the tasks to be done at nodes B and C are independent, Lemma 1 and results for rn = 1,2 can be applied to analyze these nodes. For the nodes D, E, F Case 1 analysis is applicable (similar to nodes D, E, .I, K of Case 1).

Case 3. k = 3r + 2. The merge tree for this case is given in Fig. 5. (See Fig. 4 of [4].)

The computations of the terminal nodes are given below: The left branch (node A) of the merge tree is symmetrical to the right

branch. Therefore we discuss only the computations for the right branch of this merge tree.

Node B is analyzed by means of Lemma 1 and previous results. Node D can be analyzed in a recursive fashion and Case 1 analysis applies to node C.

Case 4. f3 -c n -c f3(k + 1) for some k. As in the merge (2, n) case, we shall adapt the merge tree to either the merge tree of (3, f3(k)) or (3, f3(k + 1)). In doing so we shall have to keep the tree as balanced as possible. So we use the concept of “proportionality” as described below:

c\ f3(k) ] /

‘5 C.

I ‘j n

We use the merge tree (3, f3(t)), t = k or k + 1 in which the points ci of the tree (3, f3(k)) is replaced by ci = r ci where

r = n/f,(k) if we use the merge tree (3, f3 (k))

Vf,(k + 1) ifweusethemergetree(3,f,(k+ 1)).

Moreover we will take the minimum of these bounds. Our algorithm to compute Ii?(3, n) is written similar to Compute (2, n) but it takes into account the details of the above four cases. Computed results for the lower and upper bounds for M(3, n), 1 I n I 100 are given in Table III. Note that the bounds are tight and a(3, n) differs from M(3, n) by at most 1.

4. CONCLUDING REMARKS

To the best of our knowledge this is the first paper which addresses the optimal expected case algorithm for merge problems. Our main motivation has been to explore the relatedness of M-optimal and G-optimal al-

Page 16: Optimal expected-time algorithms for merging

356 THANH, ALAGAR, AND BUI

TABLE III LOWERANDUPPERBOUNDSFOR E(3,n)

n

1 2 3 4 5 6 7 a 9

10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50

-

LoWelI Upper bound bound

2.000 2.000 3 51 15.273 15.425 3.400 3.400 5 52 15.360 15.513 4.577 4.577 6 53 15.442 15.597 5.385 5.385 6 54 15.476 15.630 6.104 6.104 7 55 15.541 15.696 6.748 6.748 8 56 15.617 15.773 7.220 1.220 8 57 15.724 15.881 7.754 7.754 9 58 15.797 15.955 8.152 8.234 9 59 15.910 16.069 8.549 8.635 9 60 15.992 16.152 8.950 9.039 10 61 16.065 16.225 9.247 9.340 10 62 16.141 16.302 9.545 9.641 10 63 16.197 16.359 9.895 9.994 11 64 16.284 16.446

10.147 10.249 11 65 16.331 16.494 10.349 10.452 11 66 16.383 16.547 10.622 10.728 11 67 16.435 16.599 10.889 10.998 12 68 16.493 16.658 11.115 11.226 12 69 16.537 16.703 11.298 11.411 12 70 16.605 16.771 11.441 11.555 12 71 16.656 16.823 11.686 11.803 12 72 16.729 16.896 11.904 12.023 13 73 16.794 16.961 12.088 12.208 13 74 16.875 17.044 12.237 12.359 13 75 16.929 17.098 12.381 12.505 13 76 17.004 17.174 12.483 12.608 13 77 17.098 17.269 12.689 12.815 13 78 17.147 17.318 12.862 12.991 14 79 17.203 17.375 13.013 13.143 14 80 17.242 17.414 13.152 13.283 14 ai 17.312 17.485 13.263 13.395 14 82 17.349 17.522 13.380 13.514 14 83 17.418 17.593 13.464 13.598 14 a4 17.469 11.644 13.604 13.740 14 85 17.482 17.657 13.745 13.882 14 86 11.526 17.701 13.900 14.039 15 87 17.560 17.736 14.006 14.146 15 a8 17.610 14.121 14.262

17.786 15 a9 17.657 11.833

14.220 14.362 15 90 17.697 17.874 14.331 14.475 15 91 17.746 11.923 14.422 14.566 15 92 17.818 17.996 14.481 14.632 15 93 17.886 la.064 14.577 14.723 15 94 17.931 18.110 14.701 14.848 15 95 11.969 18.148 14.820 14.968 15 96 18.028 la.208 14;904 15.053 15 97 la.097 18.278 15.007 15.157 16 98 18.160 18.342 15.213 15.365 16 99 la.204 la.386 15.213 15.365 16 100 la.231 la.413

M(3,n) n

-

Lower UPPer bound bound M(3,n)

16 16 16 16 16 16 16 16 16 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 ia ia 18 18 18 18 18 la la ia la la 18 ia la la la 18 la 18 la 19 19 19 19

gorithms. We have given in this paper z(2, n) and a(3, n) algorithms and we have shown their closeness to M(2, n) and M(3, n) through a table of computed results.

It seems difficult to carry on this approach for finding E(m, n), m 2 4, because of the enormous growth in the number of possibilities to be

Page 17: Optimal expected-time algorithms for merging

OPTIMAL EXPECTED-TIME MERGING 357

examined in a merge process. Since M-optimal algorithms are not known for m > 4, we hoped to find a-optimal algorithms. This in turn, we thought, would throw some insight into M(m, n). Our limited experience indicates that finding M-optimal algorithms is as hard as finding M-opti- mal algorithms.

ACKNOWLEDGMENTS

This work is supported in part by the Natural Sciences and Engineering Research Council of Canada and the Programme de Formation de Chercheurs et d’action ConcertCe (FCAC) of QuCbec.

REFERENCES

1. V. S. ALAGAR, T. D. BUI, AND MAI THANH, “Efficient algorithms for merging,” Technical Report, Concordia University, 1982.

2. V. S. ALAGAR, T. D. But, AND MAI THANH, Efficient algorithms for merging, BIT 23 (1983). 410-428.

3. F. K. HWANG AND S. LIN, Optimal merging of 2 elements with n elements, Acru Inform. 1 (1971), 145-158.

4. F. K. HWANG, Optimal merging of 3 elements with n elements, SIAM J. Comput. 9 (1980). 298-320.

5. MAI THANH AND T. D. BUI, An improvement of binary merge algorithm, BIT 22 (1982) 454-442.

6. G. K. MANACHER, Significant improvements to the Hwang-Lin merging algorithm, JACM, J. Assoc. Comput. Mach. 2.6 (1979). 434-440.

7. J. S. MONTING, Optimal merging of 4 or 5 elements with n elements, Theoret. Compur. Sci. 14 (1981), 19-37.

8. R. M. TANNER, Minimean merging and sorting: An algorithm, SIAM J. Comput. 7 (1978). 18-37.