Abstract 1 Introduction 2 Preliminaries 3 Counting k-paths 4 Counting trees 5 Conclusion References

Deterministically Counting k-Paths and Trees Parameterized by Treewidth in Single-Exponential Time

Jonne Visser ORCID Utrecht University, The Netherlands Hans L. Bodlaender ORCID Utrecht University, The Netherlands
Abstract

In this paper, we give new and faster deterministic algorithms to count the number of k-paths and trees in host graphs of bounded treewidth. Our algorithms use time that is single-exponential in the treewidth, and employ the determinant method from [4]. Modifications of the algorithms count in single-exponential time the number of k-paths between specified end-points, the number of k-cycles, and the number of trees with k vertices that are a subgraph of the host graph.

Keywords and phrases:
Parameterized Complexity, Counting Subgraphs, #k-path, Dynamic Programming, Tree Decomposition, Determinant Method
Copyright and License:
[Uncaptioned image] © Jonne Visser and Hans L. Bodlaender; licensed under Creative Commons License CC-BY 4.0
2012 ACM Subject Classification:
Theory of computation Parameterized complexity and exact algorithms
Editors:
Akanksha Agrawal and Erik Jan van Leeuwen

1 Introduction

In this paper, we consider the problem of counting subgraphs isomorphic to a graph H in a given graph G. This well-studied problem has several applications, e.g., in bio-informatics when modeling biological networks [1, 12, 13] or when analyzing social networks [8, 17]. The frequency of specific subgraphs may give valuable insights into the functionality of a network and can be used to test the quality of network models.

Counting problems are generally much harder than their decision counterparts, asking whether a subgraph H occurs in G at all. Indeed, decision problems with a trivial solution may have a counting variant that is as hard as the counting variant of some NP-complete problems, and many counting problems are #P-Complete [14]. For this reason, most research focuses on the parameterized complexity of subgraph counting problems.

To categorize the complexity of intractable parameterized counting problems, a complexity class hierarchy #W[t],t1 analogous to the W-hierarchy of Downey and Fellows was described independently by Flum and Grohe [9] and McCartin [11]. Notably, Flum and Grohe showed that, while deciding whether there is a path of length k in a given graph is FPT, counting k-paths parameterized by k is #W[1]-complete. This makes it unlikely that there is a polynomial time algorithm that counts k-paths even when k is small.

The main contributions of this paper are new and faster algorithms to count respectively paths and trees in graphs of bounded treewidth. First, an O(18twk2n) time Dynamic Program for counting the number of k-paths in a host graph G is presented. Although the counting of k-paths parameterized by path length k has been researched a lot [2, 3, 5, 10], exact algorithms parameterized by treewidth have seen little attention. The currently fastest exact algorithm for counting k-paths parameterized by treewidth is a well-known elementary Dynamic Program using a tree decomposition of G to solve the problem in twO(tw)poly(k,n) time. The presented Dynamic Program improves on this by providing a single-exponential time algorithm for the problem, meaning that a solution is found in O(cO(tw)poly(k,n)) time for a constant c.

The second contribution of this paper is an O(tw)(k)O()n time algorithm for #k,-Tree, the problem of counting the number of copies of a tree T with k vertices and leaves in a host graph G. This result generalizes the k-path counting algorithm in the first part of the paper. Since k-paths are trees, the counting of labeled trees is at least as hard as counting k-paths, showing #W[1]-hardness when parameterized by k. Verstraete and Mubayi proved a lower bound for the number of labeled copies of tree T in host graph G of (1ϵ)nd(d1)(dt+1), where n is the number of vertices in G, d is the average degree of vertices in G, t is the number of edges in T and ϵ=(4t)5d2, provided that dt [16]. The current fastest exact algorithm to solve #k,-Tree parameterized by treewidth is an elementary Dynamic Program that takes kO(tw)2O(k)n time. The presented algorithm, therefore, improves on this running time when is significantly smaller than k and even provides a 2O(tw)poly(k,n) time algorithm when is constant.

The techniques presented in this paper build upon the determinant method introduced by Bodlaender et al. in 2015 [4]. This method counts classes of subgraphs that are isomorphic to trees and include a specific vertex, such as Hamiltonian Paths and Steiner Trees. To develop single-exponential time algorithms for #k-Path and #k,-Tree, we relax the constraint of including a specific vertex. This modification enables the counting of subgraphs without restrictions on which vertices are included. Additionally, we demonstrate that the determinant method can be extended to count subgraphs formed by “gluing together” simpler graphs.

Furthermore, the constructed Dynamic Programs can be relatively straightforwardly modified to count the number of fixed end-point k-paths and k-cycles, and to solve #k-Tree (asking for the number of occurrences of all trees with k edges in host graph G) in O(18twk4n) time. This last problem is proven to be #W[1]-hard when parameterized by k by Brand and Roth [6].

2 Preliminaries

Nice Tree decompositions

