Constrained Multilinear Detection and Generalized Graph Motifs

We introduce a new algebraic sieving technique to detect constrained multilinear monomials in multivariate polynomial generating functions given by an evaluation oracle. As applications of the technique, we show an $O^*(2^k)$-time polynomial space algorithm for the $k$-sized Graph Motif problem. We also introduce a new optimization variant of the problem, called Closest Graph Motif and solve it within the same time bound. The Closest Graph Motif problem encompasses several previously studied optimization variants, like Maximum Graph Motif, Min-Substitute Graph Motif, and Min-Add Graph Motif. Finally, we provide a piece of evidence that our result might be essentially tight: the existence of an $O^*((2-\epsilon)^k)$-time algorithm for the Graph Motif problem implies an $O((2-\epsilon')^n)$-time algorithm for Set Cover.


Introduction
Many hard combinatorial problems can be reduced to the framework of detecting whether a multivariate polynomial P ( x) = P (x 1 , x 2 , . . . , x n ) has a monomial with specific properties of interest. In such a setup, P ( x) is not available in explicit symbolic form but is implicitly defined by the problem instance at hand, and our access to P ( x) is restricted to having an efficient algorithm for computing values of P ( x) at points of our choosing. This framework was pioneered by Koutis [14], Williams [21], and Koutis and Williams [17] for use in the domain of parameterized subgraph containment problems, and it currently underlies the fastest known parameterized algorithms for many basic tasks such as path and packing problems [4].
The present paper is motivated by recent works of Guillemot and Sikora [13] and Koutis [16], who observed that functional motif discovery problems in bioinformatics are also amenable to efficient parameterized solution in the polynomial framework. Following Koutis [16], applications in this domain require one to detect monomials in P ( x) that are both multilinear and further constrained by means of colors assigned to variables x, so that the combined degree of variables of each color in the monomial may not exceed a given maximum multiplicity for that color. Our objectives in this paper are to (i) present an improved algebraic technique for constrained multilinear detection, (ii) generalize the technique to allow for approximate matching at cost, and (iii) derive improved algorithms for graph motif problems, together with evidence that our algorithms may be optimal in the exponential part of their running time. We also introduce a new common generalization-the closest graph motif problem-that tracks the weighted edit distance between the target motif and each candidate pattern; this in particular generalizes both the minimum substitution and minimum addition variants of the graph motif problem introduced by Dondi, Fertin, and Vialette [10].
Let us now describe our main results in more detail, starting with algebraic contributions and then proceeding to applications in graph motifs. All the algebraic contributions rely essentially on what can be called the "substitution-sieving" method in characteristic 2 [2,4].
1.1. Multilinearity. To ease the exposition and the subsequent proofs, it will be convenient to start with a known, non-constrained version of the substitution sieve that exposes multilinear monomials.
For an integer n, let us write [n] = {1, 2, . . . , n}. Let L be a set of k labels. For each index i ∈ [n] and label j ∈ L, introduce a new variable z i,j . Denote by z the vector of all variables z i,j .
Lemma 1 (Non-constrained multilinear detection [2,4]). The polynomial P ( x) has at least one multilinear monomial if and only if the polynomial is not identically zero, where z A i = j∈A z i,j for all i ∈ [n] and A ⊆ L.

Remark.
We can now observe the basic structure of the sieve (1): by making 2 k substitutions of the new variables z into P ( x), we reduce the question of existence of a multilinear monomial in P ( x) into the question whether the polynomial Q( z) is not identically zero. The latter can be tested probabilistically by one evaluation of Q( z) at a random point, which reduces via (1) into evaluations of P ( x) at 2 k points. This will be the basic structure in all our subsequent algorithm designs.
1.2. Constrained multilinearity. We are now ready to state our main algebraic contribution. Let C be a set of at most n colors such that each color q ∈ C has a maximum multiplicity m(q) ∈ {0, 1, . . . , n}. Associate with each index i ∈ [n] a color c(i) ∈ C. Let us say that a monomial x d1 1 x d2 2 · · · x dn n is properly colored if the number of occurrences of each color is at most its maximum multiplicity, or equivalently, for all q ∈ C it holds that i∈c −1 (q) d i ≤ m(q).
Associate with each color q ∈ C a set S q of m(q) shades of the color q, such that S q and S q are disjoint whenever q = q . Let S = ∪ q∈C S q .
For each index i ∈ [n] and each shade d ∈ S c(i) , introduce a new variable v i,d . For each shade d ∈ S and each label j ∈ L, introduce a new variable w d,j .
Lemma 2 (Constrained multilinear detection). The polynomial P ( x) has at least one monomial that is both multilinear and properly colored if and only if the polynomial Remark. This lemma enables us to (probabilistically) detect a constrained multilinear monomial of degree k using 2 k evaluations of P ( x), assuming that we are working over a sufficiently large field of characteristic 2. This solves an open problem posed by Koutis at a Dagstuhl seminar in 2010 [15], and forms the core of our algorithm in Theorem 4.

1.3.
Cost-constrained multilinearity. The previous setting admits a generalization where we associate costs to decisions to arrive at a proper coloring. Accordingly, we assume that no coloring c : [n] → C has been fixed a priori, but instead associate with each index i ∈ [n] and each color q ∈ C a nonnegative integer κ i (q), the cost of assigning the color q to i.
Once a coloring c : [n] → C has been assigned, the cost of a monomial x d1 1 x d2 2 · · · x dn n in the assigned coloring is i∈[n] d i κ i (c(i)). The objective now becomes to detect a multilinear monomial that has the minimum cost under a proper coloring.
For each index i ∈ [n] and each shade d ∈ S, introduce a new variable v i,d . For each shade d ∈ S and each label j ∈ L, introduce a new variable w d,j . Introduce a new variable η.
Lemma 3 (Cost-constrained multilinear detection). The polynomial P ( x) has at least one monomial that is both multilinear and admits a proper coloring with cost σ if and only if the polynomial . . , u A n has at least one monomial whose degree in the variable η is σ, where u A i = j∈A u i,j and for all i ∈ [n], j ∈ L, and A ⊆ L.
Remark. The previous lemma may be extended to track multiple cost parameters η 1 , η 2 , . . . simultaneously. In fact, this will be convenient in our algorithm underlying Theorem 5. We also observe that in applications one typically works with a (random) evaluation in the variables v and w, but seeks to recover an explicit polynomial in η as the output of the sieve, typically by a sequence of evaluations at distinct points, followed by interpolation to recover the polynomial in η.

1.4.
Graph motif problems. The application protagonist for our algebraic tools will be the following problem and its generalization.

Maximum Graph Motif [9]
Input: A connected, undirected host graph H with n vertices and e edges, a multiset M of colors over a base color set C, a coloring c : V (H) → C for the vertices of H, and a positive integer k. Question: Is there a subset K ⊆ V (H) of size k such that (a) the subgraph induced by K in H is connected, and (b) the multiset c(K) of colors is a subset of M , taking multiplicities into account?
Background. Graph motif problems were introduced by Lacroix et al. [18] and motivated by applications in bioinformatics, specifically in metabolic network analysis. The Maximum Graph Motif problem was introduced by Dondi, Fertin, and Vialette [9]. It is known to be NP-hard even when the given graph is a tree of maximum degree 3 and each color may occur at most once [12]. However, in practice the parameter k is expected to be small, what motivates the research on so-called FPT algorithms parameterized by k, that is, algorithms with running times bounded from above by a function f (k) times a function polynomial in the input size, which is commonly abbreviated by O * (f (k)). Indeed, Fellows et al. [11] discovered that such an algorithm exists, which was followed by a rapid series of improvements to f (k) [11,1,13], culminating in the O * (2.54 k )-time algorithm of Koutis [16] (see Table 1).

Paper
Running time Approach Fellows et al. [11] O * (87 k ), implicit Color-coding Betzler et al. [1] O * (4.32 k ) Color-coding Guillemot and Sikora [13] O * (4 k ) Multilinear detection Koutis [16] O * (2.54 k ) Constrained multilinear detection this work O * (2 k ) Constrained multilinear detection Table 1. Progress on FPT algorithms for the k-sized graph motif problem From a high-level prespective the two key ideas underlying our main theorem in this section are (i) an observation of Guillemot and Sikora [13] that branching walks [19] yield an efficient polynomial generating function for connected sets, and (ii) Lemma 2 that builds on work by Koutis [16].
Our results. The coefficient µ = O(log k log log k log log log k) in the following theorem reflects the time complexity of basic arithmetic (addition, multiplication) in a finite field of size O(k) and characteristic 2 [6]. Theorem 4. There exists a Monte Carlo algorithm for Maximum Graph Motif that runs in O(2 k k 2 eµ) time and in polynomial space, with the following guarantees: (i) the algorithm always returns NO when given a NO-instance as input, (ii) the algorithm returns YES with probability at least 1/2 when given a YES-instance as input.
Remark. We observe that the algorithm in Theorem 4 runs in linear time in the number of edges e in the host graph H. Furthermore, the exponential part 2 k of the running time is caused by the sieve (2), implying that the algorithm can be executed in parallel on up to 2 k processors with essentially linear speedup. A caveat of the algorithm is that it solves only the YES/NO-decision problem, however, it can be extended to extract a solution set K at additional multiplicative cost k to the running time; this extension will be pursued elsewhere.
1.5. Weighted edit distance and the closest motif problem. A natural generalization of the basic graph motif framework is to allow for weighted inexact matches between the "target" motif M and a connected induced subgraph. Such variants have been studied in the literature, in particular by Dondi, Fertin, and Vialette [10] in the context of either (a) addition of colors to M or (b) substitutions of colors in M . We state both problems below as decision problems parameterized by k. Our objective here is to generalize the graph motif framework to weighted edit distance between M and c(K) by introducing a common generalization, the Closest Graph Motif problem. We then use Lemma 3 to obtain an O * (2 k )-time algorithm for the problem.

Min-Add Graph Motif
We start with some preliminaries to give a precise meaning to "closest" via the weighted edit distance. Let M be a multiset over a base set of colors C 0 . Let us allow to change M by means of three basic operations: (S) substitute one occurrence of a color q ∈ M with a color q ∈ C 0 , (I) insert one occurrence of a color q ∈ C 0 to M , and (D) delete one occurrence of a color q ∈ M from M .
For multisets M and N over C 0 , the cost (or weighted edit distance) to match M with N is the minimum cost of a sequence of basic operations that transforms M to N , where the cost of the sequence is the sum of costs of the basic operations in the sequence.

Closest Graph Motif
Input: A connected, undirected host graph H with n vertices and e edges, a multiset M of colors over a base color set C 0 , a coloring c : V (H) → C 0 for the vertices of H, nonnegative integer costs σ S , σ I , σ D , a threshold cost τ , and a positive integer k. Question: Is there a subset K ⊆ V (H) of size k such that (a) the subgraph induced by K in H is connected and (b) the cost to transform the multiset M into the multiset c(K) is at most τ ?
Our results. Our main result in this section is as follows.
Theorem 5. There exists a Monte Carlo algorithm for Closest Graph Motif that runs in O((2 k k 4 + |C 0 |k 3 )eµ) time and in polynomial space, with the following guarantees: (i) the algorithm always returns NO when given a NO-instance as input, (ii) the algorithm returns YES with probability at least 1/2 when given a YES-instance as input.
Remark. Similar remarks apply to Theorem 5 as with Theorem 4. In particular, the implementation of (3) with two cost parameters enables essentially linear parallel speedup on up to 2 k k 2 processors.
1.6. A lower bound. There is some evidence that the exponential part 2 k in the running time of the algorithms in Theorem 4 and Theorem 5 may be the best possible. Our approach is to proceed by reduction from the set cover problem.

Set Cover
Input: An integer t and a family of sets We show that for any > 0 the existence of an O * ((2 − ) k )-time algorithm for Maximum Graph Motif implies an O((2 − ) n )-time algorithm for Set Cover, for some > 0. Thus, instead of trying to improve our algorithm one should rather directly attack Set Cover, for which all attempts to obtain a O((2 − ) n )-time algorithm have failed, despite extensive effort. Indeed, the nonexistence of such an algorithm is already used as a basis for hardness results [7]. Furthermore, it is conjectured [7] that an O((2 − ) n )-time algorithm for Set Cover contradicts the Strong Exponential Time Hypothesis (SETH), which states that if k-CNF SAT can be solved in O * (c n k ) time, then lim k→∞ c k = 2. This conjecture is further supported by the fact that the number of solutions to an instance of Set Cover cannot be computed in O((2 − ) n ) time for any > 0 unless SETH fails [7]. A yet further consequence of such a counting algorithm would be the existence of an O((2 − ) n )time algorithm to compute the permanent of an n × n integer matrix [3].
Moreover, this holds even for instances of Maximum Graph Motif restricted to one of the following two extreme cases: (1) each color may occur at most once, or (2) there are exactly two colors.

Algebraic Tools
This section proves Lemma 2 and Lemma 3. We start with a proof of Lemma 1 that will act as a building block of both proofs.
2.1. Proof of Lemma 1. It will be convenient to work with a polynomial consisting of a single monomial, after which it will be easy to extend the analysis to an arbitrary polynomial. So suppose that Let us start by simplifying the expression into a more convenient form. Recalling and expanding the product-sum into a sumproduct, we have The outer sum in (5) is over all subsets A ⊆ L and the inner sums range over all Let us fix an arbitrary n- Now let us consider the outer sum over subsets A ⊆ L in (5). Observe that for a fixed A ⊆ L, our fixed n-tuple f = (f 1 , f 2 , . . . , f n ) occurs exactly once in the inner sums of (5) if and only if I(f ) ⊆ A. That is to say, the fixed f occurs exactly once for each A with I(f ) ⊆ A ⊆ L. The number of such A is 2 |L|−|I(f )| , which is even-and hence cancels in characteristic 2-if and only if I(f ) = L.
Let us say that f is surjective if I(f ) = L. Since all but surjective f cancel, from (5) and the previous analysis we thus have Next we show that (6) is identically zero unless Let us fix b to be the minimum such index. Consider an arbitrary surjective n-tuple f = (f 1 , f 2 , . . . , f n ). Since |L| = k = d 1 + d 2 + . . . + d n and f is surjective, we must have that for every i ∈ [n] the function f i is bijective, in particular thus Define the mate f of f by setting f i = f i for all i ∈ [n] \ {b} and Observe that f = f and that f = f . Thus, the set of all surjective f partitions Thus, all monomials in (6) have an even coefficient and hence cancel in character- In particular, from each monomial i∈K z i,g(i) we can recover both the set K and the bijection g : K → L, implying that no cancellation happens in characteristic 2. Furthermore, from K we can recover P (x 1 , x 2 , . . . , x n ) = i∈K x i .
The lemma now follows by linearity. Indeed, an arbitrary multivariate polynomial P (x 1 , x 2 , . . . , x n ) is a sum of monomials x d1 1 x d2 2 · · · x dn n .

2.2.
Proof of Lemma 2. We obtain cancellation in characteristic 2 using identical arguments to the proof of Lemma 1, up to and including adapting (7) to the setting of Lemma 2. That is, We proceed to show that the right-hand side of (8) is not identically zero if and only if the multilinear monomial i∈K x i is properly colored.
Let us say that a function h : K → S that associates a shade h(i) ∈ S to each i ∈ K is valid if it holds that h(i) ∈ S c(i) for all i ∈ K. Observe in particular that an injective valid h : K → S exists if and only if i∈K x i is properly colored.
We are now ready to start simplifying the right-hand side of (8). Recalling that u i,j = d∈S c(i) v i,d w d,j , expanding the product-sum into a sum-product, and changing the order of summation, we have The outer sum in (9) ranges over all valid functions h : K → S. Now, let us fix an arbitrary valid h : K → S. We will show that the inner sum in (9) evaluates to zero in characteristic 2 unless h is injective.
So suppose that h is not injective. In particular, there exists at least one pair b 1 , b 2 ∈ K with h(b 1 ) = h(b 2 ) and b 1 = b 2 . Let us fix (b 1 , b 2 ) to be the lexicographically minimum such pair. Consider an arbitrary bijective g : K → L. Define the mate g of g by setting otherwise.
Since g is bijective, we have g = g and g = g. Thus, the set of all bijections Thus, for each valid h : K → S that is not injective, the monomials in the inner sum in (9) have an even coefficient and hence vanish in characteristic 2. So suppose that h is injective. (Recall that such an h exists if and only if K defines a properly colored multilinear monomial.) Let us study the inner sum in (9). Fix an arbitrary bijective g : K → L and study the inner monomial . From the variables v i,d in the monomial we can reconstruct the set K and the mapping h. Because h is injective, we can reconstruct the mapping g from the variables w d,j in the monomial by setting g(h −1 (d)) = j for each relevant pair (d, j). Since the three-tuple (K, h, g) can be reconstructed from the inner monomial, no cancellation happens in characteristic 2.
The lemma follows again by linearity.
2.3. Proof of Lemma 3. Let π : S → C be the mapping that projects each shade d ∈ S q to its underlying color π(d) = q. Imitating the proof of Lemma 1 and expanding (4) over i ∈ K as in (9), we obtain cancellation in characteristic 2, except possibly for the monomials (10) h:K→S g:K→L g bijective η i∈K κi(π(h(i))) i∈K v i,h(i) w h(i),g(i) .
Imitating the proof of Lemma 2, we obtain further cancellation in characteristic 2 unless the mapping h is injective. So suppose that h is injective. Observe that we can reconstruct the threetuple (K, h, g) from the corresponding monomial in (10) exactly as in the proof of Lemma 2, and thus no further cancellation happens in characteristic 2. The degree of η is clearly the cost of the monomial i∈K x i in its coloring c = πh. In particular, we have that i∈K x i is properly colored in c since h is injective.
The lemma follows again by linearity.

2.4.
Remarks. It is immediate from the proofs that the polynomial P ( x) may have additional variables P ( x, y) without changing the conclusion as regards multilinearity and proper coloring of the monomials when restricted to the variables x. Furthermore, any monomial that has total degree less than k in the variables x will cancel. We observe that Lemma 3 subsumes Lemma 2. Indeed, given a coloring c : [n] → C we can set the costs for Lemma 3 so that κ i (q) = 0 if c(i) = q and κ i (q) = 1 otherwise. Then, P ( x) has at least one monomial that is both multilinear and properly colored if and only if Q( v, w, η) has at least one monomial whose degree in the variable η is σ = 0.

An Algorithm for the Maximum Graph Motif Problem
This section illustrates the use of Lemma 2 in a concrete algorithm design for Maximum Graph Motif. In particular, we proceed to give a proof of Theorem 4.
Consider an instance (H, M, C, c, k) of Maximum Graph Motif. Let us write m(q) for the number of occurrences of color q ∈ C in the multiset M . Also recall that we assume that the host graph H is connected with n vertices and e edges; in particular, e ≥ n − 1. By preprocessing we may assume that m(q) ≤ k for each q ∈ C.
Our first objective is to arrive at a generating polynomial P k ( x, y) that we can use with Lemma 2. There are two key aspects to this quest: (i) the multilinear monomials need to reflect the connected vertex sets of size k in H, and (ii) we must have a fast algorithm for evaluating the polynomial at specific points.
3.1. Branching walks. The concept of branching walks was first introduced by Nederlof [19] to sieve for Steiner trees, followed by Guillemot and Sikora [13] who observed that branching walks can also be employed to span connected vertex sets of size k in the host graph H. Our approach here is to capitalize on this observation and span connected sets via branching walks.
Let The walk is simple if ϕ is injective. Finally, the walk is properly ordered if any two sibling nodes a < b in T satisfy ϕ(a) < ϕ(b) in H.

3.2.
A generating polynomial for branching walks. We now define a generating polynomial for properly ordered branching walks of size k in H. Introduce a variable x u for each vertex u ∈ V (H) and two variables y (u,v) and y (v,u) for each edge {u, v} ∈ E(H).
Let W = (T, ϕ) be a properly ordered branching walk that starts from s ∈ V (H) and has size k. Associate with W the monomial fingerprint where the product is taken over all edges {a, b} ∈ E(T ). Define the generating polynomial P k,s ( x, y) as the sum of the monomial fingerprints of the properly ordered branching walks that start from s and have size k. Let P k ( x, y) = s∈V (H) x s P k,s ( x, y). Observe that all monomial in P k ( x, y) have total degree 2k − 1.

Lemma 7.
A monomial in P k ( x, y) is multilinear in the variables x if and only if it originates from a monomial fingerprint of a simple branching walk. Moreover, such a simple branching walk can be reconstructed from its monomial fingerprint.
Proof. For the first claim it suffices to consider an arbitrary monomial of P k ( x, y) and observe that the degree of the variable x u indicates how many times u ∈ V (H) occurs in the image of ϕ. In particular, ϕ is injective if and only if the monomial is multilinear in the variables x.
For the second claim, let W = (T, ϕ) be a simple and properly ordered branching walk that starts from s. We must reconstruct W from its monomial fingerprint that has been multiplied by x s . Since ϕ is injective, we can immediately reconstruct (up to labels of the vertices) the rooted tree structure of T because the degrees of the variables y (u,v) in the monomial (if any) reveal both the edges and the orientation of each edge in T . Since W is properly ordered, we can reconstruct (up to labels of the vertices) the ordering of T . Finally, we can reconstruct the vertex labels of T by carrying out a preorder traversal of T .
An immediate corollary of Lemma 7 is that (H, M, C, c, k) is a YES-instance of Maximum Graph Motif if and only if P k ( x, y) has a monomial that is both properly colored and multilinear in the sense of Lemma 2. Indeed, a multilinear monomial corresponds to a simple branching walk, which by definition spans a connected set of vertices. Conversely, every connected set of vertices admits at least one simple branching walk. Thus, to complete the proof of Theorem 4 it remains to derive a fast way to evaluate the polynomial P k ( x, y) and then apply Lemma 2 to obtain an algorihtm design.

3.3.
Evaluating the generating polynomial. This section develops a dynamic programming recurrence to evaluate the polynomial P k ( x, y) at a given assignment of values to the variables x, y.
For a vertex u ∈ V (H), denote the ordered sequence of neighbors of u in H by u 1 < u 2 < · · · < u deg H (u) .
For each u ∈ V (H), 1 ≤ i ≤ deg H (u) + 1, and 0 ≤ ≤ k, denote by W( , u, i) the set of properly ordered branching walks W = (T, ϕ) such that (i) the size of W is , (ii) W starts from u, and (iii) for any child node a of 1 in T it holds that ϕ(a) = u j implies j ≥ i. Define the associated generating polynomial over the variables x, y by It is immediate from the definition that P ,u ( x, y) = P ,u,1 ( x, y). The functions P ,u,i ( x, y) admit the following recurrence. The base case occurs for = 1 or i = deg H (u) + 1, in which case we have (11) P ,u,i ( x, y) = 1 if = 1, 0 otherwise.
To see that the recurrence is correct, observe that the two lines above in (12) correspond to a partitioning of the properly ordered branching walks in W( , u, i) into two disjoint classes where either (i) there is no child node a of 1 in T such that h(a) = u i or (ii) there is a unique such child. (At most one such child may exist because the branching walk is properly ordered.) Thus, we can evaluate the polynomial P k ( x, y) via (11), (12), and x u P k,u,1 ( x, y) .

The algorithm.
We are now ready to describe the algorithm for Theorem 4. Assume an instance (H, M, C, c, k) of the Maximum Graph Motif has been given as input. Let b = log 2 6k and consider the finite field F 2 b of order 2 b . Introduce variables v i,d and w d,j as in the setup of Lemma 2. Assign a value from F 2 b uniformly and independently at random to each of these variables. Similarly, as in the setup of §3.2, introduce two variables y (r,s) and y (s,r) to each edge {r, s} ∈ E(H) and assign a value to each variable uniformly and independently at random from F 2 b . We thus have three vectors of values in F 2 b , namely v, w, and y.
Using the recurrence given by (11), (12), and (13) for each A ⊆ L in turn, compute the value , w), . . . , u A n ( v, w)) are determined from the set A and the values v and w as in Lemma 2. If Q( v, w, y) is nonzero in F 2 b , output YES; otherwise output NO. This completes the description of the algorithm.

