Fast Polynomial-Space Algorithms Using Inclusion-Exclusion

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.


Introduction
Since P is believed to be not equal to N P, it is accepted that algorithms solving N P-hard problems use super-polynomial, or even exponential, time.This justifies the study of moderately exponential time algorithms: algorithms that solve N P-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 Table 1 The results of this work compared to the relevant previous results.The number of vertices on the input graph is denoted by n.The running times of the algorithms of this work are given in the last column.These new algorithms use polynomial space, except the ones indicated with the * , which use O (c) space

Problem
Poly-space By Exp-space By Results STEINER TREE with unit weights 5.96 k n O(log k) [11] O (1.60 n ) [11] O (1.36 n ) [11] O (1.36 n ) STEINER TREE 5.96 k n O(log k) [11] O ((2 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 N P-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 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 O * (2.24 n )-time algorithm with polynomial space for k-COLORING.Also related to this are the O * (2 n )-time polynomialspace algorithms for #HAMILTONIAN PATH by Karp [14] and (implicitly) Kohn et al. [15], and for #PERFECT MATCHING by Björklund and Husfeldt [2].
STEINER TREE is one of the most well-studied N P-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 O (2 k )-time algorithm for the variant with bounded integer weights with k terminals, and Fuchs et al. [12] gave an O (c k )-time algorithm for the general case, for any c > 2. Both algorithms use (2 k ) 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 O(log k) and O (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 O * (2 k ) time and meets the restriction.Using the techniques of [11], this also leads to a polynomial-space 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 O (2 n )-time algorithm to solve MIST.In [13], Gaspers et al. ask if there exists an O (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 O (3 n )-time polynomial-space algorithm of Björklund et al. [5] to an O (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 O (2 k c) time and O (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 O (1.95 n ) time and polynomial space, improving over the previous O (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 O (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.

Preliminaries and Notation
We will use the O 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) 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
Note that ϕ directly corresponds to a walk in the case that G 1 is a path.We will use the notation ϕ

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.

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 P v to denote U \ P v .With the convention i∈∅ P i = U , the following holds: ( In this work, we call any application of the above theorem an Inclusion-Exclusionformulation (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 | v∈F P v |, the simplified problem.Note that if the simplified problem can be solved in O (t (n)) time and O (s(n)) space, the left-hand side of (1) can be determined in O (2 n t (n))-time and O (s(n)) space in the straightforward manner.All algorithms in this paper will exploit this observation.

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.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 O (2 n ) time and polynomial space to evaluate (1), and the theorem follows.

Branching Walks
where T is an ordered rooted tree and ϕ : 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

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: 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

)). 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 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 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 We now continue applying Theorem 1 by showing how the simplified problem can be solved in O (c) time and space.For F ⊆ K, define B F (x, W ) to be all branching walks (T , ϕ) of weight at most 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: 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 γ : The following result is a consequence of Theorem 3 and the considerations of Sect.4.2 in [11]: The STEINER TREE problem with unit weights can be solved in O (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.

DEGREE CONSTRAINED SPANNING TREE (DCST)
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 such that the degree of the root of T is at most g and the degree of every other vertex is at most c.
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: 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 O (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.

Maximum Internal Spanning Tree
A vertex of a tree is called internal if its degree is at least 2.

MAXIMUM INTERNAL SPANNING TREE
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 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 O (2 n ) time and polynomial space.
Proof Use the IE-formulation as described above.The simplified problem is to compute | v∈F P v |, which is equal to s∈V \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.

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: 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 min X 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 )).

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 )) = min V (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 B F (l) to be all sorted branching walks (T , ϕ) of length l in G such that

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 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 )}, c i=1 ϕ i (V i ) = V if and only if c i=1 ϕ 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 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) = |B F (x, j, g)|.Use N q F (x) to denote the qth element of the set N(x) \ F with respect to the ordering ≺.
b F (x, j, g + 1) 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 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 B F (x, j, g + 1) are exactly all branching walks (T , ϕ) ∈ B F (x, j 1 + j 2 + 1, g) where no child of the root of T is mapped to N g F (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 γ (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 O (2 n ) time and polynomial space.
, where F [x] stands for the set of all elements e in 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.

Cover Polynomial
We use x i for the falling factorial x! (x−i)! .The cover polynomial of a directed graph D = (V , A) can be defined as (see also [5,8]): i,j c(i, j )x i y j 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 ŵ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 | v∈F 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 O (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 ŵ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 ŵF (j ).Using this, (9) can be evaluated within the claimed resource bounds.

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 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 : Question Is there a convex coloring γ : 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 : 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 = {γ : ĉF (s, j, g, p) otherwise, (10d) where ĉF (s, W, g, p) = 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 C F (s, W, g, p) where γ (s) = γ (pa(s)) and that the term in (12) is the number of colorings in C F (s, W, g, p) where γ (s) = γ (pa(s)).

Theorem 9
The CONVEX TREE COLORING problem can be solved in O (2 k c) time and O (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 O (c 2 ) time and O (c) using Lemma 1 and using standard Fast Fourier Transform techniques this can be reduced to O (c) time and space.The theorem then follows from Theorem 1.

Counting Perfect Matchings
In this section we will count the number of perfect matchings in a graph G = (V , E).
We 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 O (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 O * n l 2 n 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 O (2 n−l ) and O (2 n ) respectively.Hence the lemma follows.
We proceed to the next algorithm: Proof Arbitrarily choose a total ordering ≺ on A and use the shorthand k = 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 (u 1 , v 1 ), . . ., (u n , v n ) ∈ U v ∈ {u 1 , . . ., u n } ∪ {v 1 , . . ., v n } for each v ∈ V .We claim that | v∈V P v | is 2 n ( (n−l) 2 )! times the number of lmatchings.To see this, notice that for every l-matching there are exactly 2 n ( n−l 2 )! elements in | v∈F P v | obtained by all permutations of the n−l 2 edges contained in G[B] and then flipping the order of the vertices of the edge.Moreover, every element in | v∈F 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 | v∈F 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 Hence to prove the lemma, it suffices to show that | v∈F 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 and it is easy to see that p F (n, k) can be computed according to Since 0 ≤ p ≤ p ≤ n 2 implies n p ≤ n p , ( 16) is maximized if min{l, n 2 − l 2 } is maximized, which is at l = n 3 .Hence ( 16) is equal to n n 3 2 n = O (1.89 n 2 n ), where the latter is due to standard approximations (see for example Lemma 4 of [7]).

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 O (2 k c) time and polynomial space algorithm.

Theorem 2 (
[14]) Hamiltonian paths of a graph of n vertices can be counted in O (2 n ) time and polynomial space.
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 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) = |C F (s, W, g, p)|.Also note that | v∈F P v |c F (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): 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.

Lemma 15 l 2 + l 2 2
-matchings can be counted in O * n n n time and polynomial space.

p F (r − 1 ,Theorem 10
m) + d G[V \F ] p F (r − 1, m − 1) otherwise, (15b) hence p F (n, k) and | v∈F P v | can be computed in polynomial time and the lemma follows.The number of perfect matchings of a graph G can be computed in O (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 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.The STEINER TREE problem can be solved in O (2 k c) time and O (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 O (c 2 ) time.This can be further reduced to O (c) time in a standard manner with the Fast Fourier Transform.Then the theorem follows from Theorem 1.