In this paper, we utilize nice tree decompositions, following the definition provided by Cygan et al. [7].

Counting trees using determinants

This section explores a determinant-based method for counting subgraphs, developed by Bodlaender et al. [4].

Given an undirected graph G=(V,E) and a nice path or tree decomposition 𝕋 of G with width pw or tw respectively, define the incidence matrix of G as follows:

Definition 1 (incidence matrix).

The incidence matrix A=(av,e) of a graph G is an n×m matrix whose rows are indexed by the vertices in V and whose columns are indexed by the edges in E. Its entries are:

av,e={1,if e=(v,w) and v>w1,if e=(v,w) and v<w0,ve, (1)

where we use the inherent ordering of vertices in 𝕋. Let V(S) be the set of end-points of edges in S; that is, V(S)={v(v,u)S}. Now, consider the reduced incidence matrix of an edge set SE:

Definition 2 (reduced incidence matrix).

Let SE, and pV(S). The (|V(S)|1)×|S| matrix Ap[S] is the submatrix of A whose rows are those of A with indices in V(S){p}, and whose columns are those of A with indices in S.

Leveraging the definition of reduced incidence matrices, we can explore a central lemma in the determinant-based counting method; this lemma is used as a step in the proof for the Matrix Tree Theorem (see, for instance, the combination of Lemmas 2.2 and 2.5 in [15]).

Lemma 3.

Let SE such that |S|=|V(S)|1. For any vertex p in V(S), the following holds: if (V(S),S) is a tree, then |det(Ap[S])|=1. Otherwise, |det(Ap[S])|=0.

Corollary 4.

Let SE such that |S|=|V(S)|1. If (V(S),S) is a tree, then pV(S)|det(Ap[S])|=|V(S)|. Otherwise, pV(S)|det(Ap[S])|=0.

Corollary 4 allows us to count the number of trees within a collection of edge sets 𝒮𝒫(E) by calculating the value of

S𝒮(1|V(S)|pV(S)|det(Ap[S])|), (2)

provided that that |S|=|V(S)|1 for all S𝒮.

3 Counting k-paths

Let G=(V,E) be an undirected graph, and let k𝐍. We address the following problem:

#k-Path Input: A graph G=(V,E) and a parameter k𝐍 Output: Pk(G); the number of (not necessarily induced) subgraphs of G that are isomorphic to a simple (non-overlapping) path with exactly k vertices.

This section details a Dynamic Programming algorithm for solving the #k-Path problem. Our method first identifies a specific collection of edge sets, 𝒮, such that the set of all trees in 𝒮 is identical to the set of all simple paths within the graph G. We then utilize 𝒮 within Corollary 4 to establish a partial sum constraint that all Dynamic Programming entries must satisfy.

3.1 Partial sum

In line with Corollary 4, we define the collection of edge sets 𝒮 as follows:

𝒮={SEvV(S),degS(v)2;|S|=|V(S)|1}.

An edge set SE constitutes a simple path if and only if the graph (V(S),S) is a tree where every vertex has a degree of at most two. Consequently, the set of trees in 𝒮 is identical to the set of simple paths within the graph G. The condition that |S|=|V(S)|1 for all S𝒮 is inherently satisfied by all trees and thus does not alter the number of trees, but does ensure the compatibility of 𝒮 with Corollary 4. The number of simple paths with length k in graph G is now given by

Pk(G) =S𝒮[(V(S),S) is a tree]
=1kS𝒮,|S|=k1pV(S)|det(Ap[S])|. (3)

The condition that |S|=|V(S)|1, while perhaps intuitive, complicates our Dynamic Programming design by requiring us to track both the number of edges and vertices within any edge set. A more computationally efficient strategy involves counting only the total number of vertices and the number of degree-one vertices. This is particularly advantageous because a simple path invariably has exactly two degree-one vertices. Consequently, we will employ the following proposition:

Proposition 5.

Suppose SE is a nonempty set such that degS(v)2 for all vV(S). Then the number of degree one vertices in V(S) is equal to two if and only if |S|=|V(S)|1.

With the equivalence from Proposition 5, we can rewrite our definition of 𝒮 (without changing 𝒮 itself):

𝒮={SEvV(S),degS(v)2;|{vV(S)degS(v)=1}|=2}. (4)

We can expand the determinant in Equation 3.1 to obtain

Pk( G)=1kS𝒮,|S|=k1pV(S)(f:S11V(S){p}sgn(f)eSaf(e),e)2 (5)
=1k S𝒮,|S|=k1pV(S)f1:S11V(S){p}f2:S11V(S){p}sgn(f1)sgn(f2)eSaf1(e),eaf2(e),e. (6)

The bijection f:S11V(S)p maps each edge e=(u,v) in S to a unique vertex f(e) in V(S)p. Observe that if f(e) is distinct from both u and v, the corresponding term in the sum becomes zero due to the zero entry af(e),e in the incidence matrix. Utilizing the property that |det(Ap[S])|0,1, we have |det(Ap[S])|=(det(Ap[S]))2.

To compute Equation 6, we will utilize Dynamic Programming on a given tree decomposition 𝕋 of G. For this purpose, we define the following parameters:

  • For every bag y𝕋, sdeg{0,1,2}|By| denotes the degree of every vertex in By in G[S]

  • For every bag y𝕋, s1{0,1}|By| denotes for every vertex in By whether it has been used as a value in the bijection f1

  • For every bag y𝕋, s2{0,1}|By| denotes for every vertex in By whether it has been used as a value in the bijection f2

  • Let t denote the number of forgotten vertices (in VyBy) that have degree one in S

  • Let l denote the number of edges in S

Furthermore, we define the following useful sets:

  • Let 𝒮y(sdeg,t,l) be the collection of all edge sets SEy with exactly l edges, with t vertices of degree one in V(S)By, and such that the degree of a vertex v in By is equal to sdeg(v) and the degree of all vertices is at most two.

  • Consider a set of edges SEy, and a set of vertices PV(S)By. For i1,2, we define y(S,P,si) as the set of all bijective functions f that map each edge in S to a unique vertex in V(S)(si1(0)P).

    Intuitively, y(S,P,si) represents the possible bijections between the edges in S and a selection of vertices from V(S). Since Proposition 5 states that |V(S)|>|S|, not all vertices in V(S) can be part of this bijection. The sets si1(0) and P both identify the vertices that are excluded from this mapping. A key distinction is that si1(0) contains vertices within the bag By, whereas P contains vertices that are strictly outside of By.

    For a valid k-path we will have that |P|=1 as in Equation 6. However, during the construction of this k-path, we might encounter intermediate states with multiple connected components. In such cases, |P| might need to be greater than one to ensure a valid bijection exists, as more vertices need to be excluded from V(S). Ultimately, we are guaranteed that |P|=1. This is because if |P|=0, the resulting edge sets form cycles, leading to a determinant of zero. Conversely, if |P|>1, the resulting edge sets become disconnected, implying more than two vertices with degree one.

For every entry of the Dynamic Program in bag y we will require that the following partial sum holds:

Ay(sdeg,s1,s2,t,l)=
S𝒮y(sdeg,t,l)(1)PV(S)By(2)f1y(S,P,s1)f2y(S,P,s2)(3)sgn(f1)sgn(f2)eS(4)af1(e),eaf2(e),e, (7)

where we have labeled the Σ’s and Π for later reference. Filling in variables, we see that in a root bag z where Ez=E and Bz=, we have that 1kAz(,,,2,k1)=Pk(G), the number of k-paths in G.

3.2 Dynamic program

This section details the computation of tables for the functions Ay (defined in Equation 7) for each node type in nice tree decompositions.

Leaf bag 𝒚

Ay(,,,t,l)={1,if t=l=00otherwise. (8)

In a leaf bag, we have that Ey=By=. Filling this into Equation 7 we see that Σ (1) has no summands unless t=l=0. In this case, Σ (1) has one summand with S=, Σ (2) has one summand with P=, Σ (3) has one summand with f1=f2= (so that sgn(f1)=sgn(f2)=1), and Π (4) has no elements.

Introduce vertex 𝒖 bag 𝒚 with child 𝒛

Ay(sdeg,s1,s2,t,l)={Az(sdeg|Bz,s1|Bz,s2|Bz,t,l)if sdeg(u)=s1(u)=s2(u)=00otherwise. (9)

Since vertex u is introduced in this bag, no edge in Ey is incident to u. Therefore degS(u)=0 for all SEy, and Σ (1) in Equation 7 has no summands if sdeg(u)0. Similarly, all summands in Σ (3) vanish whenever s1(u)0 or if s2(u)0.

If sdeg(u)=s1(u)=s2(u)=0, then Ay(sdeg,s1,s2,t,l) reduces to
Az(sdeg|Bz,s1|Bz,s2|Bz,t,l).

Forget vertex 𝒖 bag 𝒚 with child 𝒛

When t{1,2}, we set

Ay(sdeg,s1,s2,t,l) =Az(sdeg[u0],s1[u0],s2[u0],t,l)
+Az(sdeg[u1],s1[u0],s2[u0],t1,l)
+Az(sdeg[u1],s1[u1],s2[u1],t1,l)
+Az(sdeg[u2],s1[u0],s2[u0],t,l)
+Az(sdeg[u2],s1[u1],s2[u1],t,l).

If t=0, we set

Ay(sdeg,s1,s2,t,l) =Az(sdeg[u0],s1[u0],s2[u0],t,l)
+Az(sdeg[u2],s1[u0],s2[u0],t,l)
+Az(sdeg[u2],s1[u1],s2[u1],t,l).

In a forget vertex u bag y, the vertex u is excluded from By. We determine the number of satisfying edge sets by summing over the possible degrees of u.

When degS(u)=0, the edge sets that satisfy Equation 7 are the same as the edge sets in 𝒮z(sdeg[u0],t,l).

When degS(u)=1, the edge sets satisfying Equation 7 in bag y are the same as the edge sets in child z that have one less degree one vertex in SBz. If uP, Ay reduces to Az(sdeg[u1],s1[u0],s2[u0],t1,l) if t1, and zero otherwise. When uP, Ay reduces to Az(sdeg[u1],s1[u1],s2[u1],t1,l) when t1, and zero otherwise.

Finally, when degS(u)=2 we see that Ay reduces to Az(sdeg[u2],s1[u0],s2[u0],t,l) when uP. When uP, Ay reduces to Az(sdeg[u2],s1[u1],s2[u1],t,l).

Introduce edge 𝒅=(𝒖,𝒘) bag 𝒚 with child 𝒛

For sdeg(u)>0 and sdeg(w)>0 we set

Ay(sdeg,s1,s2,t,l) =Az(sdeg,s1,s2,t,l)+(1)inv(s11(1),u)+inv(s21(1),w)
×us11(1)dws21(1)d Az(sdeg,s1[u0],s2[w0],t,l1)au,daw,d,

where sdeg is equal to sdeg, except that sdeg(u)=sdeg(u)1, and sdeg(w)=sdeg(w)1. If sdeg(u)=0 or sdeg(w)=0, we can not have that dS. In this case, we set

Ay(sdeg,s1,s2,t,l)=Az(sdeg,s1,s2,t,l).

In an introduce edge d bag we have two options: either d is included in S, or d is not included in S. If d is not included in S, then Ay reduces to Az(sdeg,s1,s2,t,l).

If d=(u,w) is included in S, we have to account for all possible bijections f1 and f2. First note that for all bijections f where f(d)d, we have that af(d),d=0 and the term vanishes. Therefore we fix fi(d)=u or fi(d)=w.

The inclusion of d into the bijections might change their sign. Since for all vBy and xVyBy we have that v>x, no vertex in VyBy can contribute to a change in sign. Also, since d is introduced in bag y, we have that d>e for all eEy{d}. The change in sign of fi is therefore equal to (1)inv(si1(1),fi(d)).

Join bag 𝒚 with children 𝒛𝟏 and 𝒛𝟐

Ay(sdeg,s1,s2,t,l)=
sdeg,z1+sdeg,z2=sdegs1,z1+s1,z2=s1s2,z1+s2,z2=s2tz1+tz2=tlz1+lz2=lAz1(sdeg,z1,s1,z1,s2,z1,tz1,lz1)Az2(sdeg,z2,s1,z2,s2,z2,tz2,lz2)
(1)inv(s1,z11(1),s1,z21(1))+inv(s2,z11(1),s2,z21(1)), (10)

where we use coordinate-wise addition.

3.3 Running time analysis

Given a host graph G together with a nice path or tree decomposition, we can traverse the decomposition in post-ordering, calculating entries according to the Dynamic Program described above. This procedure gives rise to the following theorem:

Theorem 6.

There exists a deterministic algorithm that, given a graph G, a parameter k and a nice tree decomposition of G with treewidth tw, can solve #k-Path in 18twtwO(1)k2n time. Given a nice path decomposition with pathwidth pw, there exists an algorithm that can solve #k-Path in 7pwpwO(1)kn time.

4 Counting trees

In this section, we will discuss a generalization of the k-path problem where we count subgraphs isomorphic to a tree T.

Let G=(V,E) be an undirected graph. Then the #k,-Tree problem on G is defined as:

#k,-Tree Input: A graph G=(V,E) and a tree T that has leaf nodes and k vertices Output: Tk(G); the number of (not necessarily induced) subgraphs of G that are isomorphic to T, not accounting for internal symmetries in T.

To count occurrences of a target tree T using Dynamic Programming, we will decompose it into path components. This approach allows us to build upon the path-counting methods detailed in Section 3. However, vertices with a degree of three or more, acting as convergence points for multiple paths, will pose a specific challenge requiring dedicated attention.

4.1 Tree labeling

To count occurrences of a specific tree T, we first need to establish a unique labeling for it. This labeling is derived by decomposing T into path segments, a process that considers three cases based on the degree of each vertex v in T:

  • deg(v)T=1; v is a leaf.

  • deg(v)T=2; v is a path node.

  • deg(v)T>2; v is an internal junction.

We define the path segments as follows:

  • Starting in every leaf node with an unlabeled edge, we follow the unique path along the (possibly empty) set of connected path nodes, until we encounter an internal junction ji or another leaf. The paths traced in this way are called the leaf paths of T. Note that if a leaf path terminates in two leaf nodes, T is isomorphic to a simple path, and its occurrences can be counted using the method in Section 3. For the remainder of this paper, we assume all leaf paths end in one leaf and one internal junction.

  • For each internal junction, trace the paths starting in its unlabeled edges along the (possibly empty) set of connected path nodes until we encounter another internal junction (note that we can not encounter a leaf node, as per the previous step). These path segments are called internal paths.

For an illustration of this procedure, see Figure 1. By design, all edges along paths originating from leaves or internal junctions are labeled. Consequently, since any path not starting at such a point must form a cycle, all edges in the (acyclic) tree T are labeled.

Refer to caption
Refer to caption
Figure 1: A tree T (left), together with its labeling (right). In the labeled tree, the internal junctions with degree at least 3 are labeled j1,j2,j3, the internal paths are labeled pq,r for a path between jq and jr, and the leaf paths are labeled lq,i for the i’th leaf path originating from internal junction jq.

Let N={jq}q be the set of internal junctions in T, let I={pq,r=(jq,v1,v2,,jr),} the set of internal paths in T denoted by their vertices, and L={lq,i=(jq,v1,v2,,vk),} the set of leaf paths in T denoted by their vertices. We will call (N,I,L) the labeling of T. Using this labeling, we can prove the following theorem, which will help us count the distinct graphs isomorphic to T:

Theorem 7.

Let T be a tree with labeling (N,I,L), let G=(V,E) be a graph, and let SE be a set of edges in G. Then the subgraph (V(S),S) is isomorphic to T if and only if:

  • (V(S),S) is a tree

  • There exists a labeling function f:V(S)NIL, such that:

    1. 1)

      Internal junctions are the image of exactly one vertex in 𝑽(𝑺)

      • i.e. for all vN, we have that |f1(v)|=1

    2. 2)

      Path length is preserved

      • i.e. for all internal paths pq,rI, we have that |f1(pq,r)f1(jq)f1(jr)|=lenT(pq,r)

      • and, for all leaf paths lq,iL, we have that |f1(lq,i)f1(jq)|=lenT(lq,i)

    3. 3)

      Vertex degrees in paths are preserved

      • i.e. for all internal paths pq,rI, and for all vertices vf1(pq,r), we have that degS(v)=2.

      • and, for all leaf paths lqL, there is exactly one vertex tf1(lq) such that degS(t)=1. For all vertices vf1(lq)t, we have that degS(v)=2.

    4. 4)

      Neighborhoods are preserved

      • i.e. for all internal paths pq,rI, and for all vertices vf1(pq,r), let N(v) denote the neighborhood of v in S. We have that f(N(v)){pq,r,jq,jr}.

      • and, for all leaf paths lq,iL, and for all vertices vf1(lq,i), we have that f(N(v)){lq,i,jq}.