Running time.
To analyse the running time of the algorithm, observe that we can assume that m(q) ≤ k. Thus, computing the values u A ( v, w) for a fixed A ⊆ L takes O(k 2 n) arithmetic operations in F 2 b , and each such operation can be implemented to run in time µ = O(b log b log log b) [6]. Furthermore, each evaluation of (11), (12), and (13) for a fixed A takes O(k 2 e) arithmetic operations in F 2 b . Hence, recalling that e ≥ n−1, the total running time of the algorithm is O(2 k k 2 eµ).  (14) is an evaluation of a nonzero multivariate polynomial of total degree 3k − 1 at a point ( v, w, y) selected uniformly at random. Recalling that 2 b ≥ 6k, the following lemma thus implies that the value Q( v, w, y) is nonzero (and hence the algorithm outputs YES) with probability at least 1/2. Lemma 8 ([8,20,22]). A nonzero polynomial P (z 1 , z 2 , . . . , z ) of total degree d with coefficients in the finite field F q has at most dq −1 roots in F q .
This completes the proof of Theorem 4.

3.7.
Minor variants and extensions. The basic framework presented above immediately allows for some minor variants and extensions, such as seeking an exact match instead of the maximum match by setting |M | = k. Similarly, one may extend from a fixed coloring c : V (H) → C into a list coloring version where each vertex i ∈ V (H) gets associated a list C(i) ⊆ C of valid colors instead of a single color c(i), and the motif M may match against any one of the colors in the list. This variant can be implemented by simply changing the inner sum in Lemma 2 to u i,j = d∈∪ q∈C(i) Sq v i,d w d,j . That is, we sum over the shades of all the colors q in C(i).

