A tight XP Algorithm for Deciding Hamiltonicity Parameterized by CWD

# An optimal XP algorithm for Hamiltonian cycle on graphs of bounded clique-width

## Abstract.

For MSO-expressible problems like Edge Dominating Set or Hamiltonian Cycle, it was open for a long time whether there is an algorithm which given a clique-width -expression of an -vertex graph runs in time for some function . Recently, Fomin et al. (SIAM. J. Computing, 2014) presented several lower bounds; for instance, there are no -time algorithms for Edge Dominating Set and for Hamiltonian Cycle unless the Exponential Time Hypothesis (ETH) fails. They also provided an algorithm running in time for Edge Dominating Set, but left open whether Hamiltonian Cycle can be solved in time .

In this paper, we prove that Hamiltonian Cycle can be solved in time . This improves the naive algorithm that runs in time by Espelage et al. (WG 2001). We present a general technique of representative sets using two-edge colored multigraphs on vertices. The essential idea behind is that for a two-edge colored multigraph, the existence of an Eulerian trail that uses edges with different colors alternatively can be determined by two information, that are the number of colored edges incident with each vertex and the number of connected components containing an edge. This allows to avoid storing all possible graphs on vertices with at most edges, which gives the running time. We can apply this technique to other problems such as -Cycle Covering or Directed Hamiltonian Cycle as well.

###### Key words and phrases:
XP-algorithm, Hamiltonian cycle, clique-width
B. Bergougnoux and M.M. Kanté are supported by French Agency for Research under the GraphEN project (ANR-15-CE-0009). O. Kwon is supported by the European Research Council (ERC) under the European Union’s Horizon 2020 research and innovation programme (ERC consolidator grant DISTRUCT, agreement No. 648527).

## 1. Introduction

Tree-width is one of the graph width parameters that plays an important role in graph algorithms. Various problems which are NP-hard on general graphs, have been shown to be solvable in polynomial time on graphs of bounded tree-width [1, 2]. A celebrated algorithmic meta-theorem by Courcelle [3] states that every graph property expressible in monadic second-order logic which allows quantifications over edge and vertex sets (MSO) can be decided in linear time on graphs of bounded tree-width. Minimum Dominating Set, -Coloring, and Hamiltonian Cycle problems are such graph problems.

Courcelle and Olariu [5] defined the notion of clique-width of graphs, whose modeling power is strictly stronger than tree-width. The motivation of clique-width came from the observation that many algorithmic problems are tractable on classes of graphs that can be recursively decomposable along vertex partitions where the number of neighbourhood types between and are small. Courcelle, Makowsky, and Rotics [4] extended the meta-theorem on graphs of bounded tree-width [3] to graphs of bounded clique-width, at a cost of a smaller set of problems, namely, the class of problems expressible in MSO, which allows quantifications on vertex sets only. Some of the known examples of graph problems that are MSO-definable, but not MSO-definable are Max-Cut, Edge Dominating Set, and Hamiltonian Cycle problems.

A natural question is whether such problems allow an algorithm with running time for some function , when a clique-width -expression of an -vertex input graph is given. This question has been carefully answered by Fomin et al. [8, 9]. In particular, they showed that for Max-Cut and Edge Dominating Set, there is no -time algorithm unless the Exponential Time Hypothesis (ETH) fails, and proposed for both problems algorithms with running time . They argued that Hamiltonian Cycle also cannot be solved in time , unless ETH fails, but left open the question of finding an algorithm running in time . Until now, the best algorithm is the one by Espelage, Gurski, and Wanke [7] which runs in time .

### Our Contribution.

In this paper, we prove that Hamiltonian Cycle can be solved in time , thereby resolving the open problem in [9]. A Hamiltonian cycle in a graph is a cycle containing all vertices of the graph. We formally define clique-width in Section 2.

Hamiltonian Cycle Input : A graph Question : Does have a Hamiltonian cycle?

###### Theorem 1.1.

Given an -vertex graph and its clique-width -expression, one can solve Hamiltonian Cycle in time .