4.2 Partial sum

Consider a graph G=(V,E) and a subset of its edges SE. Let T be a tree with k vertices, l leaves, and labeling T=(N,I,L). Define T(S) as the set of functions f:V(S)NIL satisfying the conditions of Theorem 7. If T(G) denotes the number of distinct labeled subgraphs of G isomorphic to T, then Theorem 7 implies that

T(G) =SEfT(S)[(V(S),S) is a tree]
=1kSE|S|=|V(S)|1fT(S)pV(S)|det(Ap[S])|, (11)

where the second step follows from Corollary 4. Consider any edge set S. If there exists a function fT(S), then by its defining properties (1) and (2), we have:

  • |f1(N)|=|N|

  • |f1(pq,rjqjr)|=len(pq,r) for all internal paths pq,r

  • |f1(lq,ijq)|=len(lq,i) for all leaf paths lq,i

Since every vertex in V(T) is either an internal junction or belongs to an internal/leaf path, it follows that |V(S)|=|f1(NIL)|=|V(T)|. Consequently, the condition |S|=|V(S)1| in the first summation simplifies to |S|=k1. This allows us to expand the determinant in Equation 4.2 analogously to Section 3, resulting in

T(G)=1kSE|S|=k1fT(S)pV(S)f1:S11V(S){p}f2:S11V(S){p}sgn(f1)sgn(f2)eSaf1(e),eaf2(e),e. (12)