An Algorithm for the Closest Graph Motif Problem
This section gives a proof of Theorem 5 using Lemma 3 and the generating function developed in §3.2.
Consider an instance (H, M, C 0 , c, σ S , σ I , σ D , τ, k) of Closest Graph Motif with V (H) = {1, 2, . . . , n}. Let us again write m(q) for the number of occurrences of color q ∈ C 0 in the multiset M . We may assume that m(q) ≤ k. Furthermore, since H is connected, the number of vertices n and the number of edges e satisfy e ≥ n − 1.
The key step in arriving at Theorem 5 is to transport weighted edit distance into the setting of Lemma 3.

4.1.
Optimum edit sequences. It will be convenient to have available the following lemma that characterizes the structure of a sequence of operations that realizes the minimum cost to transform a multiset M to the multiset N , where both multisets are over C 0 .
Let k = |N |. Consider an arbitrary sequence of basic operations that transforms M to N . As the sequence is executed, each original element of M gets assigned into one of three classes. First, there are k U elements in M that remain untouched (and hence in N ) when the execution terminates. Second, there are k S elements in M that undergo at least one substitution-which we may view as "recoloring" of the element-and remain in N when the execution terminates. Third, the remaining |M | − k U − k S elements of M get deleted during execution. Thus, at least k − k U − k S insertions must occur in the sequence. Let us call the values k U and k S the parameters of the sequence.