A -labeled graph is a graph whose vertices are labeled by integers in . Clique-width -expressions are expressions which allow to recursively construct a graph with the following graph operations: (1) creating a graph with a single vertex labeled for some ,  (2) taking the disjoint union of two -labeled graphs,  (3) adding all edges between vertices labeled and vertices labeled , for ,  (4) renaming all vertices labeled into . The clique-width of a graph is the minimum such that it can be constructed using labels in . One observes that if a graph contains a Hamiltonian cycle , then each -labeled graph introduced in the clique-width -expression admits a partition of its vertex set into pairwise vertex-disjoint paths, path-partitions, which is a restriction of the Hamiltonian cycle . A natural approach is to enumerate all such partitions into paths. Furthermore, since the adjacency relations between this -labeled graph and the remaining part only depend on the labels, it is sufficient to store for each pair of labels , the number of paths whose end vertices are labeled by and . As the number of paths between two label classes is bounded by , there are at most possible such information. This is the basic idea of the XP algorithm developed by Espelage, Gurski, and Wanke [7].

The essential idea is to introduce an equivalence relation between two path-partitions. Given a path-partition that is a restriction of a Hamiltonian cycle , we consider the maximal paths in as another path-partition . As depicted in Figure 1, we can construct a multigraph associated with and on the vertex set , by adding a red edge (an undashed edge) if there is a path in with end vertices labeled by and , and by adding a blue edge (a dashed edge) if there is a path in with end vertices labeled by and . A crucial observation is that this multigraph admits an Eulerian trail where red edges and blue edges are alternatively used. This is indeed a characterisation of the fact that two such path-partitions can be joined into a Hamiltonian cycle. To determine the existence of such an Eulerian trail, it is sufficient to know the degree of each vertex and the connected components of the corresponding multigraphs of the two path-partitions. This motivates an equivalence relation between path-partitions. As a byproduct, we can keep in each equivalence class a representative and since the number of equivalence classes is bounded by , we can turn the naive algorithm into an -time algorithm. A more detailed explanation of our algorithm is provided in Section 3, after the required definitions.

The paper is organized as follows. Section 2 contains the necessary preliminaries and required notions. Section 3 is devoted to the overview of the algorithm and the proof of the existence of Eulerian trails in two-edge colored multigraphs. We then introduce in Section 4 the equivalence relation between multigraphs on the vertex set , and introduce operations related to the update of path-partitions in clique-width -expressions, and prove that they preserve the equivalence relation. We define the notion of representatives in Section 5.1 and give the algorithm in Section 5.2. We conclude with more applications of our notion of representatives in Section 6.

## 2. Preliminaries

The size of a set is denoted by , and we write to denote the set of all subsets of of size . We denote by the set of non-negative integers.

We essentially follow [6] for our graph terminology, but we deal only with finite graphs. The vertex set of a graph is denoted by and its edge set by . As usual, we write to denote an edge . Let be a graph. For , we denote by the subgraph of induced by , and for , we write for the subgraph . The degree of a vertex , denoted by , is the number of edges incident with . For two sets , is complete to if for every and , . A cut-edge in a connected graph is an edge such that is disconnected. We recall that a cycle in a graph is a Hamiltonian cycle if it covers all vertices of .

A graph is non-trivial if it contains an edge, otherwise it is said trivial. A walk of a graph is an alternating sequence of vertices and edges, starting and ending at some vertices, where for every consecutive pair of a vertex and an edge , is incident with . A trail of a graph is a walk where each edge is used at most once. A trail is closed if its first and last vertices are the same.

A multigraph is essentially a graph, but we allow two edges to be incident with the same set of vertices. Formally, a multigraph is a pair of disjoint sets, also called sets of vertices and edges, respectively, together with a map , which maps every edge to one or two vertices, still called its end vertices. Note that we admit loops in multigraphs, while we do not in our definition of graphs. If there is such that (or ), we use the term multiedge to refer to (or ). The degree of a vertex in a multigraph , is defined analogously as in graphs, except that each loop is counted twice, and similarly for other notions. If there are exactly edges such that (or ), then we denote these distinct edges by (or ); if , then for the sake of clarity, we write (or ) instead of (or ).

An Eulerian trail in a multigraph is a closed trail containing all edges.

### 2.1. Clique-width

A graph is -labeled if there is a labeling function , and we call the label of . For a -labeled graph , we simply call the set of all vertices with label as the label class of .

The clique-width of a graph is the minimum number of labels needed to construct using the following four operations:

1. Creation of a new vertex with label (denoted by ).