We now construct the partial sum that defines each entry in our Dynamic Program. The definitions of sdeg,s1,s2, and y(S,P,si) are retained from Section 3. Furthermore, we will define new parameters:

  • For every bag y𝕋, let sa(NIL{0})|By| denote the label assigned to every vertex in bag y. Relating to Theorem 7, sa(v) can be interpreted as f(v) when restricted to the vertices v in By.

  • Let α{0,1}|N| denote for every internal junction jq in N whether some vertex vV(S)By should be labeled with jq in the construction of a function fT(S). The vector α is indexed by the internal junctions in N, and we will denote by α(jq) the value corresponding to internal junction jq. Conversely, we will denote by α1(1) all internal junctions in N for which α is equal to one.

  • Let λ|IL| denote for every internal path in I and leaf path in L how many vertices in V(S) should be labeled with this path in the construction of a function fT(S). The vector λ is indexed by the internal and leaf paths in IL, and we will denote by λ(p) the value corresponding to the path p. Conversely, we will denote by λ1(1) all paths in IL for which λ is at least one.

  • Let tleaf{0,1}|L| denote for every leaf path lq,i in L the number of forgotten vertices v with degree one for which f(v) should map to lq,i in the construction of some fT(S).

  • Let 𝒮y(sdeg,sa,α,λ,tleaf) be the collection of all edge sets SEy such that there exists a labeling function fy,S:V(S)Byα1(1)λ1(1){0} that obeys the following requirements:

    1. 0)

      The functions 𝒇𝒚,𝑺 and 𝒔𝒂 are identical when restricted to bag vertices

      • i.e. for all bag vertices vBy, we have that fy,S(v)=sa(v)

    2. 1)

      All internal junctions in 𝜶1(1) are the image of exactly one vertex in 𝑽(𝑺)𝑩𝒚 under 𝒇𝒚,𝑺

      • i.e. for all internal junctions vα1(1), we have that |fy,S1(v)|=1

    3. 2)

      All paths 𝒑 in 𝑰𝑳 are the image of exactly 𝝀1(𝒑) vertices in 𝑽(𝑺)𝑩𝒚 under 𝒇𝒚,𝑺

      • i.e. for all paths pλ1(1), we have that |fy,S1(p)|=λ(p)

    4. 3)

      Vertex degrees are preserved in forgotten vertices and are equal to 𝒔deg in bag vertices

      • i.e. for all internal junctions jqα1(1), if the vertex vfy,S1(jq) (there is exactly one such vertex as per (1)) is a forgotten vertex, then deg(v)S=degT(jq). If v is a bag vertex, then deg(v)S=sdeg(v).

      • for all internal paths pq,rλ1(1)I, we have that all forgotten vertices vfy,S1(pq,r)By have degree two in S. All bag vertices vfy,S1(pq,r)By have degree sdeg(v) in S.

      • and, for all leaf paths lq,iλ1(1)L, we have that exactly tleaf(lq,i) forgotten vertices in fy,S1(lq,i)By have degree one in S, and all other vertices in fy,S1(lq,i)By have degree two in S. All bag vertices vfy,S1(lq,i)By have degree sdeg(v) in S.

    5. 4)

      Neighborhoods are preserved

      • i.e. for all internal paths pq,rλ1(1)I, and for all vertices vfy,S1(pq,r), let N(v) denote the neighborhood of v in S. We have that fy,S(N(v)){pq,r,jq,jr}.

      • and, for all leaf paths lq,iλ1(1)L, and for all vertices vfy,S1(lq,i), we have that fy,S(N(v)){lq,i,jq}.