Lemma 9.
Let there exist at least one sequence with parameters k U and k S that transforms M into N . Then, the cost of this sequence is at least with equality for at least one sequence that transforms M into N .
Proof. The inequality is immediate from the preceding analysis; the sequence that meets equality (i) does nothing for the k U untouched original elements, (ii) substitutes the correct final color with one substitution for each of the k S originals, (iii) deletes each of the |M | − k U − k S remaining originals, and (iv) finally inserts k − k U − k S new elements to match with N .
Lemma 9 reveals a useful symmetry between insertions and deletions in an optimum sequence; that is, if we let k ID = k − k U − k S , then (15) is equal to (16) σ S k S + σ I + σ D k ID + σ D |M | − k .
Thus it suffices to optimize over k-multisets of colors while tracking the parameters k S and k ID to arrive at the optimum. This strategy will be employed in our algorithm.
4.2. The algorithm. Assume an instance (H, M, C 0 , c, σ S , σ I , σ D , τ, k) of Closest Graph Motif has been given as input.
Let us first set up the application of Lemma 3. Introduce a new color " * " and let C = C 0 ∪ { * } with m( * ) = k. As already highlighted in the remarks to Lemma 3, instead of one indeterminate η, we will work with two indeterminates η S and η ID in Lemma 3 to simultaneously track the S-cost and the ID-cost. For i ∈ [n] and q ∈ C, define the cost functions The intuition underlying (17) and (18) is as follows. Coloring a vertex i with color q / ∈ {c(i), * } corresponds to substitution of a copy of q in M by a copy of c(i). Coloring i with color " * " corresponds to inserting a copy of c(i) to M .
The algorithm now proceeds as follows. Let b = log 2 6k and consider the finite field F 2 b of order 2 b . Introduce variables v i,d and w d,j as in the setup of Lemma 3. Assign a value from F 2 b uniformly and independently at random to each of these variables. Similarly, as in the setup of §3.2, introduce two variables y (r,s) and y (s,r) to each edge {r, s} ∈ E(H) and assign a value to each variable uniformly and independently at random from F 2 b . We thus have three vectors of values in F 2 b , namely v, w, and y.
The main part of the algorithm consists of two outer loops that cycle through k + 1 distinct values in F 2 b to each of the variables η S and η ID . For each pair of values (η S , η ID ) in F 2 b , we use the recurrence given by (11), (12), and (13) for each A ⊆ L in turn, and compute the value where the values . . , u A n ( v, w, η S , η ID )) are determined from the set A and the values v and w as in Lemma 3, but with (4) replaced by (20) u for all i ∈ [n], j ∈ L, and A ⊆ L. When the main part terminates, we have available (k + 1) 2 evaluations of (19) at points (η S , η ID ).
By Lagrange interpolation, we recover (19) as a bivariate polynomial of total degree at most k in the indeterminates η S and η ID . If this bivariate polynomial has at least one monomial η kS S η kID ID such that the degrees k S and k ID satisfy then the algorithm outputs YES; otherwise the algorithm outputs NO. This completes the description of the algorithm.

