2 Department of Applied Mathematics and Physics, Graduate School of Informatics, ... in the definition. If is a rooted t
FPTASβs for Trimming Weighted Trees
β
Mingyu Xiao1 , Takuro Fukunaga2 , and Hiroshi Nagamochi2 1 2
School of Computer Science and Engineering, University of Electronic Science and Technology of China, China,
[email protected] Department of Applied Mathematics and Physics, Graduate School of Informatics, Kyoto University, Japan, {takuro,nag}@amp.i.kyoto-u.ac.jp
Abstract. Given a tree with nonnegative edge cost and nonnegative vertex weight, and a number π β₯ 0, we consider the following four cut problems: cutting vertices of weight at most or at least π from the tree by deleting some edges such that the remaining part of the graph is still a tree and the total cost of the edges being deleted is minimized or maximized. The MinMstCut problem (cut vertices of weight at most π and minimize the total cost of the edges being deleted) can be solved in linear time and space and the other three problems are NP-hard. In this paper, we design an π(ππ/π)-time π(π2 /π + π)-space algorithm for MaxMstCut, and π(ππ(1/π + log π))-time π(π2 /π + π)-space algorithms for the other two problems, MinLstCut and MaxLstCut, where π is the number of vertices in the tree, π the number of leaves, and π > 0 the prescribed error bound. Key words.
1
Graph Cut, FPTAS, Tree, Tree Knapsack
Introduction
Given an undirected tree πΊ = (π, πΈ) with a nonnegative vertex weight π€(π£), π£ β π and a nonnegative edge cost π(π), π β πΈ, and a nonnegative number π β₯ 0, the maximum cutting vertices of weight at most π problem (MaxMstCut) is to ο¬nd a nonempty and proper subset π of π that maximizes the total cost of edges with exact one endpoint in π under the constraint that (i) the subgraph πΊ[π βπ] induced by π β π is connected and (ii) the total weight of vertices in π is at most π. Analogously, we also deο¬ne MaxLstCut, MinMstCut and MinLstCut, by replacing βmaximizesβ with βminimizesβ or replacing βat mostβ with βat leastβ in the deο¬nition. If πΊ is a rooted tree, then we impose the third constraint that the root is contained in the subgraph πΊ[π β π] in ο¬nding a solution π. These problems are also called the cutting π vertices (or vertices of weight π) problem in some references. In this paper, we mainly study algorithms for the above four cut problems in rooted and unrooted trees. In our algorithms, we may compute a solution π β π by identifying the corresponding set πΆ = πΈ(π, π β π) of edges joining π and π β π, called cut set. β
A preliminary version of this paper was presented in the 4th international frontiers of algorithmics workshop (FAW 2010) and appeared in [15].
2
Mingyu Xiao, Takuro Fukunaga, and Hiroshi Nagamochi
Graph cut problems have great applications and have been extensively studied in the literature. The minimum cut problem is regarded as a basic problem among this kind of problems. Many extensions of the classical minimum cut problem, including the multi-way cut problem [3, 13], the balanced cut problem [5] and the cutting π vertices problem [4], are also important and fundamental problems. The multi-way cut problem extends the minimum cut problem in a way of partitioning the graph into more than two components. The balanced cut and cutting π vertices problems are to ο¬nd an optimal cut under some constraints on the size of the two parts of the cut. These two problems have similar requirement. However, the balanced cut problem is to deal with the case of almost balanced sizes of the two sides of the cut, while the cutting π vertices problem is more to consider cuts with one small side. Although the minimum cut problem can be solved in polynomial time by ο¬ow and other techniques, most extended cut problems are NP-hard. Few βpositiveβ results on the cutting π vertices problem are known. Considering the hardness of the problems, we study the four cut problems MaxMstCut, MaxLstCut, MinMstCut and MinLstCut in the graphs restricted to trees. These problems in trees are still important to be investigated, since they naturally generate the famous knapsack problem from several ways. In fact, the cut problems in rooted trees are related to some special cases of the precedence constraint knapsack problem (PCKP) [7, 9]. In PCKP, a directed acyclic graph is given, each vertex in the graph is regarded as an item to be selected into the knapsack, and if a vertex is selected into the knapsack then all its ancestors (vertices having a direct path to the vertex) must also be selected into the knapsack. MaxMstCut (resp., MinLstCut) can model the precedence constraint knapsack problem in rooted trees with all edges directed toward the root (resp., the leaves), which is called the in-tree (resp., out-tree) knapsack problems [2, 7]. As a prior work on MinLstCut in rooted trees, there exists a (4/3 + π)approximation algorithm for the generalized partial totally unimodular cover problem with any π > 0, presented by KΒ¨onemann, Parekh and Segev [10]. Consider the matrix, whose rows are corresponding to the vertices and columns corresponding to the edges, such that its (π, π)-th component is 1 if the π-th vertex is a descendant of the π-th edge, and 0 otherwise. If we order the vertices by DFS, then 1βs appear consecutively in each column. Such a matrix is known to be totally unimodular. Although we do not give a formulation of the partial totally unimodular cover problem, this observation indicates that MinLstCut is contained by their problem. Another related work is the algorithms for the tree knapsack problems. Cho and Shaw presented a depth-ο¬rst dynamic programming algorithm for the out-tree knapsack problem in [2] that can be modiο¬ed to get an π(π(π β π))-time pseudo polynomial-time algorithm for MinLstCut in rooted trees, where π is the total weight of all vertices in the tree. This pseudo polynomial-time algorithm can also be used to derive approximation schemes, but the running time depends on π . Johnson and Niemi [7] designed several algorithms for two diο¬erent tree knapsack problems. Their π(π3 /π)-time FPTAS (fully polynomial-time approximation scheme) for the in-tree knapsack problem
FPTASβs for Trimming Weighted Trees
3
can solve MaxMstCut in rooted trees in the same time. There are few nontrivial results on the problems in unrooted trees. In this paper, except showing that MinMstCut in trees can be solved in linear time and space easily, we present: (i) π(ππ/π)-time π(π2 /π + π)-space FPTASβs for MaxMstCut in rooted and unrooted trees; (ii) π(ππ(1/π + log π))-time π(π2 /π + π)-space FPTASβs for MinLstCut and MaxLstCut in rooted and unrooted trees. The rest of the paper is organized as follows. Section 2 gives our notation system. Section 3 considers the hardness of the problems. Section 4 presents pseudo polynomial-time algorithms that will be used to design FPTASβs. Section 5 presents FPTAS for MaxMstCut in rooted trees and Section 6 presents FPTASβs for MinLstCut and MaxLstCut in rooted trees. Section 7 designs FPTASβs for MaxMstCut, MinLstCut and MaxLstCut in unrooted trees. Finally Section 8 makes some concluding remarks.
2
Preliminaries
Let β+ denote the set of positive reals, and let ββ = β+ βͺ {0}. We may denote by π (πΊ) and πΈ(πΊ) the sets of vertices and edges of an undirected graph πΊ, respectively. For a graph πΊ = (π, πΈ) and a subset π β π , let πΊ[π] denote the subgraph of πΊ induced by the vertices in π, and let πΈ(π, π β π) denote the set of edges with one endpoint in π and the other in π β π. For β a vertex weight π€ : π β ββ β and an edge cost π : πΈ β ββ , let π€(π) denote π£βπ π€(π£) and π(π) denote πβπΈ(π,π βπ) π(π), respectively. Given an unrooted tree πΊ and a vertex π in it, we use πΊπ to denote the rooted tree obtained from πΊ by choosing π as the root. In a rooted tree, let π·(π£) (resp., π΄(π£)) denote the set of descendants (resp., ancestors) of a vertex π£, where π£ β π·(π£) and π£ β π΄(π£). Denote the edge sets in the induced graphs πΊ[π·(π£)] and πΊ[π΄(π£)] by πΈπ· (π£) and πΈπ΄ (π£), respectively. Let ππ (π£) denote the edge joining π£ and its parent. For each edge π = (π’, π£), where π’ is the parent of π£, deο¬ne π·(π) and πΈπ· (π) to be π·(π£) and πΈπ· (π£), respectively. A set π is called root-connecting if πΊ[π β π] is connected and contains the root. We use π and π to denote the number of vertices and the number of leaves (i.e., vertices of degree 1) in the graph respectively. To distinguish edge weight with vertex weight, we say edge cost instead of edge weight. A special case of our cut problems is that the weight of vertices in the graph can only be 0 or 1. We will call the problems under this constraint the terminal case. We may call vertices π£ with π€(π£) = 1 terminals, and use π to denote the set of terminals in the graph and let π‘ = β£π β£.
3 3.1
Computational Complexity In General Graphs
First, we study the hardness of our cut problems in general graphs. We consider the terminal case of the problems in nonnegative edge-cost graphs without the
4
Mingyu Xiao, Takuro Fukunaga, and Hiroshi Nagamochi
constraint (i) on the connectivity of πΊ[π β π], where we can assume that given graphs are complete by introducing a new edge with cost 0 to each pair of nonadjacent vertices. Thus we treat our problems in complete graphs. For terminal cases, it may also be interesting to study the exact version of the problems: cutting exact π terminals away from the graph by minimizing (maximizing) the cost of the cut. We use MinExtCut and MaxExtCut to denote these two problems. They will also be considered later. Since the maximum cut problem is a well-known NP-hard problem, we know that terminal MaxMstCut, MaxLstCut and MaxExtCut are NP-hard. We will pay more attention to the minimum version of the problems. In both terminal MinMstCut and MinLstCut, the target π should be less than β£π β£/2, otherwise it is no meaning to distinguish them. It is easy to see that when π is a constant, terminal MinMstCut, MinLstCut and MinExtCut are polynomial-time solvable as we can exhaustively search for all π (or at most π)-terminal groups (For MinLstCut, we will ο¬nd a minimum cut in each graph obtained by contracting a π-terminal group into a single terminal). When π is part of input, it is also easy to show the NP-hardness of terminal MinExtCut by reducing from the balanced cut problem [1]. Marx [11] also studied the hardness of terminal MinExtCut from the Parameterized Complexity view. He proved that the problem is W[1]-hard, even when both π and size of the corresponding cut set are taken as parameters, which shows the corresponding parameterized problem unlikely has any parameterized algorithm. Terminal MinExtCut remains NP-hard even if π β€ β£π β£/2, and this implies that terminal MinLstCut is NP-hard, because a terminal MinExtCut instance with π β€ β£π β£/2 can be polynomially reduced to a terminal MinLstCut instance by adding heavy edges between every two terminals so that any optimal solution of the terminal MinLstCut instance cuts exactly π vertices away from the root. On the other hand, (terminal) MinMstCut is polynomially solvable by using an algorithm due to Nagamochi [12] for computing families of extreme sets (see Appendix A). 3.2
In Weighted Trees
Since the cut problems in general graphs are hard, we pay more attention to the scenarios where the graph is a tree. For the terminal case of the problems in trees, they can be solved in polynomial time by using dynamic programming (see Section 4). When vertex weight is nonnegative real number, MinLstCut and MaxMstCut in stars (trees having at most one vertex of degree > 1) are equal to the classical knapsack problem (each leaf in the star is corresponding to an item in the knapsack problem). For the hardness of MaxLstCut, we reduce another well-known NP-hard problem, the subset sum problem, to it. The subset sum problem is a special case of the knapsack problem, in which the proο¬t of each item is equivalent to the weight of the item. Given a subset sum instance (π€(1), π€(2), . . . , π€(π), β) with π items, where π€(π) is the weight of item π and β is the capacity of the knapsack, we construct a tree π with 2π + 1 vertices in this way: Each item π in the subset sum problem is corresponding to two vertices ππ
FPTASβs for Trimming Weighted Trees
5
and ππ in the tree. The weight of ππ is 0 and the weight of ππ is π€(π). There is also an auxiliary vertex π£ with weight 0 in π . There is an edge between ππ and ππ with cost π€(π) and an edge between ππ and π£ with cost 0. The target π in the tree is set to be π β β, where π is the total weight of items. Note that the cut set corresponding to an optimal solution to MaxLstCut in π will contain exact one edge in {ππ ππ , ππ π£} for each π. Then if item π is selected into the knapsack, we include edge ππ ππ into the cut set. Otherwise, we include edge ππ π£ into the cut set. For each optimal solution to MaxLstCut we can also construct a solution to the knapsack problem. Therefore, we can prove the correctness of this reduction. MinMstCut is polynomial-time solvable in general graphs even without the constraint on the vertex weight. We further show that the problem can be solved in linear time when the graph is restricted to a tree. Note that the edge cost and vertex weight are nonnegative. The cut set corresponding to an optimal solution only contains one edge. We only need to identify a feasible edge with minimum cost. An edge π in a rooted tree is a feasible edge if π€(π·(π)) β€ π, and an edge π in an unrooted tree is a feasible edge if at least one of the two component of πΊ β π is of total vertex weight β€ π. We can ο¬nd all feasible edges in a DFS (For an unrooted tree, we arbitrarily select a vertex as the root and consider if min{π€(π·(π£)), π β π€(π·(π£))} β€ π for each vertex π£). In the DFS, we only need to remember the feasible edge with minimum cost among all visited edges. Therefore, we can solve the problem in linear time and space. We will not discuss MinMstCut in the rest of the paper.
4
Pseudo Polynomial-time Algorithms
In this section, we give dynamic programming algorithms for our problems in rooted trees, which are pseudo polynomial-time algorithms and will be used to derive FPTASβs. One technique we used to design the dynamic programming algorithms is called the βleft-rightβ method for trees in [7]. To get the pseudo polynomial-time algorithms, we assume that all edge cost are integers in this section. In fact, our algorithm will ο¬nd an optimal solution π only when π(π) β€ π holds for a prescribed threshold π. We order all the leaves in the tree according to a DFS (ο¬rst visited has small index). Let πΏ = {π§1 , π§2 , . . . , π§π }, π = β£πΏβ£, be the set of leaves, where leaves π§1 , π§2 , . . . , π§π appear from left to right in this order (see Fig. 1 for an illustration). To construct a root-connecting set π, if a vertex π£ does not belong to π (i.e., π£ is not allowed to be cut away from the rooted tree), then all the edges in the path from π£ to the root are not allowed to be deleted. Let π β² be the set of non-root vertices in the tree. For 0 β€ π β€ π and 0 β€ π β€ π, deο¬ne π³ (π, π) to be the set of all root-connecting sets π β π β² that satisfy two constraints: πΏ β© π β {π§1 , π§2 , . . . , π§π } (only the ο¬rst π leaves are allowed to be cut away); and π(π) = π. We set { min{π€(π) β£ π β π³ (π, π)} for MaxMstCut ππ π (π, π) = max{π€(π) β£ π β π³ (π, π)} for MaxLstCut and MinLstCut.
6
Mingyu Xiao, Takuro Fukunaga, and Hiroshi Nagamochi root
e
z1
...... P
z2 z3 z4 Ξ± (e) = 3
Pi
i β1
zi β2
...... zi β1
zi
Fig. 1. An illustration of the rooted tree in our DP algorithm
Let π(π, π) store a set π β π³ (π, π) attaining π€(π) = ππ π (π, π), where we let π(π, π) =β₯ and ππ π (π, π) = β if π³ (π, π) = β
. Clearly for the maximum integer π0 such that ππ π (π, π0 ) β€ π, π(π, π0 ) is an optimal solution to MaxMstCut. Similarly for the maximum (resp., minimum) integer π0 such that ππ π (π, π0 ) β₯ π, π(π, π0 ) is an optimal solution to MaxLstCut (resp., MinLstCut). We maintain a table of size (π + 1) Γ (π + 1) to store ππ π (π, π) and π(π, π) for 0 β€ π β€ π and 0 β€ π β€ π. To get a recursive formula among these, we consider a partition of the edge set πΈ into π subsets ππ = πΈπ΄ (π§π ) β πΈπ΄ (π§π+1 ), π = 1, 2, . . . , π, where we regard πΈπ΄ (π§π+1 ) as β
. Note that ππ is the set of edges π such that deleting π cuts π§π away without cutting π§π+1 away (see Fig. 1 for an illustration of ππ ). Then, for any edge π β ππ , deleting π cuts away leaves π§π , π§π+1 , . . . , π§π with consecutive indices. Let πΌ(π) be the smallest index π of the leaves in π (π). Then all values ππ π (π, π) and π(π, π) for MaxMstCut can be computed by the recursive formula in Fig. 2. Algorithm DP for MaxLstCut and MinLstCut can be obtained by replacing the if condition in Step 2 with ππ π (πΌ(π)β1, π β π(π)) + π€(π) > ππ π (π, π) and modifying the choice of π0 in Step 3. Lemma 1. For a rooted tree πΊ with nonnegative integer edge cost and nonnegative vertex weight, Algorithm DP(πΊ, π, π) can be implemented to run in π(ππ) time and π(ππ + π) space. Each iteration for an edge π β ππ in the fourth line of Step 2 can be executed in π(1) time by representing π = π(π, π) as the edge set πΈ(π, π β π) and updating πΈ(π, π β π) by adding the edge π. Since {ππ β£ π = 1, 2, . . . , π} is a partition of the edge set πΈ, each edge is considered only once for each ο¬xed π in the algorithm. Since π runs from 1 to π, the running time of the algorithm is π(ππ). The space of the algorithm is π(ππ + π). Since DP(πΊ, π, π) only computes ππ π (π, π) for π from 0 to π, when the cost of an optimal solution is greater than π, DP(πΊ, π, π) cannot ο¬nd an optimal solution.
FPTASβs for Trimming Weighted Trees
7
Algorithm DP(πΊ, π, π) Input: A tree πΊ = (π, πΈ) rooted at a vertex π with nonnegative integer edge cost π and nonnegative vertex weight π€, a number π β₯ 0, and an integer π β₯ 0. Output: A maximum cost root-connecting set π such that π€(π) β€ π and π(π) β€ π, if any, or β₯ otherwise. 1. For π = 1 to π, do ππ π (0, π) ββ β and π(0, π) βββ₯. For π = 0 to π, do ππ π (π, 0) ββ 0 and π(π, 0) ββ β
. 2. For π = 1 to π, do For π = 1 to π, do ππ π (π, π) ββ ππ π (π β 1, π) and π(π, π) ββ π(π β 1, π). For each π β ππ with π(π) β€ π, do If ππ π (πΌ(π)β1, π β π(π)) + π€(π) < ππ π (π, π), then ππ π (π, π) ββ ππ π (πΌ(π)β1, π β π(π)) + π€(π·(π)) and π(π, π) ββ π(πΌ(π)β1, π β π(π)) βͺ π·(π). 3. Let π0 be the maximum integer such that ππ π (π, π0 ) β€ π. 4. Return π(π, π0 ). Fig. 2. Algorithm DP(πΊ, π, π) for MaxMstCut
Note that the recursion in Fig. 2 can be rewritten to do over vertex weight instead of edge cost by maintaining a table of size (π + 1) Γ (π + 1) to store ππ π β² (π, π) (and also π β² (π, π)) for 0 β€ π β€ π and 0 β€ π β€ π, where ππ π β² (π, π) = max{π(π) β£ π β π³ β² (π, π)} and π³ β² (π, π) is the set of all root-connecting sets π β π β² that satisfy two constraints: πΏ β© π β {π§1 , π§2 , . . . , π§π } and π€(π) = π. Then we can get running time bound π(ππ) time and space bound π(ππ + π) for the modiο¬ed algorithm (We also need to assume that all vertex weight are integers for this case). This also implies that the terminal case of our cut problems can be solved in π(ππ) time and π(ππ + π) space.
5
FPTAS for MaxMstCut in Rooted Trees
First, we consider MaxMstCut in rooted trees and then extend our results to the problem in unrooted trees in Section 7. 5.1
Preprocesses
We show some conditions on edges that can be ruled out from a given instance of MaxMstCut. An edge π is called an overload edge if π€(π·(π)) > π, i.e., the total weight of vertices cut away from the tree by deleting it exceeds π. Clearly, we can simply contract all overload edges to form the new rooted tree. A non-leaf edge π is called a dominated edge if π(π) is not larger than the total of π(πβ² ) of the child-edges πβ² of π (i.e., the edges in πΈπ· (π) adjacent to π). Thus, for any rootconnecting set π with a dominated edge π = (π’, π£) β πΈ(π, π βπ), where π£ β π, π β² = π β {π£} satisο¬es π(π β² ) β₯ π(π) and π€(π β² ) β€ π€(π) by nonnegativeness
8
Mingyu Xiao, Takuro Fukunaga, and Hiroshi Nagamochi
of π and π€, indicating that there is an optimal solution π β to MaxMstCut such that π ββ πΈ(π, π β π). Hence we can also safely contract all dominated edges. This can be done in a bottom-up manner from leaves toward the root in linear time. Observe that, in a rooted tree with no dominated edges, for each non-root vertex π£, π·(π£) has the maximum cut cost π(π·(π£)) over all root-connecting sets π β π·(π£). 5.2
A
1 -Approximation 3
Algorithm
To design our FPTAS for MaxMstCut, we ο¬rst give an π(π log π)-time 13 -approximation algorithm. The idea of the algorithm comes from a well-known greedy approximation algorithm for the knapsack problem, which is to greedily select items of the most dense. For each non-root vertex π£ with π·(π£) > 0, the density of π£ is deο¬ned to be π(π£) = π(π)/π€(π·(π£)), where π = ππ (π£). The simple approximation algorithm is presented in Fig. 3, where through out the computation, we use the density π(π£) of vertices π£ in the graph obtained in Step 1, and never recompute new densities even after ο¬xing some vertices as part of the current root-connecting set π .
Algorithm Appro(πΊ, π) Input: A rooted tree πΊ = (π, πΈ) with nonnegative edge cost π : πΈ β ββ and nonnegative vertex weight π€ : π β ββ and a number π > 0. Output: A 13 -approximation solution to MaxMstCut in πΊ. 1. Contract all overload and dominated edges. Let π β² be the set of non-root vertices in the resulting tree. Compute the density π. 2. π ββ the union of sets π·(π£) with π€(π·(π£)) = 0 and π£ β π β² . 3. While π β² β π β= β
, do Select π£ β π β² βπ such that π(π£) is maximized (possibly π β©π·(π£) β= β
). If π€(π βͺ π·(π£)) β€ π, then π ββ π βͺ π·(π£). Else return one of π and π·(π£) that attains max{π(π ), π(π·(π£))}, and halt. 4. Return π . Fig. 3. Algorithm Appro(πΊ, π)
Lemma 2. Algorithm Appro(πΊ, π) is an π(π log π)-time 13 -approximation algorithm for MaxMstCut in rooted trees with nonnegative edge cost and nonnegative vertex weight. Proof. Since we have contracted all dominated edges, we know that there is an optimal root-connecting set π β contains all sets π·(π£) with π€(π·(π£)) = 0 in the tree. Then we can simply put them into the solution set directly. Next, if the algorithm stops at Step 4, it will return an optimal solution π = π β² , since π(π β² ) attains the maximum cut cost π(π) over all root-connecting sets π.
FPTASβs for Trimming Weighted Trees
9
Otherwise the algorithm will return π or π·(π£ β² ) in Step 3, where π£ β² is the last vertex being selected in the algorithm. Note that π·(π£ β² ) is excluded from π in the algorithm. Thus π is a feasible solution when the algorithm halts. π·(π£ β² ) is also a feasible solution, because all overload edges are contracted in Step 1. Assume that π β is an optimal solution. We partition π and π β into disjoint subsets: π = π·(π£1 )βͺπ·(π£2 )βͺβ
β
β
βͺπ·(π£π¦ ) and π β = π·(π’1 )βͺπ·(π’2 )βͺβ
β
β
βͺπ·(π’π₯ ), where π£π is not a descendent of any vertex in π β{π£π } and π’π is not a descendent of any vertex in π β β {π’π }. We further assume that {π£1 , . . . , π£π¦ } β© {π’1 , . . . , π’π₯ } = {π’1 , . . . , π’β }. Let π1 = π·(π’1 ) βͺ π·(π’2 ) βͺ β
β
β
βͺ π·(π’β ) and π2 = π β β π1 = π·(π’β+1 ) βͺ β
β
β
βͺ π·(π’π₯ ). Obviously, π1 β π and π1 is still a feasible solution. By the nonnegativeness of π, π(π ) β₯ π(π1 ). Since at the time when the algorithm selects π£ β² , no vertex in {π’β+1 , . . . , π’π₯ } has been selected by the greedy strategy, we know that π(π£π ) β₯ π(π£ β² ) β₯ π(π’π ) holds for any π = 1, . . . , π¦ and π = β + 1, . . . , π₯. Since π€(π βͺ π·(π£ β² )) > π β₯ π€(π2 ), this implies that π(π βͺ π·(π£ β² )) > π(π2 ). Hence we have π(π β ) = π(π1 ) + π(π2 ) β€ π(π ) + π(π βͺ π·(π£ β² )) β€ 2π(π ) + π(π·(π£ β² )). Therefore, one of π(π ) and π(π·(π£ β² )) must have cost at least 31 π(π β ). As for the running time, we only need to show that Step 3 can be done in π(π log π) time. First of all, we compute the densities of all vertices in the tree in a DFS. If a vertex π£ has an ancestor π’ such that π(π£) < π(π’), we say that π£ is a weak vertex and ππ (π£) a weak edge. Note that the algorithm will never select a weak vertex in Step 3. We can reduce the tree by contracting all weak edges. Detecting and contracting all weak edges can be done in a DFS. After reducing the tree, the tree has the monotonicity property: on any path from the root to a leaf, the vertex densities give a nonincreasing sequence. Then we can sort all the vertices according to their densities in π(π log π) time as we do in Mergesort. After sorting the vertices, we only need to select vertices according to the sorting list. Then we can do Step 3 in π(π log π) time. Note. This greedy algorithm can get approximation ratio 12 for the knapsack problem. Note that when the graph is a star, in the above proof we will have that π(π2 ) β€ π(π βͺ{π£ β² }βπ1 ) (since π€(π βͺ{π£ β² }βπ1 ) > π βπ€(π1 ) β₯ π€(π2 ) and π(π£π ) β₯ π(π£ β² ) β₯ π(π’π ) for any π = 1, . . . , π¦ and π = β + 1, . . . , π₯). Then π(π β ) = π(π1 )+π(π2 ) β€ π(π )+π({π£ β² }). At least one of π(π ) and π({π£ β² }) must have cost at least 12 π(π β ). Ibarra and Kim [6] also introduced an π(π2 )-time 21 -approximation algorithm for MaxMstCut in rooted trees. In their algorithm, they will update the densities of vertices when each time selecting a vertex of maximum density and deleting it from the tree.3 We will use our 31 -approximation algorithm instead of their 12 -approximation algorithm, because we cannot improve the running time bound of our FPTAS by improving the approximation ratio from 13 to 21 , but will worsen the running time bound if the running time of the constant approximation algorithm changes from π(π log π) to π(π2 ). 3
The correctness of the algorithm (Theorem 2 in [6]) was proved by assuming an important property (the fourth line of the proof of Theorem 2), the complete proof of which was omitted.
10
5.3
Mingyu Xiao, Takuro Fukunaga, and Hiroshi Nagamochi
The FPTAS
Next, we design the FPTAS for MaxMstCut. Let π
=Appro(πΊ, π). Algorithm DP(πΊ, π, 3π(π
)) will ο¬nd an optimal solution for our problem (assume that all edge costs are integers). If the cost of each edge is a small number, i.e., bounded by a polynomial of π, then DP(πΊ, π, 3π(π
)) runs in polynomial time. To obtain an FPTAS, we scale the cost of each edge down to be bounded by a polynomial of π and use Algorithm DP on the new instance to get a solution. By scaling with respect to the desired error π, we can get a solution with cost within (1βπ)π(π β ) and π(π β ) in polynomial time with respect to both π and 1/π, where π β is an optimal solution to the original instance (πΊ, π). The FPTAS for MaxMstCut is described in Fig. 4. Algorithm Fptas1(πΊ, π, π) Input: A rooted tree πΊ = (π, πΈ) with nonnegative edge cost π : πΈ β ββ and nonnegative vertex weight π€ : π β ββ , and two numbers π β₯ 0 and 1 > π > 0. Output: A (1 β π)-approximation solution to MaxMstCut. 1. 2. 3. 4.
π
ββAppro(πΊ, π) and π ββ π(π
). If π = 0, return π
as an optimal solution and halt. π ββ ππ/π and replace π(π) with πβ² (π) = βπ(π)/πβ to get πΊβ² . Return DP(πΊβ² , π, β3π/πβ). Fig. 4. Algorithm Fptas1(πΊ, π, π)
Theorem 1. For MaxMstCut in a rooted tree with nonnegative edge cost and nonnegative vertex weight, algorithm Fptas1(πΊ, π, π) runs in π(ππ/π) time and π(π2 /π + π) space, and returns a root-connecting set π such that π(π ) β₯ (1 β π)π(π β ),
(1)
where π β is an optimal solution to MaxMstCut. Proof. Since Appro(πΊ, π) runs in π(π log π) time and π(π) space, and DP(πΊβ² , π, β3π/πβ) runs in π(3ππ/π) = π(ππ/π) time and π(3ππ/π + π) = π(π2 /π + π) space, we get the running time and space bounds. Next, we prove (1). It is clear that for any edge π, 0 β€ π(π) β ππβ² (π) < π. Since the cardinality of any cut is at most the number π of leaves in πΊ, any root-connecting set π β= β
satisο¬es β£πΈ(π β π, π)β£ β€ π and 0 β€ π(π) β ππβ² (π) < ππ. Since πβ² (π β ) β€ βπ(π β )/πβ β€ β3π/πβ holds, DP(πΊβ² , π, β3π/πβ) ο¬nds an optimal solution π for the scaled instance, which satisο¬es πβ² (π β ) β€ πβ² (π ) β€ β3π/πβ. Since πβ² (π ) β₯ πβ² (π β ) β₯ π, we have π(π ) β₯ ππβ² (π ) β₯ ππβ² (π β ) β₯ π(π β ) β ππ = π(π β ) β ππ β₯ (1 β π)π(π β ).
FPTASβs for Trimming Weighted Trees
6
11
FPTASβs for MinLstCut and MaxLstCut in Rooted Trees
We cannot directly extend the FPTAS for MaxMstCut in Section 5 to an FPTAS for MinLstCut or MaxLstCut in rooted trees, because we have no similar constant factor algorithm as Appro(πΊ, π) for MinLstCut or MaxLstCut. To get a constant factor algorithm, we will use a βroundingβ technique [14]. This technique is used as a basic trick for deriving FPTASβs for many problems. We will also use a new technique, called βbinary searchβ, to get the ο¬nial FPTAS. In this section, we design the FPTAS for MinLstCut, which can also be modiο¬ed to solve MaxLstCut. 6.1
The Preliminary Algorithm
First we present an algorithm Scaling for MinLstCut. Whether a given MinLstCut instance (πΊ, π) has an optimal solution π β with π(π β ) = 0 or not can be tested in linear time by checking if π€(π β² ) β₯ π for the set π β² of non-root vertices in the tree obtained by contracting all edges with positive costs. We here assume that π(π β ) β₯ πmin for the minimum πmin of positive edge costs. Given an instance such that π β€ π(π β ) for a positive number π and a prescribed number π > 0, algorithm Scaling will run in π(ππ/π) time and π(π2 /π + π) space and return a feasible solution with value π(π ) satisfying (1 + π)π(π β ) β₯ π(π ), if π(π β ) β€ 2π, or π =β₯ if π(π β ) > 2π.
Algorithm Scaling(πΊ, π, π, π) Input: A rooted tree πΊ = (π, πΈ) with nonnegative edge cost π : πΈ β π
β and nonnegative vertex weight π€ : π β π
β , and three numbers π β₯ 0, π > 0 and a number π β₯ πmin . Output: A feasible solution to MinLstCut, if any, or β₯ otherwise. 1. π ββ ππ/π and replace π(π) with πβ² (π) = βπ(π)/πβ to get πΊβ² . 2. Return DP(πΊβ² , π, β2π/πβ). Fig. 5. Algorithm Scaling(πΊ, π, π, π)
By the deο¬nition of DP(πΊβ² , π, β2π/πβ) for MinLstCut, it will return a feasible solution π such that πβ² (π ) β€ β2π/πβ if any, or β₯ otherwise. Note that if it returns β₯ then we know π(π β ) > 2π since π(π β ) β€ 2π implies πβ² (π β ) β€ β2π/πβ. Assume π β€ π(π β ) β€ 2π and let π = Scaling(πΊ, π, π, π). Analogously with the analysis of Theorem 1, we can prove that directly π(π ) β€ π β
πβ² (π ) β€ π β
πβ² (π β ) β€ π(π β ) + ππ = π(π β ) + ππ. Hence if π(π β ) β₯ π then π(π ) β€ (1+π)π(π β ) holds. Therefore, Scaling(πΊ, π, π, π) works as claimed.
12
Mingyu Xiao, Takuro Fukunaga, and Hiroshi Nagamochi
To get an approximation scheme, we need to compute a value πβ such that π β€ π(π β ) β€ 2πβ and call Scaling(πΊ, π, π, πβ ). To detect such πβ , we repeatedly check intervals [πmin , 2πmin ], [2πmin , 4πmin ], ... as in the loop in Fig. 6 to compute πβ . β
1. Let π ββ πmin ; 2. If Scaling(πΊ, π, π = 1, π) β=β₯, return π as πβ and halt; 3. Otherwise, let π ββ 2π and go to Step 2. Fig. 6. Computing πβ
It is clear that the process in Fig. 6 will return πβ by calling Scaling(πΊ, π, π = 1, π) for at most βlog(π(π β )/πmin )β times. Therefore, we can compute πβ in π(ππ log(π(π β )/πmin )) time and π(π2 + π) space. Theorem 2. There is an π(ππ(1/π + log(π(π β )/πmin )))-time and π(π2 /π + π)space algorithm that computes a solution with error π for MinLstCut in a rooted tree with nonnegative edge cost and nonnegative vertex weight. Since the running time of the approximation algorithm depending on π(π β ), it is not a real polynomial-time algorithm. Next, we further improve the running time bound from π(ππ(1/π + log(π(π β )/πmin ))) to π(ππ(1/π + log π)). 6.2
Binary Search and Further Improvement
In Fig. 6, we set π as 1 in the beginning to compute πβ , and the algorithm may run βlog(π(π β )/πmin )β loops. If we get a value π1 such that π1 β€ π(π β ) β€ ππ1 and set π as π1 in the ο¬rst step, then we can compute πβ in π(ππ log π) time. We will use a technique called βbinary searchβ to compute such a value π1 such that π1 β€ π(π β ) β€ ππ1 or a value πβ²1 such that πβ²1 β€ π(π β ) β€ 2πβ²1 in π(ππ log π) time. We sort the positive numbers in {π(π) > 0 β£ π(π), π β πΈ} into an increasing sequence π1 < π2 < β
β
β
< πβ in π(π log π) time, where π1 = πmin β€ π(π β ). We ο¬rst detect an index π such that ππ β€ π(π β ) β€ 2ππ+1 by applying algorithm Scaling in π(log π) times. For a given number π > 0, let π ββDP(πΊ, πβ² , π€, π, β2π/πβ) for π = π/π and πβ² = βπ/πβ. As observed, if π =β₯, then π(π β ) > 2π, else π is a feasible solution such that π(π ) β€ π(π β ) + π, from which we know either π(π β ) β₯ π (when π(π ) β₯ 2π) or π(π β ) β€ π(π ) < π (when π(π ) < 2π). Overall, the algorithm DP tells us either π β€ π(π β ) or π(π β ) < 2π. Staring with the initial interval πΌ = [1, 2, . . . , β], we repeat the following until the current interval contains only one index: Choose the middel index π in the current interval πΌ = [π, π + 1, . . . , π] and test whether ππ β€ π(π β ) or π(π β ) < 2ππ . Then reset πΌ to be interval [π + 1, π + 2, . . . , π] for the former case, and set πΌ to be [π, π + 1, . . . , π β 1] for the latter. The procedure ο¬nds the above index π in π(ππ log π) time and π(π2 + π) space.
FPTASβs for Trimming Weighted Trees
13
For such an index π, we can ο¬nd a (1 + π)-approximation by taking a better one from the following two solutions π1 and π2 . (i) ππ+1 β€ π(π β ) β€ 2ππ+1 : Compute π1 =Scaling(πΊ, π, π, ππ+1 ) in π(ππ/π) time and π(π2 + π) space; (ii) ππ β€ π(π β ) < ππ+1 : No edge with cost greater than ππ is used in πΈ(π β , π β π β ). Contract all those edges to obtain a new tree, wherein the total cost of all edges is not greater than πππ , and hence π(π β ) β€ πππ . By setting π to be ππ in the algorithm in Fig. 6, we can ο¬nd πβ with πβ β€ π(π β ) β€ 2πβ by at most log(π(π β )/ππ ) β€ log π iterations. Let π2 =Scaling(πΊ, π, π, πβ ). Although we do not know which of (i) and (ii) occurs, π1 or π2 gives a (1 + π)-approximation, and the required complexity is π(ππ(1/π + log π)) time and π(π2 /π + π) space. The FPTAS for MinLstCut in this section can be directly modiο¬ed to a similar FPTAS for MaxLstCut, which preserves the approximation ratio. We here only mention that a similar binary search can be obtained for MaxLstCut to reduce the time complexity from π(ππ(1/π + log(π(π β )/πmin ))) to π(ππ(1/π + log π)). For this, it suο¬ces to show that, for a given number π > 0, we can get π β€ π(π β ) or π(π β ) < 2π in π(ππ) time and π(π2 /π + π) space. Compute π ββDP(πΊβ² , π, βπ/πβ) for π = π/π and πβ² = βπ/πβ in πΊβ² . As observed, if π =β₯, then π(π β ) > π, else π is a feasible solution such that π(π ) β₯ π(π β ) β π, from which either π(π β ) < 2π (when π(π ) < π) or π(π β ) β₯ π(π ) β₯ π (when π(π ) β₯ π) holds. Hence we know π β€ π(π β ) or π(π β ) < 2π. Theorem 3. There is an π(ππ(1/π + log π))-time and π(π2 /π + π)-space algorithm that computes a solution with error π for MinLstCut and MaxLstCut in a rooted tree with nonnegative edge cost and nonnegative vertex weight.
7
FPTASβs for Unrooted Trees
If the tree is an unrooted tree, we still can solve our problems by choosing each vertex as a root and solving the π problems in the rooted trees. But the running time bound will increase by a factor of π©(π). There is a simple divide-andconquer method to improve the result. By choosing a vertex as π in the tree, we can either solve the problem in the tree rooted at π or solve several (constrained ) problems in subtrees obtained by separating at π (See Fig. 7 for the illustration). Note that in each subtree we still keep a copy of π, called ππ , with the weight being the sum of the weight of all the vertices separated away from this subtree (including vertex π itself). In each subtree we should ο¬nd a solution under the constraint that the new vertex ππ is cut away from the tree. To reduce the running time eο¬ectively, each we can select a balanced separator as the considered vertex π (Each subtree obtained after deleting π has at most half of number of vertices). With this method, we can solve the problems in unrooted trees by increasing running time bound by only a factor of π©(log π). In this section, we present an algorithm that iteratively chooses a leaf-balanced separator of the tree and solves the problem in a divide-and-conquer way. With some nontrivial analysis, we show that this method can solve our problems in unrooted trees without increasing the running time. First of all, we give the precise deο¬nitions of constrained problems
14
Mingyu Xiao, Takuro Fukunaga, and Hiroshi Nagamochi
and leaf-balanced separator. we design linear-time algorithms for our problems in paths (unrooted trees with only two leaves), which will be used as subalgorithms in our FPTASβs.
u u
w
w
rw ru rv
r v
v
Fig. 7. Separation of a tree at vertex π
7.1
Constrained Problems and Leaf-Balanced Separator
Given a set of inputs of MaxMstCut (MinLstCut, or MaxLstCut) additionally with a prescribed set πΏβ² of leaves, the constrained MaxMstCut (MinLstCut, or MaxLstCut) requires to ο¬nd a solution to cut away all leaves in πΏβ² (possibly with other leaves) from the given tree, where πΏβ² may be empty. We design an algorithm DPβ² (πΊ, πΏβ² , π, π) for the constrained MaxMstCut (MinLstCut, or MaxLstCut). Thus for πΏβ² = β
, DPβ² (πΊ, β
, π, π) is exactly DP(πΊ, π, π). The algorithm DPβ² (πΊ, πΏβ² , π, π) can be obtained by modifying DP(πΊ, π, π) as follows. In the ο¬fth line of Step 2 in Fig. 2, DP(πΊ, π, π) initializes ππ π (π, π) and π(π, π) by ππ π (π, π) ββ ππ π (π β 1, π), π(π, π) ββ π(π β 1, π). In the modiο¬ed algorithm DPβ² , the same initialization is used if leaf π§π ββ πΏβ² . On the other hand, if π§π β πΏβ² , we initialize them by ππ π (π, π) ββ β, π(π, π) βββ₯ for MaxMstCut and initialize them by ππ π (π, π) ββ β1, π(π, π) βββ₯ for MinLstCut and MaxLstCut. By this modiο¬cation, for MaxMstCut, all cuts that keep π§π β πΏβ² in the tree are assigned an inο¬nite cost. Thus the algorithm computes a minimum cost solution of the constrained MaxMstCut if a feasible solution exists. For MinLstCut and MaxLstCut, the modiο¬ed algorithm DPβ² also works as claimed. Note that the running time bound of DPβ² does not change. We can also design FPTASβs for our constrained problems with the same running time bound. We
FPTASβs for Trimming Weighted Trees
15
use Fptas1β² (πΊ, πΏβ² , π, π) (resp., Fptas2β² (πΊ, πΏβ² , π, π)) to denote the corresponding FPTAS in Section 5 for MaxMstCut (resp., FPTAS in Section 6 for MinLstCut and MaxLstCut) in a rooted tree πΊ with the constraint that all leaves in πΏβ² should be cut away in ο¬nding a solution. Next, we introduce the concept of leaf centroid, which will be used to separate the tree into several small trees. Lemma 3. For any tree, there is a vertex such that each of the subtrees obtained by removing it contains at most half of number of leaves in the original tree, and this vertex can be found in linear time. We will call the vertex described in Lemma 3 a leaf centroid. Leaf centroid is an extension of centroid introduced in [8]. Lemma 3 can be proved easily. Before we present the algorithm for unrooted trees, we consider a special case that the graphs are restricted to paths (unrooted trees with only two leaves), the algorithms for which will be used as subalgorithms in our FPTASs for general unrooted trees. 7.2
Linear Algorithms for the Problems In Paths
In this subsection, we mainly design some linear-time algorithms for (constrained) MinLstCut, MaxLstCut, MinMstCut and MaxMstCut in a path with general edge cost and nonnegative vertex weight. Note that our algorithms allow negative edge cost. MinLstCut and MaxLstCut (MinMstCut and MaxMstCut) are equivalent since we can reset the edge cost to get each other. Then we only need to consider two problems, MinLstCut and MinMstCut. In fact, we have designed a linear-time algorithm for MinMstCut in trees with nonnegative edge cost and nonnegative vertex weight in Section 3.2. However, that algorithm does not allow negative edge cost. Given a path π = π1 π2 β
β
β
ππ with π vertices, where the vertices are arranged from the left end π1 to the right end ππ . For each vertex ππ in the path, we let π1 (ππ ) = {π1 , π2 , . . . , ππ } and π2 (ππ ) = {ππ , ππ+1 , . . . , ππ }. We can compute π€(π1 (ππ )) and π€(π2 (ππ )) for all πβs in linear time. First, we present a linear-time algorithm for MinLstCut in a path in Fig. 8. In the algorithm, π(π) will store an optimal solution π β² β π under the constraint that the corresponding cut set πΈ(π β² ) contains two edges and the left edge is the π-th edge ππ ππ+1 from left to right, if any, or π(π) =β₯ otherwise. In Step 2, we check the case that the cut set of the optimal solution contains only one edge. In Step 5, we check the case that the cut set of the optimal solution contains two edges, which will be ππ ππ+1 and ππ β β1 ππ β . Note that in each iteration in Step 5, π or π will increase by 1. We require that π < π β€ π, and then there are less than 2π iterations. Each iteration can be done in π(1) time. Therefore the whole algorithm runs in linear time. To prove the correctness of the algorithm, we only need to prove that π(π) works as claimed. If π(π) =β₯, it is easy to see that there is no solution the corresponding cut set of which contains ππ ππ+1 as the left edge. Otherwise, we consider the case of π β > 0. Note each time before
16
Mingyu Xiao, Takuro Fukunaga, and Hiroshi Nagamochi
we increase π by 1 in Step 5, edge ππ β β1 ππ β is the minimum edge in the path ππ+1 ππ+2 β
β
β
ππ . Since the algorithm will increase π to the maximum index such that π€(π1 (ππ )βͺπ2 (ππ )) β₯ π, at the time before π changes to π+1, π(π) has already stored an optimal solution under the constraint. Therefore, it works as claimed. Since the algorithm will return the best one among {π, π(1), π(2), . . . , π(π β 1)}, the algorithm will ο¬nd an optimal solution to MinLstCut.
Algorithm Path1(π, πΏβ² , π) Input: A path π = π1 π2 β
β
β
ππ with an edge cost π and a nonnegative vertex weight π€ : π β ββ , a subset πΏβ² β {π1 , ππ } of leaves, and a number π β₯ 0. Output: An optimal solution π to MinLstCut with the constraint that πΏβ² β π, if any, or β₯ otherwise. 1. Let π βββ₯. 2. For π from 1 to π β 1, do If (π1 ββ πΏβ² and π€(π2 (ππ+1 )) β₯ π and π(π2 (ππ+1 )) < π(π)), then π ββ π2 (ππ+1 ). If (ππ ββ πΏβ² and π€(π1 (ππ )) β₯ π and π(π1 (ππ )) < π(π)), then π ββ π1 (ππ ). 3. For π from 1 to π β 1, do π(π) βββ₯. 4. Let π ββ 1, π ββ 3 and π β ββ 0. 5. While (π < π β 1) do Let π β² ββ π1 (ππ ) βͺ π2 (ππ ). If π€(π β² ) β₯ π then If π(π β² ) < π(π(π)), then π(π) ββ π β² and π β ββ π. If π < π, then π ββ π + 1. Else π ββ π + 1. If π = π β 1, then π ββ π + 1 and π β ββ 0. If π β β= 0, then π(π) ββ π1 (ππ ) βͺ π2 (ππ β ). 6. Return π as the best among {π, π(1), π(2), . . . , π(π β 1)}. Fig. 8. Algorithm Path1(π, πΏβ² , π)
The technique for the algorithm in Fig. 8 can also be used to derive a lineartime algorithm for MinMstCut. By modifying Path1, we present algorithm Path2 for MinMstCut in a path in Fig. 9. Diο¬erently from Path1, Path2 will use π(π) to store an optimal solution π β² β π under the constraint that the corresponding cut set πΈ(π β² ) contains two edges and the right edge is the (π β 1)th edge ππβ1 ππ from left to right. The analysis for this algorithm is also similar to that for Path1. In Path2, Step 2 is to deal with the case that the cut set contains only one edge, and Step 5 considers the case that the cut set contains two edges. In each iteration in Step 5, π or π will increase by 1, and we require that π < π β€ π. Then the algorithm will run in linear time. The correctness of the algorithm follows from the following observation. In Step 5, the algorithm will keep edge ππβ ππβ +1 as a minimum edge in the path π1 π2 β
β
β
ππ+1 (when πβ β= 0),
FPTASβs for Trimming Weighted Trees
17
where π satisο¬es that π€(π1 (ππ ) βͺ π2 (ππ )) β€ π. Since for each π, the algorithm will increase π to the maximum index satisfying the constraint, the algorithm can ο¬nd an optimal solution for π(π).
Algorithm Path2(π, πΏβ² , π) Input: A path π = π1 π2 β
β
β
ππ with an edge cost π and a nonnegative vertex weight π€ : π β ββ , a subset πΏβ² β {π1 , ππ } of leaves, and a number π β₯ 0. Output: An optimal solution π to MinMstCut with the constraint that πΏβ² β π, if any, or β₯ otherwise. 1. Let π βββ₯. 2. For π from 1 to π β 1, do If (π1 ββ πΏβ² and π€(π2 (ππ+1 )) β€ π and π(π2 (ππ+1 )) < π(π)), then π ββ π2 (ππ+1 ). If (ππ ββ πΏβ² and π€(π1 (ππ )) β€ π and π(π1 (ππ )) < π(π)), then π ββ π1 (ππ ). 3. For π from 3 to π, do π(π) βββ₯. 4. Let π ββ 1, π ββ 3 and πβ ββ 0. 5. While (π β€ π) do Let π β² ββ π1 (ππ ) βͺ π2 (ππ ). If π€(π β² ) β€ π then If π(π β² ) < π(π(π)), then π(π) ββ π β² and πβ ββ π. If π β€ π β 2, then π ββ π + 1. Else π ββ π + 1. If πβ β= 0, then π(π) ββ π1 (ππβ ) βͺ π2 (ππ ). 6. Return π as the best among {π, π(3), π(4), . . . , π(π)}. Fig. 9. Algorithm Path2(π, πΏβ² , π)
7.3
The Algorithms for Unrooted Trees
Now we are ready to design and analyze the algorithm for general unrooted trees. Recall that πΊπ is the rooted tree obtained from an unrooted tree πΊ by choosing π as the root. For a neighbour π£ of π, let πΊπ (π£) denote the tree obtained by contracting π β π·(π£) in πΊπ into a single (nonroot) vertex ππ£ with weight π€(ππ£ ) being the total weight of vertices in π β π·(π£). Separating a vertex π in a unrooted tree πΊ means to construct unrooted subtrees πΊπ (π£) for all neighbour π£ of π. In our algorithm, we will select the vertex π for such separation as the leaf centroid of the tree. Note that π€π (π£) can be computed in a DFS for all pairs of π and its neighbour π£. We will assume that we can get all the subtrees after separating a tree at a vertex π in linear time. The main steps of our algorithm for (constrained) MaxMstCut in unrooted trees is presented in Fig 10.
18
Mingyu Xiao, Takuro Fukunaga, and Hiroshi Nagamochi
Algorithm Unroot(πΊ, πΏβ² , π, π) Input: An unrooted tree πΊ = (π, πΈ) with nonnegative edge cost π : πΈ β ββ and nonnegative vertex weight π€ : π β ββ , a subset πΏβ² of leaves in πΊ, and two numbers π β₯ 0 and 1 > π > 0 (Initially, πΏβ² = β
). Output: A (1 β π)-approximation solution π to MaxMstCut with the constraint that πΏβ² β π. 1. If πΊ has only two leaves, solve the problem in linear time by using the algorithm presented in Section 7.2 and return the solution. 2. Let π be a leaf centroid of πΊ and πΊπ the rooted tree obtained by selecting π as the root in πΊ. 3. π β Fptas1β² (πΊπ , πΏβ² , π, π). 4. For each neighbour π£ of π, do 4.1 Construct the subtree πΊπ (π£). 4.2 Let π β² βUnroot(πΊπ (π£), πΏβ² βͺ {ππ£ }, π, π). 4.3 If π(π) < π(π β² ), let π β π β² . 5. Return π. Fig. 10. Algorithm Unroot(πΊ, π, πΏβ² , π)
Algorithm Unroot for MinLstCut and MaxLstCut can be obtained by replacing the called algorithm Fptas1β² (πΊπ , π, πΏβ² , π) with Fptas2β² (πΊπ , πΏβ² , π, π) in Step 3 and modify the if condition in Step 4.3. The correctness of algorithm Unroot follows from this observation: Let π be an optimal solution, if π β π β π then we can ο¬nd a solution within the error bound in the ο¬rst step, if π β π then the optimal solution is an optimal solution to the problem in πΊπ (π£) for some neighbour π£ of π with the constraint π β π, which implies that we can solve the problem by solving the constrained problems in πΊπ (π£). We will solve the problem directly if the tree has only two leaves. Then the algorithm will run in π(log π) iterations by Lemma 3. Note that when the tree has at least three leaves, no leaf centroid is a leaf of the tree, and hence πΏβ² does not contain a possible root, implying that our algorithm always receives a well-deο¬ned input. As for the running time, we have showed that the problems can be exactly solved in linear time when the graphs are restricted to paths. The hard part is the analysis for the general case. Since the case for MaxMstCut will be covered by the case of MinLstCut and MaxLstCut, in this section we will analyze the algorithm for MinLstCut. We consider the search tree π― generated in the algorithm. Each node of π― corresponds to an instance of the constrained MinLstCut in unrooted trees. The root of π― represents the original instance πΊ(0) = πΊ.4 The children of a node π£ in π― correspond to the instances called recursively by the fourth step of the algorithm when it solves the instance corresponding to π£. In each non-leaf node of π― , the algorithm will call Fptas2β² once in Step 3. The whole running time 4
We may use the same notation to denote the instance in a node of π― and the corresponding tree in the instance.
FPTASβs for Trimming Weighted Trees
19
of the algorithm will be the sum of all the running time taken by Fptas2β² in non-leaf nodes and the running time taken by the linear-time algorithms in leaf nodes. Note that the running time used in each leaf node is also bounded by the running time of Fptas2β² . In π― , we say that a node is in level π if the path from the node to the root πΊ(0) contains π edges. We ο¬x an ordering of the nodes in the same level of π― (π) according to a BFS. We will use πΊπ to denote the instance corresponding to the π-th node in the π-th level of π― . Let π (π) denote the total number of vertices of all trees in the π-th level instances. We see that π (π) β€ 2π for any π, since no edge in the original πΊ(0) appear more than once over all instances in the same level. (π) (π) Fig. 11 llustrates a search tree π― . Let ππ and ππ denote the numbers of vertices (π)
and leaves in the instance πΊπ . Then a time bound on the basic computation (π)
for executing Fptas2β² to πΊπ
(π) (π)
is given by πππ ππ (1/π + log 2π) for a constant (π)
π > 0. To analyze the running time, we ο¬rst get a bound on the time ππ0 of basic computations for solving all problems in the trees corresponding to the (πβ1) children of instance πΊπ0 for some π0 . Then we bound the time π (π) of basic computations for solving all instances in the π-th level of π― . Finally, we get the whole running time of the algorithm by summing up π (π) for all πβ² π .
G (0)
G1(1)
Level 1
......
G1(i )
......
G2(i )
......
G3(1)
...... ......
......
G (j0i β1)
Level i-1
Level i
G2(1)
G (j0i β+1)1
Gx(i )
Gx(i+)1
......
...... Fig. 11. An illustration of π― (πβ1)
Take an instance πΊπ0
generality, we assume that (π)
we have 3 β€ ππ
not corresponding to a leaf of π― . Without loss of
(πβ1) πΊπ0
(π)
has child instances πΊπ (π = 1, 2, . . . , π₯). Then βπ₯ (πβ1) (π) (πβ1) (πβ1) (π) β€ ππ0 β1, 3 β€ ππ β€ β 12 ππ0 β+1, π=1 ππ β€ ππ0 +π₯β1,
20
Mingyu Xiao, Takuro Fukunaga, and Hiroshi Nagamochi
βπ₯ (π) (πβ1) and π=1 ππ β€ ππ0 + π₯. Under these constraints, we can prove the following relation (see Appendix B for the full proof): π₯ β π=1
(π) (π)
π π ππ β€
1 (πβ1) (πβ1) 5 (πβ1) π ππ0 + ππ0 . 2 π0 2
(π)
(2) (πβ1)
Now, we prove a bound for ππ0 . For all subinstances of πΊπ0 , the basic comβπ₯ (π) (π) (π) putation for executing their Fptas2β² is bounded by ππ0 = π=1 πππ ππ (1/π + (π)
log 2π). By (2), we can bound ππ0 as follows: (π)
ππ0 β€
π₯ β
π (πβ1) (πβ1) (π) (π) (πβ1) πππ ππ (1/π + log 2π)β€ (ππ0 ππ0 + 5ππ0 )(1/π + log 2π). (3) 2 π=1
Next, we prove a bound for π (π) , i.e., the running time for solving all instances β (π) in the π-th level of π― . Clearly, π (π) = π ππ . By using these and (3), we can bound π (π) as follows: β (πβ1) (πβ1) (πβ1) )(1/π + log 2π) + 5ππ ππ π (π) β€ π 2π (ππ β β (πβ1) (πβ1) (πβ1) 1 = 2 π πππ (1/π + log 2π) + π 5π ππ (1/π + log 2π) 2 ππ 1 (πβ1) 5π (πβ1) β€ 2π + 2π (1/π + log 2π) β€ 21 π (πβ1) + 5ππ(1/π + log 2π). For the maximum level β = π(log π), we have β β β 1 β (π) 1 π β€ π (0) + (π (π) β π (πβ1) ) β€ πππ(1/π+log π)+5π(β+1)π(1/π+log 2π). 2 π=0 2 π=0
Therefore our algorithm for MinLstCut runs in π(ππ(1/π + log π)) time. In the same way, we know that MaxMstCut in unrooted trees can also be solved in the same running time as that for the problem in rooted trees. The space used in the algorithms for the problems in unrooted trees also does not increase. Then we get Theorem 4. There is an π(ππ/π)-time and π(π2 /π + π)-space algorithm that computes a solution with error π for MaxMstCut in an unrooted tree with nonnegative edge cost and nonnegative vertex weight. Theorem 5. There is an π(ππ(1/π + log π))-time and π(π2 /π + π)-space algorithm that computes a solution with error π for MinLstCut and MaxLstCut in an unrooted tree with nonnegative edge cost and nonnegative vertex weight.
8
Concluding Remarks
In this paper, we have designed several eο¬ective algorithms for some related cut problems in rooted trees by using scaling, rounding, binary search, left-right
FPTASβs for Trimming Weighted Trees
21
DP and some other techniques. We have also extended our algorithms to the corresponding problems in unrooted trees without increasing the running time bounds with nontrivial analysis. Although the algorithms presented in this paper are eο¬ective, there is a gap between the upper bound for the knapsack problem and the upper bounds for our problems. It will be interesting to further reduce the gap. Another question for further study is to consider the problems in more graph classes, such as πtrees, directed acyclic graphs and so on. In our problems, we restrict the edge cost and vertex weight to be nonnegative. There are simple reductions among the problems as long as no restriction such as nonnegativeness is imposed on cost/weight/target. We only need to reset the values of the edge cost, vertex weight and target π to get diο¬erent problems. For the terminal version of the problem without the nonnegativeness constraint on edge cost, we can also solve it by modifying our dynamic programming algorithm in Section 4. However, it is not convenient to discuss approximation algorithm when the optimal value can be negative or positive.
Acknowledgements Part of the work was done when the ο¬rst author was visiting Kyoto University in 2009. This work was partially supported by Grant-in-Aid for Scientiο¬c Research from the Ministry of Education, Culture, Sports, Science and Technology of Japan, and National Natural Science Foundation of China under the Grant 60903007.
A
Algorithm for MinMstCut
Theorem 6. An optimal cut to terminal MinMstCut without constraint (i) in a graph with nonnegative edge cost can be obtained in π(π‘3 ππ log π) time, where π‘ = β£π β£, π = β£π β£ and π = β£πΈβ£. Proof. Let π(π) denote the cut function of πΊ, i.e., the sum of the costs of edges between π and π β π in πΊ. Let π β be the set of vertices to be removed by an optimal cut, and assume that β£π β β£ is minimized over all such sets. Then π€(π β ) β€ π and π(π ) > π(π β ) for all nonempty proper subsets π β π β . To ο¬nd such a set π β eο¬ciently, deο¬ne a set function π : 2π β ββ by setting π (π β² ) to be the minimum cost of a cut separating π β² and π β π β² , i.e., π (π β² ) = min{π(π β² ) β£ π β² β π, π β² β©π = π β² }. We see that π is a symmetric submodular set function, and we can ο¬nd the family π³ of all extreme subsets π β² β π (i.e., those sets such that π (π β²β² ) > π (π β² ) for all nonempty proper subsets π β²β² β π β² ) in π(β£π β£3 β£π β£β£πΈβ£ log β£π β£) time by an algorithm due to Nagamochi [12]. The remaining task is to pick up an extreme set π β with the minimum cost π (π β ) among all extreme set π β² β π³ and π€(π β² ) β€ π. The subset π β attaining π(π β ) = π (π β ) and π β β© π = π β gives an optimal cut [π β , π β π β ].
22
B
Mingyu Xiao, Takuro Fukunaga, and Hiroshi Nagamochi
Proof of (2)
To prove (2), we ο¬rst give the following inequality. Lemma 4. Given β nonnegative numbers π₯ β₯ 2, ππ , ππ (π = 1, 2, . . . , π₯), π΄, π΅, βπ₯ π₯ β and π such that π=1 ππ β€ π΄, π=1 ππ β€ π΅, ππ β€ β β€ π΄ and π β€ ππ (π = 1, 2, . . . , π₯). Then for π = βπ΄/ββ, it holds π₯ β
ππ ππ β€ β(π΅ β (π₯ β π β 1)π).
π=1
Proof. Without βπ loss of generality, we assume that π1 β₯ π2 β₯ β
β
β
β₯ ππ₯ . For π₯π = πβ β π=1 ππ , consider πβ²π (π = 1, . . . , π₯) such that πβ²1 = β
β
β
= πβ²π = β, βπ₯ βπ₯ πβ²π β€ ππ (π = π + 1, . . . , π₯), and π=π+1 πβ²π = π=π+1 ππ β π₯π . Then we have π₯ β
ππ ππ β€
π=1
π₯ β
πβ²π ππ .
π=1
Furthermore, consider πβ²π (π = 1, . . . , π₯) such that where and πβ²π = π (π = π + 1, . . . , π₯), and we have π₯ β π=1
Therefore,
βπ₯
π=1
πβ²π ππ β€
π₯ β
βπ
β² π=1 ππ
= π΅ β (π₯ β π)π
πβ²π πβ²π .
π=1
βπ₯ ππ ππ β€ β(π΅ β (π₯ β π)π) + π=π+1 πβ²π πβ²π β€ β(π΅ β (π₯ β π)π) + (π΄ β πβ)π β€ β(π΅ β (π₯ β π)π) + βπ = β(π΅ β (π₯ β π β 1)π).
Now we are ready to prove (2). Proof. When π₯ = 2, it is easy to see that β2 (π) (π) (πβ1) (πβ1) 1 (πβ1) + 2)(ππ0 β 2) + 12 ππ0 β
3 π=1 ππ ππ β€ ( 2 ππ0 (πβ1) 1 (πβ1) (πβ1) 1 (πβ1) = 2 ππ0 ππ0 + 2 ππ0 + 2ππ0 β4 5 (πβ1) 1 (πβ1) (πβ1) β€ 2 ππ0 ππ0 + 2 ππ0 . (π)
(π)
(πβ1)
When π₯ β₯ 3, we let ππ = ππ , ππ = ππ , β = β 21 ππ0 (πβ1) π π0
(πβ1)
β + 1, π΄ = ππ0
+ π₯,
π΅ = + π₯ β 1 and π = 3. It is easy to see that when π₯ β₯ 3, it holds 2(π₯ β 1) β₯ 3π = 3βπ΄/ββ. By Lemma 4, we get βπ₯ (πβ1) 1 (πβ1) + 2)(ππ0 + π₯ β 1 β 3(π₯ β π β 1)) π=1 ππ ππ β€ β(π΅ β (π₯ β π β 1)π) = ( 2 ππ0 (πβ1) (πβ1) (πβ1) β€ 12 ππ0 ππ0 + 2ππ0 . This completes the proof.
FPTASβs for Trimming Weighted Trees
23
References 1. T. N. Bui, C. Jones. βFinding good approximate vertex and edge partitions is NP-hard,β Inform. Process. Lett. 42 (1992), 153β159. 2. G. Cho, D.X. Shaw. βA depth-ο¬rst dynamic programming algorithm for the tree knapsack problem,β INFORMS Journal on Computing. 9(4) (1997), 431β438. 3. E. Dahlhaus, D. Johnson, C. Papadimitriou, P. Seymour, M. Yannakakis. βThe complexity of multiterminal cuts,β SIAM J. Comput. 23(4) (1994), 864β894. 4. U. Feige, R. Krauthgamer, K. Nissim. βOn cutting a few vertices from a graph,β Discrete Applied Mathematics 127 (2003), 643β649. 5. U. Feige, M. Mahdian. βFinding small balanced separators,β In: Proceedings of the 38th Annual ACM symposium on Theory of Computing (2006), 375β384. 6. O. Ibarra, C. Kim.βApproximation algorithms for certain scheduling problems,β Math. Oper. Res., 3(3) (1978),197β204. 7. D. S. Johnson, K. A. Niemi. βOn knapsacks, partitions, and a new dynamic programming technique for trees,β Mathematics of Operations Research, 8(1) (1983), 1β14. 8. C. Jordan. βSur Les Assemblages De Lignes,β J. Reine Angew. Math. 70 (1869), 185-190. 9. H. Kellerer, U. Pferschy, D. Pisinger, βKnapsack Problems,β Springer, 2004. 10. J. KΒ¨ onemann, O. Parekh, D. Segev. βA uniο¬ed approach to approximating partial covering problems,β In: Proceedings of the 14th Annual European Symposium on Algorithms, Lecture Notes in Computer Science 4168 (2006), 468β479. 11. D. Marx. βParameterized graph separation problems,β Theoret. Comput. Sci. 351(3) (2006), 394β406. 12. H. Nagamochi. βMinimum degree orderings,β Algorithmica, 56(1) (2010), 17β34. 13. H. Nagamochi. βAlgorithms for the minimum partitioning problems in graphs,β Electronics and Communications in Japan 90(10) (2007), 63β78. 14. S. Sahni. βGeneral Techniques for Combinatorial Approximation,β Operations Research 25(6) (1977), 920-936. 15. M. Xiao, T. Fukunaga, H. Nagamochi. βFPTASβs for some cut problems in weighted trees,β In: Proceedings of the 4th International Frontiers of Algorithmics Workshop, Lecture Notes in Computer Science 6213 (2010), 210β221.