MDM _BSB& mm WwnHW Ji JBHI ■ m mmmmmm Hi I PfflfflHsBB HhHB mm BHtSKfffi? H Imkm gHEl H ■H aa v ^■■■J mmwmmmWBtmmmaBRi fu*5, WW BBS UE Bra HH H HEn B HH BfnSI Dal ■ nuH H llii HBrSZH BWn BBJ Hra R HHBBHCh nwitfftmiflnnffli B8I Ik raws H ■HI euraUHa H HI LIBRARY OF THE UNIVERSITY OF ILLINOIS AT URBANA-CHAMPAICN 510.84 IA6r no .679-681 cop. 2. The person charging this material is re- sponsible for its return to the library from which it was withdrawn on or before the Latest Date stamped below. Theft, mutilation, and underlining of books are reasons for disciplinary action and may result in dismissal from the University. UNIVERSITY OF ILLINOIS LIBRARY AT URBANA-CHAMPAIGN NOV 5 OCT 13 197? RECO JAN 2 3 L161 — O-1096 Digitized by the Internet Archive in 2013 http://archive.org/details/lowerboundsonmer680yaoa j~. , yijjCDCS-R-T^-68o s*f?VJL^l, LOWER BOUNDS ON MERGING NETWORKS by Andrew Chi- Chin Yao Foong Frances Yao October, I97U The Librarv "' JAN lMST5 ..viS uiucdcs-r-tH-680 LOWER BOUNDS ON MERGING NETWORKS Andrew Chi-Chih Yao Foong Frances Yao Department of Computer Science University of Illinois Urbana, Illinois 6l801 Research is supported by NSF GJ-U1538 ABSTRACT Let M(m,n) be the minimum number of comparators needed in an (m,n)- merging network. It is shown that M(m,n) 2 n(£g(m+l)) /2 , which implies that Batcher's merging networks are optimal up to a factor of 2 + e for almost all values of m and n. It is also proved that M(2,n) = [3n/2], and that r = lim M(m,n)/n exists, r is determined to within 1. m m n-x» 1. Introduction An (m,n) -merging network [2] is a network in which the input consists of two sorted sets {x n £ x_ £ •• • £ x } and {y n <: y_ <: •• • $ y }, and the id m id n output is the sorted set {z_ S z_ £ ••• £ z } with {z.'s} = {x.'s, y 's}. ^ 12 m+n i j k The network is built of comparators which are themselves (l ,l) -merging networks. A comparator is usually drawn as in Figure 1, and a merging network is shown in Figure 2. One can choose any input convention that specifies how the sequence {x.'s} are to be interspersed in the {y 's}. By standard technique [3], it can be shown that a transformation exists between any two such conventions which preserves the number of comparators used. Let M(m,n) be the minimum number of comparators needed in an (m,n)- merging network. The famous "odd-even merge" by Batcher [l] readily gives the following upper bound for M(m,n), which is also the best upper bound currently known. M(m,n) | AOB | . It follows that | A-B | $ \g |A| 1. However it is easy to see that |a| = n and |b| = n. (There are n internal nodes in a binary tree with n + 1 leaves.) Therefore |A-B| :> [n/2]. This leads to | aub| = | A-B | + |b| * [n/2l + n = f3n/2l. □ 3. Lover Bound for M(m,n) The upper bound on M(m,n) as given in equation (l) can "be rewritten as follows : M(m,n) £ (n + m)Ug(m + l) + constant)/2 for m <: n. (2) In this section we shall derive a lower bound, M(m,n) 5 nUg(m + l))/2 (3) By comparing (2) and (3), we see that for any e > 0, M(m,n) is determined to within a factor of 2 + e for all sufficiently large m and n. The rest of this section is devoted to a prcof of (3). In an (m,n)-merging network, we can look at the input set as a column vector with m + n components, and each comparator as a function which, given a vector, either transposes two of its components or does not change it. We shall assume that the input vector is a permutation of (l, 2, •••, m + n) and that the x.'s are inputs to the first m lines. Thus, if a network contains I comparators, appearing in sequence from left to right as a , a , '", a , then T any input vector V = (x , • • • , x , y , • • • , y ) is transformed into T (l, 2, •••, m + n) through a chain of vectors: a a a 1 2 ^ I T where V = (l, 2, ••*, m + n) . Now, a set of r different input vectors can be viewed as forming an (m + n) x r matrix. The a. 's can then be regarded, by their columnwise actions, as transformations on (m + n) x r matrices. We will choose r = m + 1, and consider the effect of the a.'s when the following input matrix A is given : A o = n + 1 \ 1 1 n + 2 n+2 ^ 2 n+3 n+3 n + 3 n + m 1 2 n + m 2 3 n + m 3 1+ 1 2 3 1 2 3 • m m + 1 m + 2 n + 1 n + 2 m + n In the i-th column of A , the upper part is the ordered list of length m, (l, 2, '•', i - 1, n + i, n + i + 1, • • * , n + m) , and the lower part is the ordered list of length n, (i, i+1, •••, n + i - l). Let a a A — ^ A l ~ ^ A 2 Z » A. (10 be the sequence of transformations that A undergoes in an (m,n) -merging network , where \ • \ m + n m *. To derive a lower "bound on I , the number of comparators in the network, we define an entropy function: Definition h Given a vector v = (a_ 5 a,_ , •••, a J _.) where 1 d m+1 1 <: a <: m + n for all k, we define p. = |{k|a = i}| for 1 S i < m + n, and m+n E(v) = i | 1 p. Jig p. (if p. = 0, then p. lg p. is taken to be 0.) Definition 5 For the matrices A, (0 £ h <: i) defined in (h) , let m+n E( V " J £ 1 E < v j ) where v. is the j-th row vector of A, . m Lemma 6 E ( A Q ) = 2 -^ J ^ J (5) and E(A ) = (m + n) ■ (m + l)£g(m + l) (6) Proof In A , only the first m row vectors have non-zero entropies. For 1 $ j £ m, the j-th row vector of A has entropy j Jig j + (m + 1 - j )Jlg(m + 1 - j ) , hence (5) follows. Equation (6) is true because every row vector of A has entropy (m + l)Jlg(m + l). \_j For each h , A n and A n _ differ in at most two rows , thus the difference h h-1 in their entropies is bounded as implied by the following lemma. Lemma 7 Let v and v' be two vectors satisfying the conditions of Definition k, and let w and w' be obtained from v and v' by exchanging certain corresponding components. Then E(w) + E(w') £ E(v) + E(v') + 2(m + l) Proof Let p., p.', q. , q. ' denote the number of i's appearing in i l ' i l v, v', w, w' respectively. Then p. + p. ' =q. + Q. ' i = 1, 2, • • • , m + n l ill 10 Hence E(w) + E(w') - E(v) - E(v' ) = 2 q ± ig q i + 2 q i » Hg q. 1 - Z ? ± Ig v ± - Z v ± ' ig p.' i i i i v< 2 (q t + a i f )Ag(q i + q i ') - Z P; . £g Pi - E p ± ' Jig n(Jlg(m + l))/2 Proof By Lemma 6, m E(A Q ) = 2 ^ J JLg j <: m(m + l) Jig m. Thus E(A ) - E(A ) 5 (m + n)(m + l)Jlg(m + l) - m(m + l) Jig m $ n(m + l)£g(m + l) . On the other hand, Lemma 7 implies that E(A h ) - E(A _ ) £ 2(m +1) for 1 $ h $ I. 11 It follows that , „ n(m + l)&g(m + l) _ n&g(m + l) * S 2(m + 1) " 2 where il is the number of comparators in any (m,n) -merging network. 12 h. Asymptotic Behavior of M(m,n) In this section, we study the asymptotic behavior of M(m,n) for fixed m. Theorem 9 For any fixed m, lim M(m,n)/n exists. n-*° To prove Theorem 9> we shall make use of the following lemma. Lemma 10 M(m,n)/n < M(m,n )/n + mn /n for n < n. Proof Divide the inputs {y £ y £ ••• $ y } into groups S., , S^, •••, S r , i where each group, except maybe the last one, contains 1 2 I n/n n I n n elements (Figure 5). Let S contain the largest n elements, S contain the next largest n elements, etc. We can then construct an (m,n)-merging network by first merging the m elements on top with S . After that the largest n elements in the inputs are picked out at the bottom n lines. We then merge the top m elements with S~ , and so on. This implies M(m,n) < rn/n "lM(m, n Q ) $ (n/n Q )M(m, n Q ) + M(m, n Q ) Since it is clear that M(m, n ) < m n , the lemma is proved. As a consequence of Lemma 10, we obtain the following corollary. Corollary 11 M(m,n)/n <: M(m,n)/n + e(n) for fixed m, n , where e(n) -> as n -*■ °°. def Proof of Theorem 9 For fixed m, let us write R (n) = M(m,n)/n. m Since R (n) is bounded from below (say by 0), we can consider L = lim inf R (n). m m n-*» We will show that R (n) actually converges to L. m For any 6 > 0, choose an n such that R (n n ) * L + 6 m 13 m '[n/n Q l 1 n-n Q +l n Figure 5. An (m,n) -merging network built of (m,n) -merging networks. lU By Corollary 11, R (n) $ R (n_) + e(n) (8) m m <: L + 6 + e(n) for all n > n , where e(n) -*■ as n ■*■ °°. But (8) implies that lim sup R (n) £ L. m n-x» Therefore L = lim R (n). This proves the theorem. m n-H» Theorem 12 Let r = lim M(m,n)/m. Then m Ug(m + l))/2 S r m < Ug ml/2 + m/2^ g ml (9) Proof This follows from Theorem 8 and (l). Straightforward calculation will show that the difference between the upper bound and the lower bound for r in (9) is less than 1. m 15 CONCLUSION We have shown that Batcher's (m,n) -merging network is in general optimal up to a constant factor. And at least in one non-trivial case (m = 2) , we have shown that Batcher's merging network is in fact the best possible. It will be interesting to see whether Batcher's merging network is optimal for more cases; in particular, when m = 3. 16 REFERENCES [l] Batcher, K. E. , Sorting Networks and Their Applications, Proc. AFIPS Spring Joint Comp. Conf . , 32, 307-31 1 *. [2] Knuth, D. E. , The Art of Computer Programming, Vol. 3, pp. 220-233. [3] Knuth, D. E., The Art of Computer Programming, Vol. 3, p. 239, Exercise l6, JIBLIOGRAPHIC DATA iHEET 1. Report No. uiucdcs-r-T 1 +-68o Title and Subtitle LOWER BOUNDS ON MERGING NETWORKS Author(s) Andrew Chi-Chih Yao, Foong Frances Yao Performing Organization Name and Address University of Illinois Department of Computer Science Urbana, Illinois 61801 2. Sponsoring Organization Name and Address National Science Foundation 1800 G Street, N.W. Washington, D.C. 20550 3. Recipient's Accession No. 5. Report Date October, 197^ 8. Performing Organization Rept. No. 10. Project/Task/Work Unit No. 11. Contract /Grant No. NSF GJ-U1538 13. TyP e °f Report & Period Covered 14. 15. Supplementary Notes 6. Abstracts Let M(m,n) be the minimum number of comparators needed in an (m,n)- merging network. It is shown that M(m,n) 5 nUg(m+l))/2, which implies that Batcher's merging networks are optimal up to a factor of 2 + e for almost all values of m and n. It is also proved that M(2,n) = [3n/2], and that r = lim M(m,n)/n exists, r is determined to within 1. m m n -x» 17. Key Words and Document Analysis. 17a. Descriptors Merging network, comparator 17b. Identifiers /Open-Ended Terms 17e. COSAT1 Field/Group 18. Availability Statement Unlimited FORM NTIS-35 (10-70) 19. Security Class (This Report) UNCLASSIFIED 20. Security Class (This Page UNCLASSIFIED 21. No. of Pages 20 22. Price USCOMM-DC 40329-P7I CO en to a. CO Hi HI ' ; " i>i£ RUffli (§■ Kg UNIVERSITY OF ILLINOIS URB ANA 510 84 I16R no C002 no 679 164(1174 Rtporl / 3 0112 088401515 H SDHM twit ■ ■ ■ ■ ■ * H H I I I - 1 H ■ ■ iH H BH hrb n ■ H9 m w Hi Bi nl Smffl Bbbhb