4.3.
Running time. The analysis is essentially similar to §3.5, with two differences. First, the outer loop in the main part introduces a multiplicative factor k 2 compared with §3.5. Second, the implementation of (20) requires us to sum over all the shades originating from M and the k shades of the color " * ". This can be done efficiently by precomputing the inner sums d∈Sq v i,d w d,j for each color q ∈ C, index i ∈ [n], and label j ∈ L, which takes O (|M | + k)knµ time outside the main loops. In the outer loop of the main part it thus suffices to compute only the outer sum in (20) for each choice of (η S , η ID ), which leads to O |C 0 |knµ time for each iteration of the outer loop. In the inner loop over A ⊆ L, it takes O(knµ) time to prepare the vector u A ( v, w, η S , η ID ). Compared with §3.5, this gives a further contributing factor of |C 0 |k outside the inner loop. (The running time cost of the final interpolation step and the checking of the at most k 2 monomials of the bivariate polynomial Q( v, w, y, η S , η ID ) with respect to (21) is assumed to be subsumed by the running time bound.) 4.4. Correctness. We start by observing that (17) and (18) imply that (19) has total degree at most k in the variables η S and η ID , thus implying that Lagrange interpolation will correctly recover the polynomial in η S and η ID from the (k + 1) 2 evaluations computed in the main loop. Let us say that (19)-viewed as a polynomial in all the variables v, w, y, η S , η ID -is witnessing if there exists at least one monomial whose degrees k S and k ID satisfy (21). (19) is witnessing if and only if the given input is a YES-instance of Closest Graph Motif.