2. Disjoint union of two labeled graphs and (denoted by ).

3. Joining by an edge each vertex with label to each vertex with label (, denoted by ).

4. Renaming label to (denoted by ).

Every graph can be defined by an algebraic expression using these four operations. Such an expression is called a clique-width -expression or shortly a -expression if it uses at most distinct labels.

For instance, the cycle of length can be constructed using the following -expression: . We can represent this expression as a tree-structure, depicted in Figure 2. Such trees are known as syntactic trees associated with -expressions.

A clique-width -expression is called irredundant if whenever is applied, the constructed graph contains no prior edges between vertices with label and vertices with label . Courcelle and Olariu [5] proved that given a clique-width -expression, it can be transformed into an irredundant -expression in linear time. Therefore, we can assume that a given clique-width expression is irredundant.

### 2.2. Path-partition

For a graph , a set of pairwise vertex-disjoint paths in is called a path-partition of if . A path-partition is -labeled if each end vertex of a path in is labeled by some integer in . For a path-partition of a -labeled graph , the labeling of induced by the labeling of consists in assigning to each end vertex of a path in its label in . Lastly, for a -labeled path-partition of a graph, we define the auxiliary multigraph with vertex set and edge set where is the number of paths in with end vertices labeled and respectively.

## 3. Overview of the algorithm

In an irredundant clique-width -expression defining a given graph , is recursively constructed using -labeled graphs. Such -labeled graphs arising in the -expression defining are subgraphs of and satisfy the following properties:

1. for two vertices with same labels in , ,

2. for some label class , say , and label class , say , in with , if there exist , with , then is complete to in , and there are no edges between and in .

In (2), the former statement is because when we add , all vertices in each set of or have same labels, and the latter statement is because of the irredundancy of . Given such a -labeled subgraph of , for any Hamiltonian cycle , the restriction of to induces a -labeled path-partition of . Because of the two properties (1) and (2), it is sufficient to store the end vertices of each path. This is naturally represented as a multigraph on vertices, motivating the definition of the auxiliary multigraphs associated with -labeled path-partitions. Our algorithm will be based on the following characterization of equivalent path-partitions.

We formally prove the following relations between two path-partitions in Section 5.

###### Proposition 5.2.

Let and be -labeled path-partitions of whose labelings are induced by the labeling of . If

• and

• is a component of is a component of ,

then the following are equivalent.

1. has a Hamiltonian cycle containing each path in as a subpath and such that every edge in is contained in .

2. has a Hamiltonian cycle containing each path in as a subpath and such that every edge in is contained in .

Suppose there are two such path-partitions and , and has a Hamiltonian cycle containing each path in as a subpath and such that every edge in is contained in . Let be the subpaths of connecting two consecutive paths in . See Figure 1 for an illustration, where dashed edges denote the paths of . Note that if a path in is an edge, then it is an edge between two label classes, and since is an irredundant -expression, these two label classes are completely adjacent to each other.

One can observe that there is a one-to-one correspondence between the end-vertices of and those of . Let us label each end vertex of a path in as the label of , We consider the auxiliary multigraph and the auxiliary multigraph by considering as a path-partition of the underlying graph on . We obtain a multigraph from the disjoint union of and by identifying each . Following the Hamiltonian cycle , one easily checks that there is an Eulerian trail which alternates between edges in and edges in .

We will prove that if we replace with in , then the new graph also admits an Eulerian trail, because of the given conditions in Proposition 5.2. To see this, we observe the following, which is a strengthen of Euler’s theorem on Eulerian trails. It is well known that a connected multigraph contains an Eulerian trail if and only if every vertex has even degree. Moreover, when edges are colored by two colors, say red and blue, and each vertex is incident with the same number of edges for both colors, then we can find an Eulerian trail where the two colors appear alternatively. We call such an Eulerian trail a red-blue alternating Eulerian trail. For a multigraph colored by red and blue and , let denote the number of red edges incident with , and let denote the number of blue edges incident with .

###### Lemma 3.1.

Let be a connected multigraph whose edges are colored by red and blue. Then the following are equivalent. Then has a red-blue alternating Eulerian trail if and only if for every vertex , .

###### Proof.