With the parameters defined above, we will determine the Dynamic Program entries Ay for each bag y such that

Ay(sdeg,s1,s2,sa,α,λ,tleaf)=
S𝒮y(sdeg,sa,α,λ,tleaf)(1)PV(S)By(2)f1y(S,P,s1)f2y(S,P,s2)(3)sgn(f1)sgn(f2)eS(4)af1(e),eaf2(e),e. (13)

Consider a vector λT|IL| indexed by all internal paths (I) and leaf paths (L) of T. For each internal path pI, the corresponding value in λT is len(p)2, and for each leaf path pL, the value is len(p)1. Then, in a bag y with Ey=E and By=, the expression 1kAy(,,,,1|N|,λT,1|L|) precisely equals Equation 12, thus yielding the number of subgraphs in G isomorphic to T.

4.3 Dynamic program

In this section, we will describe a Dynamic Program that iteratively calculates all partial sums of Equation 13. The entry calculations are accompanied by a brief explanation.

Leaf Bag 𝒚

Ay(,,,,α,λ,tleaf)={1,if α=0|N|,λ=0|IL|,tleaf=0|L|,0otherwise. (14)

Introduce vertex 𝒖 bag 𝒚 with child 𝒛

Ay(sdeg,s1,s2,sa,α,λ,tleaf)=
{Az(sdeg|Bz,s1|Bz,s2|Bz,sa|Bz,α,λ,tleaf)if sdeg(u)=s1(u)=s2(u)=0,sa(u)=,Az(sdeg|Bz,s1|Bz,s2|Bz,sa|Bz,if sdeg(u)=s1(u)=s2(u)=0,α[jq0],λ,tleaf)sa(u)=jqN,α(jq)=1,Az(sdeg|Bz,s1|Bz,s2|Bz,sa|Bz,α,if sdeg(u)=s1(u)=s2(u)=0,λ[pλ(p)1],tleaf)sa(u)=pIL,λ(p)>00otherwise. (15)

Because vertex u is introduced in this bag, no edge in Ey is incident to u, and therefore the partial sum reduces to zero if sdeg(u)0,s1(u)0 or s2(u)0. Depending on the label sa(u) there are slightly different cases.

Forget vertex 𝒖 bag 𝒚 with child 𝒛

Ay (sdeg,s1,s2,sa,α,λ,tleaf)=
Az(sdeg[u0],s1[u0],s2[u0],sa[u0],α,λ,tleaf)
+ ptleaf1(1)(Az(sdeg[u1],s1[u0],s2[u0],sa[up],α,λ,tleaf[p0])+Az(sdeg[u1],s1[u1],s2[u1],sa[up],α,λ,tleaf[p0]))
+ pλ1(1)(Az(sdeg[u2],s1[u0],s2[u0],sa[up],α,λ,tleaf)+Az(sdeg[u2],s1[u1],s2[u1],sa[up],α,λ,tleaf))
+ jqα1(1)(Az(sdeg[udegT(jq)],s1[u0],s2[u0],sa[ujq],α,λ,tleaf)+Az(sdeg[udegT(jq)],s1[u1],s2[u1],sa[ujq],α,λ,tleaf)). (16)

To obtain the total number of partial solutions in a forget bag we sum over all possible degrees of u in Bz (denoted as sdeg,z(u)). The case that sdeg,z(u)=0 accounts for the edge sets S such that uS. The case that sdeg,z(u)=1 accounts for the edge sets where u is a leaf, the case that sdeg,z(u)=2, accounts for the edge sets where u is a path node, and the case where sdeg,z(u)>2, accounts for the edge sets where u is an internal junction.

Introduce edge 𝒅=(𝒖,𝒘) bag 𝒚 with child 𝒛

Due to the preservation of neighborhoods requirement (4) for fy,S, the edge d can only be included in S if there is some internal path pq,rI such that sa(u),sa(w){pq,r,jq,jr}, or if there is some leaf path lq,i such that sa(u),sa(w){lq,i,jq}. Let 1IL(u,w) be the indicator function that is equal to one if there exists such a path, and zero otherwise. If sdeg(u)=0, sdeg(w)=0, or if 1IL(u,w)=0, we set

Ay(sdeg,s1,s2,sa,α,λ,tleaf)=Az(sdeg,s1,s2,sa,α,λ,tleaf), (17)

Otherwise, we set

Ay( sdeg,s1,s2,sa,α,λ,tleaf)=Az(sdeg,s1,s2,sa,α,λ,tleaf)
+us11(1)dws21(1)d(Az(sdeg,s1[u0],s2[w0],sa,α,λ,tleaf)au,daw,d(1)inv(s11(1),u)+inv(s21(1),w)). (18)

In an introduce edge d bag we have two options: either d is included in S, or it is not. In the case that dS, then Ay(sdeg,s1,s2,sa,α,λ,tleaf) reduces to Az(sdeg,s1,s2,sa,α,λ,tleaf). If dS we have to correctly account for the change in sign of bijections f1 and f2. This is done in the same way as in Section 3.2.

Join bag 𝒚 with children 𝒛𝟏 and 𝒛𝟐

Ay(sdeg,s1,s2,sa,α,λ,tleaf)=
sdeg,z1+sdeg,z2=sdegsa,z1=sa,z2=sajqN,αz1(jq)+αz2(jq)=α(jq)+|sa1(jq)|pIL,λz1(p)+λz2(p)=λ(p)+|sa1(p)|tleaf,z1+tleaf,z2=tleafs1,z1+s1,z2=s1s2,z1+s2,z2=s2Az1(sdeg,z1,s1,z1,s2,z1,sa,z1,αz1,λz1,tleaf,z1)Az2(sdeg,z2,s1,z2,s2,z2,sa,z2,αz2,λz2,tleaf,z2)(1)inv(s1,z11(1),s1,z21(1))+inv(s2,z11(1),s2,z21(1)), (19)

where we use coordinate-wise addition.

4.4 Running time analysis

Using the Dynamic Program above we can prove the following theorem:

Theorem 8.

There exists a deterministic algorithm that, given a graph G together with a nice tree decomposition of G with treewidth tw and given a tree T with leaf nodes and k vertices with <k12e, can solve #k,-Tree in O(tw)twO(1)(k)O()n time. Given a nice path decomposition of G with pathwidth pw, there exists an algorithm that solves #k,-Tree O(pw)pwO(1)(k)O()n time.

5 Conclusion

In this paper, we have given deterministic algorithms for the exact counting of k-paths and trees. These algorithms are single-exponential, parameterized by the tree- or pathwidth of the host graph G, and are linear in the number of vertices in G. Both algorithms utilize the determinant-based approach introduced by Bodlaender et al. [4] to construct a Dynamic Program. The algorithms in this paper can also be straightforwardly modified to count the number of cycles of length k, the number of fixed-endpoint k-paths, and the number of k-Trees in single-exponential time when parameterized by the treewidth of the host graph.

Before our work, no algorithms were known for the studied problems with single-exponential dependency on the treewidth. However, the base of the exponents of the algorithm to count trees is rather large. An interesting question is whether these bases can be improved. One possible way in which the algorithm could be improved is if a more efficient way of counting the length of the internal and leaf paths is found. Keeping track of how many edges are in each path quickly blows up the running time, as there are (k)O() possible combinations. A more efficient way of counting would significantly reduce the scaling of the running time with .

The techniques of this paper can be used to count even more general graph patterns. Suppose for example that some graph H is ’almost’ acyclic. That is, there is some small set of edges C that, when removed, H becomes acyclic. Then we can treat the set of end-points V(C) of those edges in C as internal junctions (so we can label vertices as end-points of such edges), and we can verify the existence of edges in G between those end-points without including them in the bijections. The running time of such an algorithm would be similar to that of the tree counting algorithm but with replaced with +|V(C)|.

References

  • [1] Noga Alon, Phuong Dao, Iman Hajirasouliha, Fereydoun Hormozdiari, and S. Cenk Sahinalp. Biomolecular network motif counting and discovery by color coding. Bioinformatics, 24(13):
    i241–i249, 2008.
    doi:10.1093/bioinformatics/btn163.
  • [2] Noga Alon and Shai Gutner. Balanced hashing, color coding and approximate counting. In Proceedings 4th International Workshop on Parameterized and Exact Computation, IWPEC 2009, pages 1–16. Springer, 2009. doi:10.1007/978-3-642-11269-0_1.
  • [3] V. Arvind and Venkatesh Raman. Approximation algorithms for some parameterized counting problems. In Proceedings 13th International Symposium on Algorithms and Computation, ISAAC 2002, pages 453–464. Springer, 2002. doi:10.1007/3-540-36136-7_40.
  • [4] Hans L. Bodlaender, Marek Cygan, Stefan Kratsch, and Jesper Nederlof. Deterministic single exponential time algorithms for connectivity problems parameterized by treewidth. Information and Computation, 243:86–111, 2015. doi:10.1016/j.ic.2014.12.008.
  • [5] Cornelius Brand, Holger Dell, and Thore Husfeldt. Extensor-coding. In ACM SIGACT 50th Annual Symposium on Theory of Computing, STOC 2018, pages 151–164, 2018. doi:10.1145/3188745.3188902.
  • [6] Cornelius Brand and Marc Roth. Parameterized counting of trees, forests and matroid bases. In 12th International Computer Science Symposium in Russia: Computer Science – Theory and Applications, CSR 2017, pages 85–98. Springer, 2017. doi:10.1007/978-3-319-58747-9_10.
  • [7] Marek Cygan, Jesper Nederlof, Marcin Pilipczuk, Michal Pilipczuk, Johan M.M. van Rooij, and Jakub Onufry Wojtaszczyk. Solving connectivity problems parameterized by treewidth in single exponential time. ACM Transactions on Algorithms, 18(2):17:1–17:31, 2022. doi:10.1145/3506707.
  • [8] Alexandra Duma and Alexandru Topirceanu. A network motif based approach for classifying online social networks. In Proceedings 9th IEEE International Symposium on Applied Computational Intelligence and Informatics, SACI 2014,, pages 311–315. IEEE, 2014. doi:10.1109/SACI.2014.6840083.
  • [9] Jörg Flum and Martin Grohe. The parameterized complexity of counting problems. SIAM Journal on Computing, 33(4):892–922, 2004. doi:10.1137/S0097539703427203.
  • [10] Daniel Lokshtanov, Andreas Björklund, Saket Saurabh, and Meirav Zehavi. Approximate counting of k-paths: Simpler, deterministic, and in polynomial space. ACM Trans. Algorithms, 17(3), 2021. doi:10.1145/3461477.
  • [11] Catherine McCartin. Parameterized counting problems. Annals of Pure and Applied Logic, 138(1):147–182, 2006. doi:10.1016/j.apal.2005.06.010.
  • [12] R. Milo, S. Shen-Orr, S. Itzkovitz, N. Kashtan, D. Chklovskii, and U. Alon. Network Motifs: Simple building blocks of complex networks. Science, 298(5594):824–827, 2002. doi:10.1126/science.298.5594.824.
  • [13] N. Pržulj, D. G. Corneil, and I. Jurisica. Modeling interactome: scale-free or geometric? Bioinformatics, 20(18):3508–3515, July 2004. doi:10.1093/bioinformatics/bth436.
  • [14] L.G. Valiant. The complexity of computing the permanent. Theoretical Computer Science, 8(2):189–201, 1979. doi:10.1016/0304-3975(79)90044-6.
  • [15] Janneke van den Boomen. The Matrix Tree Theorem, 2007. Bachelor thesis, Radbout Universiteit Nijmegen. URL: https://www.math.ru.nl/˜bosma/Students/jannekebc3.pdf.
  • [16] Jacques Verstraete and Dhruv Mubayi. Counting Trees in Graphs. The Electronic Journal of Combinatorics, 23(3):P3.39, 2016. doi:10.37236/6084.
  • [17] Stanley Wasserman and Katherine Faust. Social Network Analysis: Methods and Applications, volume 8. Cambridge University Press, 1994. doi:10.1017/CBO9780511815478.