Lemma 10. The polynomial
Proof. In the "only if" direction, consider a monomial of (19) whose degrees k S and k ID satisfy (21). From Lemma 3 we have that the polynomial P k ( x, y) has at least one monomial that is both multilinear in x and admits a proper coloring with S-cost k S and ID-cost k ID . From §3.2 it follows that this monomial of P k ( x, y) corresponds to a simple branching walk in H and thus identifies a connected set K ⊆ V (H) of vertices in H. Furthermore, the existence of a proper coloring of the monomial implies by (17), (18), and Lemma 9 that there exists a sequence of basic operations that transforms the multiset M to the multiset c(K) with total cost (16). In particular, since k S and k ID satisfy (21), we have that (H, M, C 0 , c, σ S , σ I , σ D , τ, k) is a YES-instance of Closest Graph Motif.
In the "if" direction, let (H, M, C 0 , c, σ S , σ I , σ D , τ, k) be a YES-instance of Closest Graph Motif. Let K ⊆ V (H) be a solution set and consider an associated sequence ∆ of basic operations that transforms M to c(K) with cost at most τ . We may without loss of generality assume that the cost of the sequence ∆ satisfies equality in Lemma 9. In particular, from (16) we thus observe that the parameters k S and k ID of the sequence ∆ thus satisfy (21). Consider a simple branching walk of size k in H that spans the vertices in K. From §3.2 we observe that there is a corresponding multilinear monomial in P k ( x, y). Next observe that we can properly color this monomial in the sense of Lemma 3 by (i) assigning the color * to each of the k ID values i ∈ K that correspond to elements inserted in ∆, (ii) assigning the substituted color to each of the k S values i ∈ K that correspond to elements of M receiving substitutions in ∆, and (iii) assigning the color c(i) to each of the remaining k − k S − k ID values i ∈ K that correspond to elements of M that are not touched by ∆. Furthermore, by (17) and (18), this proper coloring has S-cost k S and ID-cost k ID . From Lemma 3 we thus have that (19)-viewed as a polynomial in the variables v, w, y, η S , η ID -has at least one monomial whose degrees k S and k ID satisfy (21).
Let us now study the operation of the algorithm in more detail. We have that the given input is a NO-instance if and only if (19) is not witnessing. Thus, given a NO-instance as input, the algorithm always gives a NO output.
So suppose that the given input is a YES-instance. Since (19) is witnessing, there exist degrees k S and k ID that are present in a monomial of (19) such that (21) holds. In particular, coefficient of the monomial η kS S η kID ID computed by the algorithm is an evaluation of a nonzero multivariate polynomial of total degree 3k − 1 at a point ( v, w, y) selected uniformly at random. Recalling that 2 b ≥ 6k, Lemma 8 thus implies that the coefficient is nonzero (and hence the algorithm outputs YES) with probability at least 1/2. This completes the proof of Theorem 5.

