UNIVERSITY OF ILLINOIS LIBRARY AT URBANA-CHAMPAIG.N CENTRAL CIRCULATION BOOKSTACKS The person charging this material is re- sponsible for its renewal or its return to the library from which it was borrowed on or before the Latest Date stamped below. You may be charged a minimum fee of $75.00 for each lost book. Theft, mutilation, and underlining of books are reasons for disciplinary action and may result in dismissal from the University. TO RENEW CALL TELEPHONE CENTER, 333-8400 UNIVERSITY OF ILLINOIS LIBRARY AT URBANA-CHAMPAIGN JfiN '■- lyjyjf When renewing by phone, write new due date below previous due date. L162 Cc>0 ^s. 7'fiZ* UIUCDCS-R-78-948 UILU-ENG 78 1740 ON THE COMPLEXITY OF EDGE LABELINGS FOR TREES BY S. Zaks and Y. Perl November 1978 * 'J i*5 DEPARTMENT OF COMPUTER SCIENCE UNIVERSITY OF ILLINOIS AT URBANA-CHAMPAIGN URBANA, ILLINOIS Univci&Hj - Digitized by the Internet Archive in 2013 http://archive.org/details/oncomplexityofed948zaks ON THE COMPLEXITY OF EDGE LABELINGS FOR TREES S. Zaks" and Y. Perl ' October 1978 : Department of Computer Science, University of Illinois at Urbana- Champaign, Urbana, Illinois 61801. The work of this author was supported in part by the National Science Foundation under grant NSF MCS 77-22830. ** On leave from the Department of Mathematics and Computer Science, Bar- I Ian University, Ramat-Gan, Israel. ABSTRACT Given a tree T with n edges and a set W of n weights, we deal with labelings of the edges of T with weights from W, optimizing certain objective functions. For some of these functions the optimization problem is shown to be NP-complete (e.g., finding a labeling with minimal diameter), m and for others we find polynomial-time algorithms (e.g., finding a labeling with minimal average distance). TABLE OF CONTENTS I. INTRODUCTION 1 II. RADIUS AND DIAMETER: NP-COMPLETE RESULTS 4 III. RADIUS: POLYNOMIAL RESULTS 9 IV. AVERAGE MEASUREMENTS: POLYNOMIAL RESULTS 13 V. OPEN PROBLEMS 20 Wl w I. INTRODUCTION 1 . 1 Definitions Lot T=(V,E) be a tree with vertices V={1 ,2,. . . ,n+l } and edqes E={e-| , e ? ,..., e }. A vertex of degree one is a leaf , and an edge incident th a leaf is a terminal edge . P denotes a path with n vertices. W={w,, w> is a set of weiqhts such that 0 , eep(i.j) eep(i.j) respectively. p(i,j) is the number of edges in p(i,j). is the average weight on p(i,j). 1 .2 The Objective Functions The quantities which we optimize, for a given tree T, over all possible labelings f, are the following: 1. D , 2. R , 3. SUMDIS(J) = z d(i,j) , 4. SUMMAX[J) KJ = I max(i,j) , 5. SUMMIN{T) = Z min(i,j) , and 6. sumavb(i) KJ = z avr(i,j) . The functions (3)-(6) are average measurements ,si nee the summations are over all pairs of vertices. 1 .3 Motivation This work is applicable in the design of communication networks. Given communication lines of different properties, such as communication cost, capacity, vulnerability and reliability, we want to assign these comm- unication lines to the direct connections ("edges") of a given communication network (of a tree structure), such that certain objective cost functions will be optimized. For example, the function SUMDIS is measuring the average communi- cation cost of the network (see [4] and [8]). The diameter is measuring the maximal communication cost in the network, and the radius is measuring the maximal communication cost from a directory optimally located in the network. Let c(e) and v(e) be the capacity and vulnerability of a communi- cation line assigned to the edge e, respectively. Define the capacity and vulnerability between the vertices i and j as c(i,j) = min (c(e)} and v(i,j) = max (v(e)} , eep(i.j) eep(i,j) respectively. Then the functions SUMMIT and SUMMAX measure the average capacity and vulnerability of the network, respectively. 1 .4 In section 2 we present several NP-complete problems, concerning optimizing the radius and the diameter of a tree and of a binary weighted (0,1 weights) general graph. Polynomial-time algorithms for special cases of minimizing the radius of a tree are shown in section 3. In section 4 we present polynomial -time algorithms for optimizing average measurement functions of the tree, such as SUMDIS and SUMMAX. Open problems are found in section 5. II. RADIUS AND DIAMETER: NP-COMPLETE RESULTS 2.1 In this section the following problems are shown to be NP-complete (see [6]): PROBLEM 1 : Given a tree T with n edges, a set W of n non-negative weights, and an integer k>0, to determine whether there exists a labeling f with diameter <_ k. PROBLEM 2 : Like PROBLEM 1, for radius < k. Note :! .This result holds also for rooted trees. 2. PROBLEMS 1 and 2 remain NP-complete when the weights are bounded PROBLEM 3 : Like PROBLEM 1, for radius > k. Note_:l. Maximizing the diameter of a tree is trivial. 2. PROBLEMS 1 , 2 and 3 are NP-complete also for the corresponding vertex labeling problems. PROBLEM 4 : Given a connected graph G with m edges and a set of 0,1 weights W, |W|=m, to determine whether there exists a labeling with radius <_ 1. PROBLEM 5 : Given a connected graph G with n+1 vertices and a set of 0,1 weights W, |W|=n, to determine whether G contains a spanning tree which can be labeled such that its diameter < 2. 2.2 The reductions are from the PARTITION problem and the MAXIMUM TERMINAL SPANNING TREE problem, both known to be NP-complete (see [6] and [2] ): PARTITION : Given positive integers a i , i=l,2,...,n, to determine whether there exists a set Ic{l ,2, . . . ,n} such that E a. = i a- . iel HI MAXIMUM TERMINAL SPANNING TREE : Given a graph G and an integer k>0, to determine whether G has a spanning tree with at least k terminals (=leaves). 2.3 Proof for PROBLEM 1 We show that PARTITION is reduced to PROBLEM 1. Given a., 1-1 ,2,..., n, (an instance of PARTITION), we define the following instance of PROBLEM 1: T : ~^ n edges *\^ W = {a-,, a«, ..., a. 0, 0, z. a.} . c. n v. ~, j n O's k " I Z i a i ' We prove that there exists a solution to the PARTITION problem iff there exists a labeling of T with diameter <_ k. Suppose there exists a solution to the PARTITION problem, namely z a. - z a. for some l£{l,2,...,n} . The following labeling has a iel n i*fl n diameter k: label AB with z. a. , spread the a.'s for iel and i^I on BC and BD, respectively, and label the rest of the edges with O's. Suppose there exists a labeling with diameter <_ k. One can find such a labeling in which za. labels the edge AB (if in the given labeling AB is labeled with a., for some t, and za. labels another edge e, then by interchanging za. and a. the diameter is not increased). This means that the a.'s on BC and on BD must sum up to j Za. each, hence we have a solution to the given PARTITION instance. □ 2.4 Proof for PROBLEM 2 We prove that PARTITION is reduced to PROBLEM 2. Given a. (as above), we define the following instance of PROBLEM 2: T ■ P 2n + 1 M = {a,, a,, ..., a„, 0, 0} , and k = lza n0 ' s k 2 za i . The rest follows immediately. rj Note : The same reduction holds in the case when this path is rooted in its center, which proves that PROBLEM 2 is NP-complete also for rooted trees. Note : As was pointed out by Dave Johnson [5], PROBLEM 1 and PROBLEM 2 remain NP-complete when the weights are bounded, and this is shown by a similar reduction from 3-PARTITION ( see [2]), ( "NP-complete in the strong sense" ). 2.5 Proof for PROBLEM 3 We prove that PARTITION is reduced to PROBLEM 3. Given a. (as above), we define the following instance of PROBLEM 3: T ' P n + 2 • W = {a-. , a«» . .. i a , x} where x>max {a.} , and k = x + p- «za. If there exists a solution to PARTITION then the labeling shown in figure 1 has a radius R = k. / a.'s for iel ^x a.'s for i^I Figure 1 If there exists a labeling with radius /?>_ x + j Ea., then let D be a center and DB a radius (see figure 2). Then d(D,B) >_ x + 1 za. , and hence d(A,D) <_ j la. . A D y C B • • • • • • • • • • • • Figure 2 Also d(D,B) <_d(A,C), otherwise D is not a center. Therefore x + \ sa -j 1 d(D,B) <_ d(A,C) < y + d(A,D) < y + j Za i , hence x0 (an instance of MAXIMUM TERMINAL SPANNING TREE), we define the following instance of PROBLEM 4: G is the same given graph and W contains n-k O's and all the rest l's. We prove that G has a spanning tree with at least k leaves iff G has a labeling with radius /?<_! . Suppose G has a spanning tree with at least k leaves. This yields a labeling of G with radius R<_ 1 , by labeling the internal edges (of the tree) with O's , and thus ewery internal vertex (of the tree) is a center for the graph G with radius i?_ k. □ 2.8 Proof for PROBLEM 5 The reduction is similar to that of PROBLEM 4. D 2.9 Conjecture The following problem is also NP-complete: given a connected graph and a set of 0,1 weights, to determine whether there exists a labeling with diameter D<\ . We have the following observations about this problem. Suppose the graph G is labeled with the given weights such that its diameter D<\ . It is clear that D=0 iff G contains a spanning tree with all edges labeled 0. Thus the interesting case is when D=1. In this case we may assume that the edges labeled with generate a forest in G, since if they generate any cycle we can replace one 0-edge with a 1-edge without increasing the diameter (putting this 0-edge in another arbitrary place not closing a cycle of 0's). Let T.= (V.,E.) S i=l,2,...,j be the trees in this forest. A graph G'=(V , ,E') is constructed from G by contructing (see [3] ) all the vertices of each tree T. , i = l,2,...j, into one vertex u • . It can be shown that G is labeled with a diameter z?=l iff G' is a complete graph. This observation lead us to the above conjecture. III. RADIUS: POLYNOMIAL RESULTS 3.1 In the previous section we proved that minimizing the diameter or the radius in a tree are NP-complete problems. Here we present polynomial -time algorithms for certain instances of these problems. 3.2 PROBLEM 6 : Given a tree T and a set of 0,1 weights W, to find a labeling with minimal radius. The following algorithm solves this problem in 0(n) running-time: Algorithm A 1. wh i 1 e (number of leaves in T) <_ (number of l's in W) do begin label all the terminal edges with 1 ; delete the terminal edges from T ; delete the used l's from W ; end ; 2. Put all the remaining l's on terminal edges ; label all other edges with 0's. Proof : Left to the reader. □ Note : Algorithm A is applicable also for rooted trees. 3.3 PROBLEM 7 : Like PROBLEM 6, for a set of a,b weights, a/?, where R is the radius of T' . Then the path from r to x contains an edge labeled with b in T and labeled with a in T' . Let (y,z) be the first such edge from the root r. On the other hand there exists an edge (u,v) labeled with b in T' and labeled with a in T. By the property of T all the edges in the subtree T' are labeled with b. Let w be a vertex in T' with maximal distance d'(r,w) . d'(r,w) R + (a-b) . Hence the algorithm should have labeled the edge (u,v) with b before labeling 12 the edge (y,z), a contradiction. Therefore the labeling of T is optimal. □ 3.4 PROBLEM 8 : Given a tree T and a set of 0,1 weights W, to find a labeling with minimal diameter. This is done in 0(n) running-time algorithm, identical to that of PROBLEM 6. 3.5 PROBLEM 9 : Like PROBLEM 8, for a bounded number of distinct weights. Also in this case the solution is polynomial. This is done in a dynamic programmwng technique, proposed by Nimrod Megiddo [9] , and is similar to the one described in the sequel (see PROBLEM 13, section 4.9). The details are left to the reader. 13 IV. AVERAGE MEASUREMENTS: POLYNOMIAL RESULTS 4.1 In this section we present polynomial -time algorithms for optimization problems concerning the functions SUMDIS , SUMAVR, SUMMIN and SUMMAX. 4.2 PROBLEM 10 : Given T and W, to find a labeling that maximizes or minimizes SUMDIS{1) = z d(i,j) . i f° r i=l ,2,... ,n, maximizes (minimizes) the function SUMDIS '(T) . The optimal labeling is unique up to permuting edges with equal connections. Assuming that all weights are distinct, the number N of optimal labelings satisfies 2 UJ < N < n! The bounds are achieved for the graphs P ,, and K-, 3 r n+1 i ,n The connections can be calculated in 0(n) time by regarding T as rooted and traversing it in post-order (see [6] ). Therefore, and because of the sorting step involved, the algorithm for optimal labeling (for either maximizing or minimizing SUMDIS{1) ) has O(nlogn) running-time. 14 4.3 PROBLEM 11 : Given T and W, to find a labeling that maximizes or minimizes SUMAVR{1) = z i J 9 N , . i<: j |p(i.j)| The solution is essentially similar to the solution of PROBLEM 19. The only change is that the connections c(e) are replaced by the average connection c(e) defined by c(e) = z c.(e)/j , J J where c.(e) is the number of paths of length j through the edge e. J Calculating the average connections is done by a breadth-first search (see [1] ) from every edge e, getting the number of paths of length i on each side of e (for every i), and then "merging" the information from both sides of e by convolution doable in O(nlogn) time (see [1] ). Therefore the algorithm in this case is of 0(n logn) time. 4.4 PROBLEM 12 : Given T and W, to find a labeling that minimizes SUMMAX{1) = I max(i ,j) . The problem of maximizing SUMMAX[J) is still open. Similarly, our algorithm for solving PROBLEM 12 solves also the problem of maximizing the function SUMMIN{1) , while the problem of minimizing SUMINiJ) is still open. Conjecture : The problem of maximizing (minimizing) SUMMAX(J) ( SUMMIN(l) ) is NP-hard. The algorithm to solve PROBLEM 12 is based on the following theorem: Theorem : Given T and W as above, and assuming w. < w. +1 for every i, we have: 1. In any labeling that minimizes SUMMAX(J) the largest weight w labels a terminal edge, n 3 2. For any terminal edge there exists an optimal labeling in which w labels this edge, n 3 3. min {SUMMAX f (J)} = ? i. w . (which means that this optimal 15 value is independent on the tree T). Note : The result holds also for the case <_ w, <_ ••• < w , and the modi- fication of the proof is left to the reader. Proof : We prove the theorem by induction on n. The theorem holds for n=l ,2 and 3 . Assume it holds for a tree with less than n edges. Let T be a tree with n edges. Assume f is a labeling that minimizes SUMMAX(1) , and that w labels a non-terminal edge e, thus partitioning T into two subtrees T, and Tp containing k and n+l-k vertices, respectively, for some 2 <_ k £n-l. Wlog we assume that w _, labels an edge in T, . Applying the inductive hypothesis to T, we know that there exists an optimal labeling for T, in which a specified terminal edge is labeled with w ,. We choose this edge to be such that by removing it with its corresponding leaf we won't disconnect T (see figure 4). k vertices n+l-k vertices Figure 4 Note that all the paths from vertices in T, , containing w , are not effected by this new labeling of T, (since on them w is maximal), and, as for T, , the value of SUMMAX is not changed by the inductive hypothesis. In the current labeling the contribution of w and w _, to SUMMAX(T) is k(n+l-k)w n + (k-l)w n _ 1 (1) By Interchanging w .j and w we get a labeling f in which their contribution is 16 nw n + (k-l)(n+l-k)w n _ 1 . (2) But substracting (1) from (2) gives (2) - (1) = (k-l)(n-k)(w n _ 1 - w n ) < because l x^l . (6) 18 We define a labeling f as follows: Art ~ I X -i "■" I Art Al-i X » f : a u ba ' ba ^b ••• ba r "'ba r (7) By (5) we have "<-«•(-':) (■•;)- <•> Using (5), (8) and (6) it can be shown that M f ,(a) < M f (a) , hence SUMMAX fl {J) > SUMMAxAl) , a contradiction. D Using this theorem it is clear how one should "spread" the a's among the b's in order to get a labeling that maximizes the function SUMMAX. 4.9 A Path, k Weights Here T=P + , , and W contains m. copies of w. for i = l,2,...,k, where m, + m ? + ••• + m. = n and w, > w ? > ••• > w, >_ 0. The following dynamic programming approach, proposed by Nimrod Megiddo [9] , solves the 2k+l problem in 0(n ). Let T be a path of length is. labeled with s. copies of w. for i=l,2,...,k, where the leftmost label is w and p. is the i a l position of the first occurrence of w. (from the left). Denote by ( s^, s 2 , ... , s k , w g , p-j, p 2 , ... , p k ) the maximal value for SUMMAX(T) . Note that p =1. a If there exists b such that p,=2 then *(s 1 ,...,s k ,w a ,p 1 ,...p k ) = max {(sl , . . . ,s a _ 1 ,s a -l ,s a+] , . . . ,s k ,w b ,p^ ,. . . ,p k ) + p a *(a) } where p! = p.-l for i^b and i^(a) is the contribution of the leftmost vertex 19 vertex to SUMMAX(T) } easily calculated using the p-'s. If there exists no such b then w labels the second edge too, and we compute by a