It is clear that if has a red-blue alternating Eulerian trail, then for every vertex , . We prove the other direction. Let be the number of edges in . We choose a red-blue alternating trail with maximum such that is colored red, and there is exactly one non-trivial component of , and contains and , and in ,

• for each , ,

• if , and is colored red (resp. blue), then (resp. ) and .

• if , then or .

We claim . Suppose . Note that there are at least two edges in .

We observe that there are at most one cut-edge in incident with . If there are two cut-edges incident with , then one cut-edge satisfies that has a connected component that does not contain and . However, all vertices in satisfy by the assumption, and in particular, they have even degrees, and this is not possible. Therefore, there are at most one cut-edge in incident with .

Suppose and is colored red. The proof is symmetric when is colored blue. If there is a blue edge incident with in , then we can choose as a next edge to extend the red-blue alternating trail. Thus, we may assume there is only one edge incident with and it is a cut-edge of . By the condition, is not adjacent to any red edge in , and thus it has degree in . Therefore, has only one non-trivial component, and it implies that we can choose as a next edge to extend the red-blue alternating trail.

Suppose and . In this case, should be a red edge. Since there are at least two blue edges incident with in , we can choose a blue edge that is not a cut-edge. Suppose and . In this case, should be a blue edge. Note that by the condition that there is at least one non-trivial connected component containing and , and thus there is at least one red edge incident with in . We claim that there is at least one red edge among them that is not a cut-edge. Suppose for contradiction that there is only one red edge incident with in and it is a cut-edge in . By the assumption, there is exactly one blue edge incident with in . Since one of two edges incident with is not a cut-edge, the other one is also not a cut-edge. It contradicts to the assumption. Thus, we can choose a red edge that is not a cut-edge.

In each case, we can extend the red-blue alternating trail using , which contradicts to the maximality. Therefore , and should be connected to by a blue edge . Thus, is a required red-blue alternating Eulerian trail. ∎

Indeed, when we replace with in , the set of components does not change (thus consists of one non-trivial component), and each vertex is incident with same number of red and blue edges, and by Lemma 3.1, the resulting graph has an Eulerian trail. We will argue that one can construct a Hamiltonian cycle of from paths of using the properties (1) and (2) at the beginning of this section.

Motivated by Proposition 5.2, we define in Section 4 an equivalence relation between two sets of multigraphs on the same vertex set . We further define operations on those multigraphs, corresponding to procedures of updating path-partitions, and prove that the equivalence between two sets is preserved under such operations. These results will form the skeleton of the main algorithm.

## 4. An equivalence relation between families of k-vertex multigraphs

For two multigraphs and on the same vertex set and with disjoint edge sets, we denote by the multigraph with vertex set and edge set .

For families of multigraphs on the vertex set and two distinct integers , we define the following operations:

1. is the set of all multigraphs where can be obtained from a multigraph in as follows1: choose two distinct edges and , and let be the multigraph on vertex set and edge set with mapped to .

2. is the set constructed from by doing the operation times.

3. is the set of all multigraphs where can be obtained from a multigraph in by replacing every edge by an end vertex with an edge with an end vertex .

4. .

Let and be two families of multigraphs on the vertex set . We write if for every multigraph on the vertex set ,

• whenever there exists such that and has at most one non-trivial component, there exists such that and has at most one non-trivial component.

We say that is equivalent to , written , if and .

We prove that the equivalence between two families is preserved by the operation .

###### Proposition 4.1.

Let and be two families of multigraphs on the vertex set . If , then .

###### Proof.

Suppose . It is sufficient to prove that . For this, suppose there exist a graph on and such that and has at most one non-trivial component. Since , there exist , edges , in such that with mapped to in . Let with mapped to in . We claim that

• and

• has at most one non-trivial component.

By the construction of from , for every , has the same degree in and , and the degrees of and in are one less than the degrees in , respectively. Since the degrees of and in are one more than the degrees in , we have . Assume now that has at least two non-trivial components. First observe that the four vertices are in the same non-trivial component of , and are in a same non-trivial component of . If is another non-trivial component of , then it does not intersect , i.e., is non-trivial component in that does not intersect the one containing , yielding a contradiction.

