Abstract
Given a graph with n vertices, k terminals and positive integer weights not larger than c, we compute a minimum Steiner Tree in \(\mathcal{O}^{\star}(2^{k}c)\) time and \(\mathcal{O}^{\star}(c)\) space, where the \(\mathcal{O}^{\star}\) notation omits terms bounded by a polynomial in the input-size. We obtain the result by defining a generalization of walks, called branching walks, and combining it with the Inclusion-Exclusion technique. Using this combination we also give \(\mathcal{O}^{\star}(2^{n})\)-time polynomial space algorithms for Degree Constrained Spanning Tree, Maximum Internal Spanning Tree and #Spanning Forest with a given number of components. Furthermore, using related techniques, we also present new polynomial space algorithms for computing the Cover Polynomial of a graph, Convex Tree Coloring and counting the number of perfect matchings of a graph.
Similar content being viewed by others
Avoid common mistakes on your manuscript.
1 Introduction
Since \(\mathcal{P}\) is believed to be not equal to \(\mathcal{NP}\), it is accepted that algorithms solving \(\mathcal{NP}\)-hard problems use super-polynomial, or even exponential, time. This justifies the study of moderately exponential time algorithms: algorithms that solve \(\mathcal{NP}\)-hard problems exactly, but run in exponential time in the worst case. Naturally the challenge still is to get the worst-case complexity as low as possible, and this question already has given rise to many non-trivial algorithms. See for example the survey by Woeginger [20].
Many of these algorithms also use exponential space. In fact, the time/space-usage ratio is polynomial in the input (i.e. the running time is bounded by a polynomial function of the space usage). It is expected that these algorithms are not practical even for small problem-instances, since they tend to run out of memory, require lot of (slow) disk access, and hardly allow parallel execution. Therefore polynomial-space exact algorithms have already been studied for several \(\mathcal{NP}\)-hard problems [3, 7, 11, 14, 15, 20]. In this paper we focus on space usage and give improved algorithms for several problems.
In 2009, Björklund et al. [3] drew new attention to the well-known principle of Inclusion-Exclusion: They gave \(\mathcal {O}^{*}(2^{n})\)-time algorithms for several set partition problems, the most prominent one being k-Coloring. They also mention a simple adjustment to their algorithm to achieve an \(\mathcal {O}^{*}(2.24^{n})\)-time algorithm with polynomial space for k-Coloring. Also related to this are the \(\mathcal{O}^{*}(2^{n})\)-time polynomial-space algorithms for #Hamiltonian path by Karp [14] and (implicitly) Kohn et al. [15], and for #Perfect Matching by Björklund and Husfeldt [2].
Our algorithms heavily rely on the work of Björklund et al. [2–6]. The results can be read from Table 1.
Steiner Tree is one of the most well-studied \(\mathcal{NP}\)-complete problems. For this problem, the Dreyfus-Wagner [9] dynamic programming algorithm has been the fastest exact algorithm for over 30 years. However, recently Björklund et al. [4] gave an \(\mathcal{O}^{\star}(2^{k})\)-time algorithm for the variant with bounded integer weights with k terminals, and Fuchs et al. [12] gave an \(\mathcal{O}^{\star}(c^{k})\)-time algorithm for the general case, for any c>2. Both algorithms use Ω(2k) space. In 2008, Fomin et al. [11] initiated the study of polynomial space algorithms for Steiner Tree. They gave polynomial space algorithms with running times bounded by \(5.96^{k}n^{\mathcal{O}(\log k)}\) and \(\mathcal{O}^{\star}(1.60^{n})\) where n is the number of vertices in the graph. They pose the question whether Steiner Tree is fixed parameter tractable with respect to k when there is a polynomial space restriction. We answer this question affirmatively by providing an algorithm that runs in \(\mathcal{O}^{*}(2^{k})\) time and meets the restriction. Using the techniques of [11], this also leads to a polynomial-space \(\mathcal{O}^{*}(1.36^{n})\)-time algorithm.
The Max Internal Spanning Tree (MIST) and Degree Constrained Spanning Tree (DCST; also called Min-Max Degree Spanning Tree) problems are natural generalizations of Hamiltonian path. In [10], Fernau et al. ask if there exists an \(\mathcal{O}^{\star}(2^{n})\)-time algorithm to solve MIST. In [13], Gaspers et al. ask if there exists an \(\mathcal{O}^{\star}(2^{n})\)-time algorithm solving DCST. We answer both questions by giving polynomial-space algorithms with this running time.
The Cover polynomial of a directed graph, introduced by Graham and Chung [8], generalizes all problems that can be solved using two operations named deletion and contraction of edges, and is designed to be the directed analogue of the Tutte polynomial. We improve the \(\mathcal{O}^{\star}(3^{n})\)-time polynomial-space algorithm of Björklund et al. [5] to an \(\mathcal{O}^{\star}(2^{n})\)-time polynomial-space algorithm. We also give the same improvement for #Spanning forests, which is one particular case of the Tutte polynomial. For more information about the Tutte polynomial we refer to [5].
Finally, we give two new algorithms for Convex Tree Coloring and #Perfect matching (counting the number of perfect matchings of a graph). (A special case of) the Convex Tree Coloring problem was studied in [19], where a \(\mathcal {O}^{\star}(2^{k}c)\) time and \(\mathcal{O}^{\star}(c)\) space algorithm was given. We will continue this study by emphasizing the space usage aspect. Finally, we show that # Perfect matching can be solved in \(\mathcal{O}^{\star }(1.95^{n})\) time and polynomial space, improving over the previous \(\mathcal{O}^{\star }(2^{n})\) time polynomial space algorithm of Björklund and Husfeldt [2]. It is worth to mention that with exponential space, one can count perfect matchings of general graphs even in \(\mathcal{O}^{\star}(1.62^{n})\) time due to Koivisto [16].
The paper is organized as follows: After the preliminaries in Sect. 2, we revisit the principle of Inclusion-Exclusion and the well-known Hamiltonian path algorithm in Sect. 3. After this we provide in Sect. 4 a natural extension by introducing the concept of branching walks and give the resulting algorithms. In the remaining sections we prove the remaining results that are not primarily based on branching walks.
2 Preliminaries and Notation
We will use the \(\mathcal{O}^{\star}\) notation that suppresses any factor that is polynomial in the input size. For an integer i, we use [i] to denote {1,…,i}. We also use Iverson’s bracket notation: for a proposition p, [p] denotes 1 if p is true and 0 otherwise. Let G=(V,E) be a graph. We will use V(G) and E(G) for the vertices V of G and the edges E of G, respectively. The number of vertices of the input graphs is denoted by n. The graph G[X] induced by X is (i) (X,(X×X)∩E) where X⊆V, and (ii) (⋃ e∈X e,X) if X⊆E. For v∈V(G), N G (v) are all vertices adjacent to v in G and d G (v)=|N G (v)|; The subscript G is omitted if the graph is clear from the context. A walk of length k in G is a tuple W=(v 1,…,v k+1)∈V k+1 such that (v i ,v i+1)∈E for each 0<i≤k. We say W is from v if v 1=v, and W is cyclic if v 1=v k+1. Furthermore, v∈V is said to be visited by W if v i =v for some 1≤i≤k. For a rooted tree T we will use rt(T) to denote the root of T. For a vertex v∈V(T) we will also use pa(v) to denote the parent of v.
Also given a graph G 1=(V 1,E 1), a homomorphism from G 1 to G is a function φ:V 1→V such that (u,v)∈E 1 implies (φ(u),φ(v))∈E. Note that φ directly corresponds to a walk in the case that G 1 is a path. We will use the notation φ(X)={φ(u)∣u∈X} and φ(Y)={(φ(u),φ(v))∣(u,v)∈Y} for X⊆V 1 and Y⊆E 1. If G 2=(V 2,E 2) is a third graph with V 1∩V 2=∅ and φ 1:V 1→V and φ 2:V 2→V are homomorphisms, we will use φ 1∪φ 2 to denote the homomorphism V 1∪V 2→V defined by φ(v)=φ 1(v) and φ(w)=φ 2(w) with v∈V 1 and w∈V 2.
2.1 Model
We assume integers in the input are given in binary, and we will prove our results for the RAM computation model where any arithmetic operation and storing any integer is assumed to take constant time and space. However, all our results also hold in the (more realistic) RAM computation model where arithmetic operations and storing integers only take constant time and space if they are constant-sized. To see the significance, note for example that in the first model two n-bits integers can be added in constant time, while in the second it takes linear time.
3 Inclusion-Exclusion
Theorem 1
(Folklore)
Let U and R be sets and for every v∈R, let P v be a subset of U. Use \(\overline{P_{v}}\) to denote U∖P v . With the convention \(\bigcap_{i \in\emptyset}\overline{P_{i}}=U\), the following holds:
In this work, we call any application of the above theorem an Inclusion-Exclusion-formulation (IE-formulation). In the context of this paper it is convenient to use the following terminology: We refer to the set U as the universe, to R as the requirement space and to P v as a property. Moreover, given a set F⊆R, we call the task of computing \(|\bigcap_{v \in F}\overline{P_{v}}|\), the simplified problem. Note that if the simplified problem can be solved in \(\mathcal{O}^{\star}(t(n))\) time and \(\mathcal{O}^{\star} (s(n))\) space, the left-hand side of (1) can be determined in \(\mathcal{O}^{\star}(2^{n}t(n))\)-time and \(\mathcal {O}^{\star}(s(n))\) space in the straightforward manner. All algorithms in this paper will exploit this observation.
3.1 Hamiltonian Paths
To illustrate Theorem 1, we will first recall the following IE-formulation due to Karp [14] for counting Hamiltonian paths. Given a (possibly directed) graph G=(V,E), a Hamiltonian path is a walk that contains each vertex of G exactly once.Footnote 1
Theorem 2
([14])
Hamiltonian paths of a graph of n vertices can be counted in \(\mathcal{O}^{\star}(2^{n})\) time and polynomial space.
Proof
Let G=(V,E). In the context of Theorem 1, define the universe U as all walks of length n−1 in G, the requirement space R=V, and P v as all walks of length n−1 that visit vertex v, for every v∈V. With these definitions, the left-hand side of (1), |⋂ v∈V P v |, is the number of Hamiltonian paths in G. Now it remains to show how to solve the simplified problem. Given F⊆V and x∈V∖F, let w F (x,k) be the number of walks from x of length k in G[V∖F]. Then w F (x,k) admits the following recurrence:
Also, notice that
and hence the simplified problem can be solved in polynomial time using dynamic programming on (2) (the parameter F is fixed but is added for clarity). Thus it takes \(\mathcal{O}^{\star}(2^{n})\) time and polynomial space to evaluate (1), and the theorem follows. □
4 Branching Walks
Definition 1
A branching walk B in G=(V,E) is a pair (T,φ) where T is an ordered rooted tree and φ:V(T)→V is a homomorphism from T to G. For a vertex x∈V, B is from x if φ(rt(T))=x. B visits a vertex v∈V if v∈φ(V(T)). The length of B is |E(T)|.
A branching walk is a natural generalization of a walk: Notice that a branching walk (T,φ) is a walk in the special case that T is a path rooted at an endpoint. Since we will count distinct branching walks, we emphasize that two branching walks (T 1,φ 1) and (T 2,φ 2) are distinct if there is no isomorphism ψ:T 1→T 2 such that φ 1(v)=φ 2(ψ(v)) for every v∈V(T 1).
4.1 Steiner Tree
In this section we will give an extension of the technique in the previous section to obtain a new IE-formulation for the Steiner Tree problem, which is defined as follows:
Steiner Tree
- Input :
-
G=(V,E), c∈ℤ+, weight function w:E→[c]∖0 and terminals K⊆V.
- Question :
-
Is there a subtree (V′,E′) of G such that K⊆V′ and ∑ e∈E′ w(e)≤c?
Given a branching walk (T,φ), the quantity ∑ e∈E(T) w(φ(e)) is said to be its weight.
Lemma 1
Let s 0∈K. There exists a subtree S=(V′,E′) of G such that K⊆V′ and w(E′)≤c if and only if there exists a branching walk B=(T,φ) from s 0 of weight at most c such that K⊆φ(V(T)).
Proof
For the forward direction, assume S to be ordered by fixing an arbitrary order. Then define B=(S,φ), with φ:V′→V′ the identity function, and let rt(S)=s 0 (this is possible since s 0∈K⊆V(S)). Then, clearly w(φ(E(S)))≤c. For the backward direction, notice that (φ(V(T)),φ(E(T))) is connected and if we let S be a spanning tree of (φ(V(T)),φ(E(T))), it has the required properties. □
Consider the following IE-formulation: Let s 0∈K be an arbitrarily chosen terminal, and define the universe U to be the set of all branching walks (T,φ) from s 0 of weight at most c. Let the requirement space R be K. For every v∈K, define a property P v ⊆U that consists of all branching walks in U that visit v. It follows that the left-hand side of (1), |⋂ v∈K P v |, is the number of branching walks of weight at most c that contain all terminals. By Lemma 1, this quantity is larger than 0 if and only if the instance of Steiner Tree is a yes-instance. Hence we can restrict our goal to determining |⋂ v∈K P v |. For this we use Theorem 1.
Before we proceed, first let us recall a basic combinatorial problem: Let \(\mathcal{T}_{n}\) be the set of all distinct ordered rooted trees on n edges (also called the Catalan numbers). We will give a recurrence for \(|\mathcal{T}_{n}|\). Let
be the gluing operation such that T=γ(T 1,T 2) is obtained by connecting rt(T 1) and rt(T 2), setting rt(T)=rt(T 2), letting the first child of rt(T) be rt(T 1), being followed by the children of rt(T) in T 2. Clearly γ is a bijection so \(|\mathcal{T}_{n}| = \sum_{i=0}^{n-i-1} |\mathcal{T}_{i}||\mathcal{T}_{n-i-1}|\).
We now continue applying Theorem 1 by showing how the simplified problem can be solved in \(\mathcal{O}^{\star}(c)\) time and space. For F⊆K, define \(\mathcal{B}_{F}(x,W)\) to be all branching walks (T,φ) of weight at most W from x in G[V∖F], where x∈V∖F. Hence \(U=\mathcal{B}_{\emptyset}(x,c)\). Let \(b_{F}(x,W) = |\mathcal{B}_{F}(x,W)|\). First, note that the simplified problem is to compute
for a given set F⊆K of terminals. Now b F (s 0,W) can be computed in polynomial time using the following lemma in combination with dynamic programming:
Lemma 2
Let F⊆K and x∈V∖F, then
Proof
There is one branching walk B of weight 0, B=(T,φ), from x with T being a single vertex and φ mapping this single vertex to x, hence Case 4a. For the second case, define a function
by γ′((T 1,φ 1),(T 2,φ 2))=(γ(T 1,T 2),φ 1∪φ 2). Now γ′ is a bijection since γ is a bijection as stated in (3) and for the branching walk (γ(T 1,T 2),φ) it must hold that φ(rt(T 1))∈N(φ(rt(T 2))). Hence Case 4b follows. □
Theorem 3
The Steiner tree problem can be solved in \(\mathcal {O}^{\star}(2^{k}c)\) time and \(\mathcal{O}^{\star}(c)\) space.
Proof
Due to Lemma 1 the considered IE-formulation solves Steiner Tree, and we can use dynamic programming on (4b) to compute the simplified problem in \(\mathcal{O}^{\star }(c^{2})\) time. This can be further reduced to \(\mathcal{O}^{\star}(c)\) time in a standard manner with the Fast Fourier Transform. Then the theorem follows from Theorem 1. □
The following result is a consequence of Theorem 3 and the considerations of Sect. 4.2 in [11]:
Theorem 4
The Steiner Tree problem with unit weights can be solved in \(\mathcal{O}^{\star}(1.36^{n})\) time using polynomial space.
Proof
Modify Algorithm steiner as described in Sect. 4.2 in [11], except that we replace Step 4 of steiner with the algorithm due to Theorem 3. This clearly does not change the worst-case running time as claimed in Theorem 5 of [11], and it is easy to see that the new algorithm uses polynomial space. □
4.2 Degree Constrained Spanning Tree
Degree Constrained Spanning Tree (DCST)
- Input :
-
G=(V,E), 1≤c≤n.
- Question :
-
Is there a spanning tree of G with maximum degree at most c?
Analogous to Lemma 1, we will use the following lemma to reduce our problem to computing some quantity involving branching walks:
Lemma 3
There exists a spanning tree of G of maximum degree at most c if and only if there exists a branching walk B=(T,φ) of length n−1 such that φ(V(T))=V and the maximum degree of T is at most c.
Proof
For the forward direction, assume S to be a spanning tree of G of maximum degree at most c and order it by fixing an arbitrary order. Then define B=(S,φ), with φ:V(S)→V(S) the identity function, and choose rt(S) arbitrarily. For the backward direction, notice that (φ(V(T)),φ(E(T))) is a tree of maximum degree at most c. □
Now we can use the following IE-formulation: Define the universe U as all branching walks (T,φ) of length n−1 such that the maximum degree of T is at most c. Define the requirement space R=V and P v to be all branching walks in U visiting v, for every v∈V. That is, let P v ={(T,φ)∈U:v∈φ(V(T))}. For F⊆V, define \(\mathcal{D}_{F}(x,j,g)\) as all branching walks (T,φ)∈U from x of length j in G[V∖F] such that the degree of the root of T is at most g and the degree of every other vertex is at most c. Hence \(U=\bigcup_{x\in V\setminus F}\mathcal{D}_{\emptyset}(x,n-1,c)\). Let \(d_{F}(x,j,g) =|\mathcal{D}_{F}(x,j,g)|\). We apply Theorem 1, and conclude that the simplified problem is to compute the number of branching walks in the universe that avoid F, and hence
This can be done in polynomial time with dynamic programming using the following lemma:
Lemma 4
Proof
To see that Case 5a holds, notice that d F (x,0,g)=0 if g is negative since the root has a non-negative degree, and otherwise there is one branching walk (T,φ) of length zero obtained by letting T be the tree on one vertex and letting φ be the function mapping this vertex to x.
For Case 5b, define γ′((T 1,φ 1),(T 2,φ 2)) to be the branching walk (γ(T 1,T 2),φ 1∪φ 2), where γ is the gluing operation from (3). Then we claim that γ′ is a bijection
To see this, define a (c,g)-tree as a tree of maximum degree c with the degree of its root at most g, and notice that γ(T 1,T 2) is a (c,g)-tree if and only if T 1 is a (c,c−1)-tree and T 2 is a (c,g−1)-tree. Then Case 5b follows by combining with the arguments in the proof of Lemma 2. □
Theorem 5
The Degree Constrained Spanning Tree problem can be solved in \(\mathcal{O}^{\star}(2^{n})\) time and polynomial space.
Proof
Due to Lemma 3 the considered IE-formulation solves DCST, and we can use dynamic programming on (4) to compute the simplified problem in polynomial time. Then the theorem follows from Theorem 1. □
4.3 Maximum Internal Spanning Tree
A vertex of a tree is called internal if its degree is at least 2.
Maximum internal Spanning Tree
- Input :
-
G=(V,E), 1≤c≤n.
- Question :
-
Is there a spanning tree of G with at least c internal vertices?
Lemma 5
There exists a spanning tree of G with at least c internal vertices if and only if there exists a branching walk B=(T,φ) of length n−1 such that φ(V(T))=V and T has at least c internal vertices.
Proof
For the forward direction, assume S to be a spanning tree of G with at least c internal vertices and order it by fixing an arbitrary order. Define B=(S,φ), with φ:V(S)→V(S) the identity function. It clearly has the required properties. For the backward direction, notice that (V,φ(E(T))) is a spanning tree with at least c internal vertices since ϕ(E(T))=n−1. □
Consider the following IE-formulation: Define the universe U to be all branching walks (T,φ) of length n−1 such that T has at least c internal vertices. For v∈V, let P v ={(T,φ)∈U:v∈φ(V(T))}. For F⊆V and δ∈ℤ−∪{0,1,2}, define \(\mathcal{M}^{\delta}_{F}(x,j,g)\) as all branching walks (T,φ) in G[V∖F] of length j from x such that |{v∈V(T)∖rt(T):v is internal}|+[d(rt(T))≥δ]=g. Let \(m^{\delta}_{F}(x,j,g)=|\mathcal{M}^{\delta}_{F}(x,j,g)|\), then
Lemma 6
Proof
To see that Case 6a holds, notice that there is only one branching walk of length 0 from x and its tree-part is a single vertex, so g must be equal to 1 if δ≤0 and equal to 0 otherwise by definition. For Case 6b, first define γ′((T 1,φ 1),(T 2,φ 2)) as the branching walk (γ(T 1,T 2),φ 1∪φ 2), where γ is the gluing operation from (3). Then we claim that γ′ is a bijection
To see this, note that γ(T 1,T 2) has g′ internal vertices not equal to the root if and only if T 1 has \(g'_{1}\) and T 2 has \(g'_{2}\) internal vertices not equal to the root with \(g'_{1}+g'_{2} = g'\) and
Hence the δ and g accumulators are modified correctly. Then Case 6b follows by combining with the arguments in the proof of Lemma 2. □
Theorem 6
The Maximum Internal Spanning Tree problem can be solved in \(\mathcal{O}^{\star}(2^{n})\) time and polynomial space.
Proof
Use the IE-formulation as described above. The simplified problem is to compute \(|\bigcap_{v \in F}\overline{P_{v}}|\), which is equal to \(\sum _{s \in V \setminus F}m^{2}_{F}(s,n-1,c)\) since the root needs at least two neighbors in order to be an internal vertex. It follows from Lemma 5 that there exists B∈⋂ v∈V P v if and only if there exists a spanning tree with at least c leaves. □
4.4 Counting Spanning Forests
Define a c-spanning forest to be an acyclic spanning subgraph with exactly c connected components. In this section we will address the following problem:
#Spanning Forests
- Input :
-
G=(V,E), 1≤c≤n.
- Question :
-
The number of acyclic spanning subgraphs of G with exactly c connected components.
Assume that a total ordering ≺ on the vertex set V is given. Given a subset X⊆V, let minX be the minimum element of X with respect to ≺.
Definition 2
A sorted branching walk is a branching walk (T,φ) such that for every v∈V(T) with children c 1,…,c l , numbered with respect to the order of T, φ(c i )≺φ(c j ) for every i<j and φ(rt(v))=minφ(V(T)).
It can be noted that the definition implies no two children of vertex v∈V(T) can be mapped to same vertex in G.
Lemma 7
There is a bijection between the set of all subtrees S of G, and the set of all sorted branching walks B=(T,φ) of length |φ(E(T))| such that φ(E(T)) induces a subtree.
Proof
Note that it is sufficient to show that for every subtree S of G, there is exactly one a sorted branching walk B=(T,φ) of length |φ(E(T))| such that φ(E(T))=E(S).
Since φ(V(T))=V(S) and B is sorted, we know that φ(rt(T))=minV(T). Since |E(S)|=|E(T)|, φ is a bijection and hence S and T are isomorphic. Moreover φ(c i )≺φ(c j ) whenever c i occurs before c j as a child of a vertex in T since B is sorted. This implies that T and φ are uniquely determined by S. □
Define \(\mathcal{B}_{F}(l)\) to be all sorted branching walks (T,φ) of length l in G such that F∩φ(V(T))=∅. Also, define \(b_{F}(l)=|\mathcal{B}_{F}(l)|\).
Lemma 8
The number of c-spanning forests is equal to
Proof
We apply Theorem 1. Define U to be the set of all families f of sorted branching walks of total length n−c (that is, the sum of the length of all members of f is n−c). Let the requirement space be V, and for every v∈V define P v to be all elements f∈U such that there is (T,φ)∈f with v∈φ(V(T)). It is not hard to see that a term of the summation of (7) (ignoring (−1)|F|) is equal to \(|\bigcap_{v \in F}\overline{P_{v}}|\).
Applying Theorem 1, it remains to show that the number of c-spanning forests is |⋂ v∈V P v |. To see this, notice that for a family of sorted branching walks f={(T 1,φ 1),…,(T c ,φ c )}, \(\bigcup_{i=1}^{c}\varphi_{i}(V_{i}) = V\) if and only if \(\bigcup_{i=1}^{c}\varphi_{i}(E_{i})\) is a c-spanning forest. Then every c-spanning forest corresponds to exactly one set of branching walks of total length n−c due to Lemma 7. The lemma follows. □
Define \(\mathcal{B}_{F}(x,j,g)\) as all sorted branching walks (T,φ) from x of length j such that φ(V(T))∩F=∅ and no child of the root of T is mapped to one of the first g−1 neighbors of x in G[V∖F] with respect to the ordering ≺. Define \(b_{F}(x,j,g)=|\mathcal {B}_{F}(x,j,g)|\). Use \(N_{F}^{q}(x)\) to denote the qth element of the set N(x)∖F with respect to the ordering ≺.
Lemma 9
Proof
For Case 8a, notice there is exactly one branching walk (T,φ) with T being a single vertex and with φ mapping this vertex to x.
To see Case 8b, notice that since g>|N(x)∩F|, in any branching walk in \(\mathcal{B}_{F}(x,j,g)\) the root can not have any children but since j>0 this must be the case, and hence such a branching walk does not exist.
For Case 8c, first notice that \(\mathcal{B}_{F}(x,j,g+1)\) are exactly all branching walks \((T,\varphi) \in\mathcal {B}_{F}(x,j_{1}+j_{2}+1,g)\) where no child of the root of T is mapped to \(N_{F}^{g}(x)\). Define γ′((T 1,φ 1),(T 2,φ 2)) as the branching walk (γ(T 1,T 2),φ 1∪φ 2), where γ is the gluing operation from (3). Then it is not too hard to see that γ′ is a bijection
since γ′(B 1,B 2) and \(\gamma'(B'_{1},B'_{2})\) are distinct whenever either B 1 and \(B^{'}_{1}\) or B 2 and \(B'_{2}\) are distinct. Then Case 8c follows by combining with the arguments in the proof of Lemma 2. □
Theorem 7
The #Spanning forests problem can be solved in \(\mathcal {O}^{\star}(2^{n})\) time and polynomial space.
Proof
Let \(\overline{F} = V \setminus F\) and \(b_{F}(l) = \sum_{x\in \overline{F}} b_{\overline{F}[x]}(x,l,1)\), where \(\overline{F}[x]\) stands for the set of all elements e in \(\overline{F}\) such that x≺e. Using dynamic programming in combination with Lemma 9, the values b F (l) can be computed for every 1≤l≤n for a fixed F. Also using standard dynamic programming, the simplified problem (that is, the summand of (8a) ignoring the (−1)|F|) can be computed in polynomial time. Hence (8a) can be evaluated within the claimed resource bounds and the theorem follows from Lemma 8. □
5 Cover Polynomial
We use \(x^{\underline{i}}\) for the falling factorial \(\frac {x!}{(x-i)!}\). The cover polynomial of a directed graph D=(V,A) can be defined as (see also [5, 8]):
where c(i,j) is defined as the number of ways to partition V into i directed paths and j directed cycles of D. In this section we will address the following problem:
Cover Polynomial
- Input :
-
A graph G.
- Question :
-
The coefficients c(i,j) for every 0≤i,j≤n.
Since paths and cycles with l edges contain l+1 and l vertices respectively, the sum of the lengths of the paths and cycles in such a partition will be n−i. Moreover, if V is covered by i paths and j cycles with lengths summing up to n−1, the path and cycles are disjoint because of the size restriction. Recall from Sect. 3.1 that w F (s,j) is the number of walks starting from s of length j avoiding F. Similarly, define w F (j) as all walks of length j avoiding F and \(\hat{w}_{F}(j)\) as the number of cyclic walks of length j avoiding F.
Lemma 10
Proof
We apply Theorem 1. Define U as all combinations of i walks and j cyclic walks with lengths summing up to exactly n−i. Define the requirement space to be V, and for every v∈V let P v be all combinations of walks and cyclic walks in U such that at least one of the (cyclic) walks visits v. It is easy to see that each summand (ignoring the (−1)|F|) equals \(|\bigcap_{v \in F}\overline {P_{v}}|\), and since |⋂ v∈F P v |=c(i,j) by the above discussion, the lemma follows from Theorem 1. □
Theorem 8
The Cover Polynomial problem can be solved in \(\mathcal {O}^{\star}(2^{n})\) time and polynomial space.
Proof
By using minor modifications of the dynamic programming algorithm using (2), for every F⊆V and 0≤j≤n, both w F (j) and \(\hat{w}_{F}(j)\) can be computed in polynomial time. Using straightforward dynamic programming, the simplified problem can be obtained from the values w F (j) and \(\hat{w}_{F}(j)\). Using this, (9) can be evaluated within the claimed resource bounds. □
6 Convex Tree Coloring
In this section we solve a generalization of the Convex Recoloring problem studies in [19] and improve upon one of their results. Let T=(V,E) be a tree and w:E(T)×[k]×[k]→[c]. A k-coloring is a function γ:V→[k]. As before, for X⊆V let φ(X) be ⋃ v∈X φ(v). The coloring γ is minimal if γ(V)=[k]. Define w(γ)=∑(u,v)∈E(T) w((u,v),γ(u),γ(v)). The coloring γ is convex if for every x,y,z∈V such that y is in the (unique) path from x to z it holds that γ(x)=γ(z) implies γ(x)=γ(y), or more informally: γ is convex if all its color classes induce a connected subtree. It is worth mentioning that in [19] the slightly different Convex Tree Recoloring (CTR) was studied, but that CTR is a special case of CTC.
Convex Tree Coloring (CTC)
- Input :
-
A tree T=(V,E) with a weight function w:E×[k]×[k]→[c].
- Question :
-
Is there a convex coloring γ:V→[k] with w(γ)≤c?
Let us first note that we can safely assume that T is in fact binary, since if it is not, we can insert vertices and force them to have the same color by using an appropriate weight function. Also note we can restrict ourselves to minimal colorings by k vertices of degree one to arbitrary vertices and setting w(⋅,⋅,⋅=)=0. Hence the colors assigned to the added vertices does not matter at all, but if a color is not minimal, it can be extended to a minimal one using the new added vertices. Thus we can restrict ourselves to solving the following variant:
Minimal Convex Binary Tree Coloring (MCBTC)
- Input :
-
A binary tree T=(V,E) with a weight function w:E×[k]×[k]→[c].
- Question :
-
Is there a minimal convex coloring γ:V→[k] with w(γ)≤c?
For a given coloring γ, use pce(γ) to denote the number of poly-chromatic edges, i.e. the number of edges (y,z)∈E(T) such that φ(y)≠φ(z).
Lemma 11
The instance of MCBTC is a yes-instance if and only if there exists a k-coloring γ such that pce(γ)=k−1, and w(γ)≤c.
Proof
In a tree, the fact that γ gives k monochromatic connected components is equivalent with pce(γ)=k−1 since after contracting all monochromatic edges, we again obtain a tree. □
Using Lemma 11, we can reduce our problem to determining the existence of a minimal k-coloring with k−1 polychromatic edges. We will use Theorem 1: For notational convenience add a vertex to T, make it adjacent to an arbitrarily chosen other vertex of T and let the added vertex be the root of T. For the added edge, set all corresponding weights to 0. Define the universe U={γ:V→[k]∣pce(γ)=k−1∧w(γ)≤c}. Define the requirement space to be [k] with for each 1≤v≤k a requirement P v being all elements γ of U with v∈γ(V). Then |⋂ v∈[l] P v |>0 if and only if the current instance is a yes-instance by Lemma 11. Define \(\mathcal {C}_{F}(s,W,g,p)\) as all k-colorings γ of T[s] with pce(γ)=g+[γ(rt(T))≠p], γ(V(T[s]))∩F=∅ and w(γ)≤W and let \(c_{F}(s,W,g,p)=|\mathcal{C}_{F}(s,W,g,p)|\). Also note that \(|\bigcap_{v \in F}\overline{P_{v}}|c_{F}(\mathtt{rt}(T),c,k-1,1)\) (the color of the root is not relevant here so we just set it to 1). It remains to show how to compute c F (rt(T),c,k−1,p):
Lemma 12
where
Proof
For Case 10a, the only possible valid coloring is the one where γ(s)=γ(pa(s)). For Case 10b, any coloring γ with γ(s)≠γ(pa(s)) and low enough cost is counted. For Case 10c, no such a coloring exists since a leaf is only adjacent to one edge. For Case 10d, s is not a child and hence has two children s 1 and s 2. It is not too hard to see that the term in (11) is the number of colorings in \(\mathcal{C}_{F}(s,W,g,p)\) where γ(s)=γ(pa(s)) and that the term in (12) is the number of colorings in \(\mathcal{C}_{F}(s,W,g,p)\) where γ(s)≠γ(pa(s)). □
Theorem 9
The Convex Tree Coloring problem can be solved in \(\mathcal {O}^{\star}(2^{k}c)\) time and \(\mathcal{O}^{\star}(c)\) space.
Proof
By Lemma 11 and the discussion before it we can reduce Convex Tree Coloring to finding a minimal k-coloring γ with k−1 polychromatic edges and w(γ)≤c. This can be solved using the IE-formulation as discussed above. The simplified problem can be solved in \(\mathcal{O}^{\star}(c^{2})\) time and \(\mathcal{O}^{\star}(c)\) using Lemma 1 and using standard Fast Fourier Transform techniques this can be reduced to \(\mathcal{O}^{\star}(c)\) time and space. The theorem then follows from Theorem 1. □
7 Counting Perfect Matchings
In this section we will count the number of perfect matchings in a graph G=(V,E). We let |V|=2n. First, we arbitrarily partition the vertex set V into A and B (thus, A∪B=V, and A∩B=∅), with |A|=|B|=n. Let an l-matching of G be a perfect matching M⊆E such that |{e∈M:|e∩A|=1}|=l, i.e. a perfect matching containing exactly l edges with exactly one endpoint in A.
We will need the following simple lemma:
Lemma 13
([18], Lemma 4.10; [1], Theorem 4)
Given an independent set S⊆V, the number of perfect matching of G can be computed in \(\mathcal{O}^{\star}(2^{2n-|S|})\).
We will first give two algorithms that we combine later. Both algorithms solve the same problem, but with different running times. Afterwards we show how to combine the two to obtain the main result of this section.
Lemma 14
l-matchings can be counted in \(\mathcal{O}^{*}\bigl(\binom{n}{ l}2^{n}\bigr)\) time and polynomial space.
Proof
Given a perfect matching M, define
That is, L(M) is the set of all vertices in A that are matched with a vertex in b in M. Then, if we define f(X) as the number of perfect matchings M such that L(M)=X, then we can compute the number of l-matchings according to
Define g(X,B) as the number of perfect matchings in the graph obtained from G[X∪B] by making X into an independent set. Then f(X)=pm(A∖X)g(X,B) where pm(A∖X) is the number of perfect matching in G[A∖X]. Using Lemma 13 both pm(A∖X) and g(X,B) can be computed in polynomial space and time \(\mathcal {O}^{\star}(2^{n -l})\) and \(\mathcal{O}^{\star}(2^{n})\) respectively. Hence the lemma follows. □
We proceed to the next algorithm:
Lemma 15
l-matchings can be counted in \(\mathcal{O}^{*}\bigl({n\choose\frac{n}{2} + \frac{l}{2}}2^{n}\bigr)\) time and polynomial space.
Proof
Arbitrarily choose a total ordering ≺ on A and use the shorthand \(k=\frac{n+l}{2}\). We will use Theorem 1: Define the universe U to be
and the requirement space to be V. Define P v to be
for each v∈V. We claim that |⋂ v∈V P v | is \(2^{n}(\frac {(n-l)}{2})!\) times the number of l-matchings. To see this, notice that for every l-matching there are exactly \(2^{n}(\frac{n-l}{2})!\) elements in \(|\bigcap_{v \in F}\overline{P_{v}}|\) obtained by all permutations of the \(\frac{n-l}{2}\) edges contained in G[B] and then flipping the order of the vertices of the edge. Moreover, every element in \(|\bigcap_{v \in F}\overline{P_{v}}|\) can obtained in this way from exactly one l-matching.
Thus, combining Theorem 1 with the above we obtain that the number of l-matchings is
We proceed by trimming (see also [6]): Observe that \(|\bigcap_{v \in F}\overline{P_{v}}|=0\) if |F∩A|>(n−k) since u 1,…,u k ∈A are distinct for any ((u 1,v 1),…,(u n ,v n ))∈U. Hence for evaluating (14), we can restrict ourselves to sum over F⊆V such that |F∩A|≤(n−k). The number of F⊆V such that |F∩A|≤(n−k) is \(\mathcal{O}^{\star }({n \choose n-k}2^{n})=\mathcal{O}^{\star}({n \choose k}2^{n})\). Hence to prove the lemma, it suffices to show that \(|\bigcap_{v \in F}\overline{P_{v}}|\) can be computed in polynomial time for a fixed F.
Let {a 1,…,a n } be obtained by sorting A with respect to the total ordering ≺. Define
Then we have \(|\bigcap_{v \in F}\overline{P_{v}}|=p_{F}(n,k)|E(G[B\setminus F])|^{n-k}\) and it is easy to see that p F (n,k) can be computed according to
hence p F (n,k) and \(|\bigcap_{v \in F}\overline{P_{v}}|\) can be computed in polynomial time and the lemma follows. □
Theorem 10
The number of perfect matchings of a graph G can be computed in \(\mathcal{O}^{\star}(1.95^{|V(G)|})\) time and polynomial space.
Proof
Sum over all 0≤l≤n over the number of l-matchings computed by the algorithm of minimum running time among the algorithms of Lemmas 14 and 15. The running time of this algorithm is
Since \(0 \leq p \leq p' \leq\frac{n}{2}\) implies \(\binom{n }{ p} \leq \binom{n }{p'}\), (16) is maximized if \(\min\{ l, \frac{n}{2} - \frac{l}{2} \}\) is maximized, which is at \(l=\frac {n}{3}\). Hence (16) is equal to \(\binom{n}{ \frac {n}{3}}2^{n} = \mathcal{O}^{\star}(1.89^{n}2^{n})\), where the latter is due to standard approximations (see for example Lemma 4 of [7]). □
8 Further Remarks
It is worth mentioning that, as the proofs in this paper might suggest, the results of this paper admit a generalization. The study of such a generalization was initiated in the conference version of this work and finally given in [17]. In the latter Theorem 3 is also improved by giving a \(\mathcal{O}^{\star }(2^{k}c)\) time and polynomial space algorithm.
Notes
Note that this is slightly different from the usual definition, since a path corresponds to two walks in both directions. So we will actually obtain a number that is exactly twice the number of Hamiltonian paths.
References
Amini, O., Fomin, F.V., Saurabh, S.: Counting subgraphs via homomorphisms. In: Proceedings of the 36th International Colloquium on Automata, Languages and Programming (ICALP), Part I. Lecture Notes in Computer Science, vol. 5555, pp. 71–82. Springer, Berlin (2009)
Björklund, A., Husfeldt, T.: Exact algorithms for exact satisfiability and number of perfect matchings. Algorithmica 52(2), 226–249 (2008)
Björklund, A., Husfeldt, T., Koivisto, M.: Set partitioning via inclusion-exclusion. SIAM J. Comput. 39(2), 546–563 (2009)
Björklund, A., Husfeldt, T., Kaski, P., Koivisto, M.: Fourier meets Möbius: fast subset convolution. In: Proceedings of the 39th Annual ACM Symposium on Theory of Computing (STOC), pp. 67–74. ACM, New York (2007)
Björklund, A., Husfeldt, T., Kaski, P., Koivisto, M.: Computing the Tutte polynomial in vertex-exponential time. In: Proceedings of the 49th Annual IEEE Symposium on Foundations of Computer Science (STOC), pp. 677–686. IEEE Comput. Soc., Los Alamitos (2008)
Björklund, A., Husfeldt, T., Kaski, P., Koivisto, M.: Trimmed Moebius inversion and graphs of bounded degree. Theory Comput. Syst. 47(3), 637–654 (2010)
Bodlaender, H.L., Kratsch, D.: An exact algorithm for graph coloring with polynomial memory. Technical Report UU-CS-2006-015, Department of Information and Computing Sciences, Utrecht University (2006)
Chung, F.R.K., Graham, R.L.: On the cover polynomial of a digraph. J. Comb. Theory, Ser. B 65(2), 273–290 (1995)
Dreyfus, S.E., Wagner, R.A.: The Steiner problem in graphs. Networks 1, 195–207 (1972). doi:10.1002/net.3230010302
Fernau, H., Gaspers, S., Raible, D.: Exact and parameterized algorithms for max internal spanning tree. In: Proceedings of the 35th International Workshop on Graph-Theoretic Concepts in Computer Science (WG). Lecture Notes in Computer Science, vol. 5911, pp. 100–111. Springer, Berlin (2009)
Fomin, F.V., Grandoni, F., Kratsch, D.: Faster Steiner tree computation in polynomial-space. In: Proceedings of the 16th Annual European Symposium on Algorithms (ESA). Lecture Notes in Computer Science, vol. 5193, pp. 430–441. Springer, Berlin (2008)
Fuchs, B., Kern, W., Mölle, D., Richter, S., Rossmanith, P., Wang, X.: Dynamic programming for minimum Steiner trees. Theory Comput. Syst. 41(3), 493–500 (2007)
Gaspers, S., Saurabh, S., Stepanov, A.A.: A moderately exponential time algorithm for full degree spanning tree. In: Proceedings of the 5th International Conference on Theory and Applications of Models of Computation (TAMC). Lecture Notes in Computer Science, vol. 4978, pp. 479–489. Springer, Berlin (2008)
Karp, R.M.: Dynamic programming meets the principle of inclusion and exclusion. Oper. Res. Lett. 1, 49–51 (1982)
Kohn, S., Gottlieb, A., Kohn, M.: A generating function approach to the traveling salesman problem. In: Proceedings of the 1977 Annual Conference (ACM), pp. 294–300. ACM, New York (1977). doi:10.1145/800179.810218
Koivisto, M.: Partitioning into sets of bounded cardinality. In: Proceedings of the 4th International Workshop Parameterized and Exact Computation (IWPEC). Lecture Notes in Computer Science, vol. 5917, pp. 258–263. Springer, Berlin (2009)
Lokshtanov, D., Nederlof, J.: Saving space by algebraization. In: Proceedings of the 42nd ACM Symposium on Theory of Computing (STOC), pp. 321–330. ACM, New York (2010)
Nederlof, J.: Inclusion exclusion for hard problems. Master’s thesis, Utrecht University (August 2008)
Ponta, O., Hüffner, F., Niedermeier, R.: Speeding up dynamic programming for some \(\mathcal{NP}\)-hard graph recoloring problems. In: Proceedings of the 5th International Conference on Theory and Applications of Models of Computation (TAMC), pp. 490–501. Springer, Berlin (2008)
Woeginger, G.J.: Space and time complexity of exact algorithms: some open problems (invited talk). In: First International Workshop on Parameterized and Exact Computation (IWPEC). Lecture Notes in Computer Science, vol. 3162, pp. 281–290. Springer, Berlin (2004)
Open Access
This article is distributed under the terms of the Creative Commons Attribution License which permits any use, distribution, and reproduction in any medium, provided the original author(s) and the source are credited.
Author information
Authors and Affiliations
Corresponding author
Additional information
A preliminary version of parts this work appeared in the Proceedings of ICALP 2009.
This work is supported by the Research Council of Norway.
Rights and permissions
Open Access This article is distributed under the terms of the Creative Commons Attribution 2.0 International License (https://creativecommons.org/licenses/by/2.0), which permits unrestricted use, distribution, and reproduction in any medium, provided the original work is properly cited.
About this article
Cite this article
Nederlof, J. Fast Polynomial-Space Algorithms Using Inclusion-Exclusion. Algorithmica 65, 868–884 (2013). https://doi.org/10.1007/s00453-012-9630-x
Received:
Accepted:
Published:
Issue Date:
DOI: https://doi.org/10.1007/s00453-012-9630-x