A Lower Bound Reduction from Set Cover
We base our proof of Theorem 6 on the following theorem, which can be extracted from the proof of Theorem 4.4 in a recent paper by Cygan et al. [7]. Theorem 11 ([7]). If Set Cover can be solved in O((2 − ) n+t ) time for some > 0 then it can also be solved in O((2 − ) n ) time, for some > 0. 5.1. Proof of Theorem 6. Let (S, t) be an instance of Set Cover. We are going to show a polynomial-time reduction to Maximum Graph Motif so that in the resulting instance (H, C, m, c, k) we have q∈C m(q) = k = n + t + 1. Combined with Theorem 11, this reduction will immediately establish our claim.
We show that (S, t) is a YES-instance if and only if (H, C, m, c, k) is a YESinstance. To establish the "only if" direction, suppose that S i1 , S i2 , . . . , S it is a solution of (S, t). Then let K = {r} ∪ U ∪ {s j ij : j = 1, 2, . . . , t}. It is clear that c(K) = C and that H[{r} ∪ {s j ij : j = 1, 2, . . . , t}] is connected. Since for every a ∈ U there is j = 1, 2, . . . , t such that a ∈ S ij , so {a, s j ij } ∈ E(G[K]). It follows that G[K] is connected, and hence K is a solution of (H, C, m, c, K). To establish the "if" direction, suppose that K is a solution of (H, C, m, c, k). Then for every j = 1, 2, . . . , t there is exactly one i j ∈ {1, 2, . . . , m} such that s j ij ∈ K, since c(K) = C. Moreover, since G[K] is connected we observe that for every a ∈ U there is a j = 1, 2, . . . , t such that {a, s j ij } ∈ E(G[K]). But then a ∈ S ij and it follows that S i1 , S i2 , . . . , S it is a solution of (S, t).
To establish part (2), let C = {1, 2} with m(1) = n + 1 and m(2) = t. Set c(r) = 1 and c(a) = 1 for every a ∈ U . All the remaining vertices are colored with 2. The proof of equivalence is similar to part (1) and is left to the reader.