Since , there exists such that
and has at most one non-trivial component. By Lemma 3.1, contains an Eulerian trail where edges in and edges in are alternatively used. Let and be the edges where appear in the Eulerian trail in this order (recall that is mapped to ). Clearly, if we remove the edges and add an edge mapped to in , then the obtained multigraph still admits an alternating Eulerian trail. Let with mapped to in . One easily checks that , and since has an Eulerian trail where edges in and edge in are alternatively used, by Lemma 3.1, and has at most one non-trivial component. Because , we can thus conclude that . ∎

We prove a similar property for the other operations.

###### Proposition 4.2.

Let and be families of multigraphs on the vertex set and let be two distinct integers. If , then .

###### Proof.

Suppose . It is sufficient to prove that . Suppose there exist a graph on and such that and has at most one non-trivial component. By Lemma 3.1, there is an Eulerian trail where edges of and edges of are alternatively used. Since , there exists such that is obtained from by replacing every edge with an end vertex with an edge with an end vertex . Clearly, we can construct from by reversing each of these operations. We construct the multigraph from as follows :

• following the construction of from , whenever an edge is replaced with for some , we replace the edge with in where and are consecutive edges in .

This operation preserves the existence of an alternating Eulerian trail. It implies that
and also has at most one non-trivial component.

Since , there exists such that
and has at most one non-trivial component. In other words, has an Eulerian trial where edges in and edges in are alternatively used. Similar to the previous procedure, we can obtain a graph form by following the construction of from , such that and has an Eulerian trail where edges in and edges in are alternatively used. By Lemma 3.1 and has at most one non-trivial component, and we conclude that . ∎

###### Proposition 4.3.

Let be families of multigraphs on the vertex set . If , then .

###### Proof.

Suppose . It is sufficient to prove that . Suppose there exist a graph on and and such that
and has at most one non-trivial component. Thus, has an Eulerian trail where edges in and edges in are alternatively used. Clearly, . Now, we obtain a graph from by successively repeating the following: if is a maximal path in which alternates between edges of and those of , remove all the edges of and add an edge between the two endpoints of the . Notice that by replacing in each maximal path alternating between edges of and of , by the edge , we obtain an Eulerian trail alternating between edges of and edges of .

Since , there exists such that has an Eulerian trail where edges in and edges in are alternatively used. We can replace each edge of with in , obtaining an Eulerian trail of which alternates between edges of and of . Therefore, and has at most one non-trivial component. This concludes the proof of the statement. ∎

## 5. Hamiltonian Cycle problem

We prove the main result of this paper.

###### Theorem 1.1.

Given a graph and its -expression, one can solve Hamiltonian Cycle in time .

### 5.1. Equivalence between partial solutions

We now define formally our notion of representatives based only on the degree sequence and connected components of auxiliary multigraphs associated with -labeled path-partitions.

###### Definition 5.1 (Representatives by auxiliary multigraphs).

Let and be multigraphs on vertex set . We write whenever
and is a component of is equal to is a component of . One easily checks that is an equivalence relation on any set of multigraphs on vertex set .

For a family of multigraphs on vertex-set , let be the operation which takes in each equivalence class of a representative.

The goal of this section is to prove the following.

###### Proposition 5.2.

Let be a graph with its irredundant clique-width -expression , and let be a node in the syntactic tree. Let be the -labeled graph constructed at , and let and be -labeled path-partitions of whose labelings are induced by the labeling of . If , then the following are equivalent.

1. has a Hamiltonian cycle containing each path in as a subpath and such that every edge in is contained in .

2. has a Hamiltonian cycle containing each path in as a subpath and such that every edge in is contained in .

###### Proof.

By symmetry, it is sufficient to prove that (1) implies (2). Suppose has a Hamiltonian cycle containing each path in as a subpath and such that every edge in is contained in . Let be the set of all maximal paths in , and let . We consider as the path-partition of where the end vertices of paths in are labeled by their labels in .

Since is a Hamiltonian cycle, has an Eulerian trail where edges in and edges in are alternatively used. Thus has at most one non-trivial connected component, and

 (degAux(P1)(v1),…,degAux(P1)(vk))=(degAux(Q)(v1),…,degAux(Q)(vk)).

Since by the assumption, has at most one non-trivial connected component and

 (degAux(P2)(v1),…,degAux(P2)(vk))=(degAux(Q)(v1),…,degAux(Q)(vk)).

Therefore, by Lemma 3.1, admits an Eulerian trail where the edges in