An optimal XP algorithm for Hamiltonian cycle on graphs of bounded cliquewidth
Abstract.
For MSOexpressible problems like Edge Dominating Set or Hamiltonian Cycle, it was open for a long time whether there is an algorithm which given a cliquewidth 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 twoedge colored multigraphs on vertices. The essential idea behind is that for a twoedge 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:
XPalgorithm, Hamiltonian cycle, cliquewidth1. Introduction
Treewidth is one of the graph width parameters that plays an important role in graph algorithms. Various problems which are NPhard on general graphs, have been shown to be solvable in polynomial time on graphs of bounded treewidth [1, 2]. A celebrated algorithmic metatheorem by Courcelle [3] states that every graph property expressible in monadic secondorder logic which allows quantifications over edge and vertex sets (MSO) can be decided in linear time on graphs of bounded treewidth. Minimum Dominating Set, Coloring, and Hamiltonian Cycle problems are such graph problems.
Courcelle and Olariu [5] defined the notion of cliquewidth of graphs, whose modeling power is strictly stronger than treewidth. The motivation of cliquewidth 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 metatheorem on graphs of bounded treewidth [3] to graphs of bounded cliquewidth, 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 MSOdefinable, but not MSOdefinable are MaxCut, 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 cliquewidth 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 MaxCut 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 cliquewidth in Section 2.
Hamiltonian Cycle Input : A graph Question : Does have a Hamiltonian cycle?
Theorem 1.1.
Given an vertex graph and its cliquewidth expression, one can solve Hamiltonian Cycle in time .
A labeled graph is a graph whose vertices are labeled by integers in . Cliquewidth 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 cliquewidth 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 cliquewidth expression admits a partition of its vertex set into pairwise vertexdisjoint paths, pathpartitions, 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 pathpartitions. Given a pathpartition that is a restriction of a Hamiltonian cycle , we consider the maximal paths in as another pathpartition . 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 pathpartitions 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 pathpartitions. This motivates an equivalence relation between pathpartitions. 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 twoedge 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 pathpartitions in cliquewidth 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 nonnegative 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 cutedge 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 nontrivial 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. Cliquewidth
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 cliquewidth of a graph is the minimum number of labels needed to construct using the following four operations:

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

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

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

Renaming label to (denoted by ).
Every graph can be defined by an algebraic expression using these four operations. Such an expression is called a cliquewidth 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 treestructure, depicted in Figure 2. Such trees are known as syntactic trees associated with expressions.
A cliquewidth 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 cliquewidth expression, it can be transformed into an irredundant expression in linear time. Therefore, we can assume that a given cliquewidth expression is irredundant.
2.2. Pathpartition
For a graph , a set of pairwise vertexdisjoint paths in is called a pathpartition of if . A pathpartition is labeled if each end vertex of a path in is labeled by some integer in . For a pathpartition 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 pathpartition 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 cliquewidth 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:

for two vertices with same labels in , ,

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 pathpartition 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 pathpartitions. Our algorithm will be based on the following characterization of equivalent pathpartitions.
We formally prove the following relations between two pathpartitions in Section 5.
Proposition 5.2.
Let and be labeled pathpartitions of whose labelings are induced by the labeling of . If

and

is a component of is a component of ,
then the following are equivalent.

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

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 pathpartitions 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 onetoone correspondence between the endvertices 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 pathpartition 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 redblue 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 redblue alternating Eulerian trail if and only if for every vertex , .
Proof.
It is clear that if has a redblue alternating Eulerian trail, then for every vertex , . We prove the other direction. Let be the number of edges in . We choose a redblue alternating trail with maximum such that is colored red, and there is exactly one nontrivial 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 cutedge in incident with . If there are two cutedges incident with , then one cutedge 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 cutedge 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 redblue alternating trail. Thus, we may assume there is only one edge incident with and it is a cutedge of . By the condition, is not adjacent to any red edge in , and thus it has degree in . Therefore, has only one nontrivial component, and it implies that we can choose as a next edge to extend the redblue 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 cutedge. Suppose and . In this case, should be a blue edge. Note that by the condition that there is at least one nontrivial 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 cutedge. Suppose for contradiction that there is only one red edge incident with in and it is a cutedge in . By the assumption, there is exactly one blue edge incident with in . Since one of two edges incident with is not a cutedge, the other one is also not a cutedge. It contradicts to the assumption. Thus, we can choose a red edge that is not a cutedge.
In each case, we can extend the redblue alternating trail using , which contradicts to the maximality. Therefore , and should be connected to by a blue edge . Thus, is a required redblue alternating Eulerian trail. ∎
Indeed, when we replace with in , the set of components does not change (thus consists of one nontrivial 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 pathpartitions, 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 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:

is the set of all multigraphs where can be obtained from a multigraph in as follows
^{1} : choose two distinct edges and , and let be the multigraph on vertex set and edge set with mapped to . 
is the set constructed from by doing the operation times.

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 .

.
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 nontrivial component, there exists such that and has at most one nontrivial 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 nontrivial 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 nontrivial 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 nontrivial components. First observe that the four vertices are in the same nontrivial component of , and are in a same nontrivial component of . If is another nontrivial component of , then it does not intersect , i.e., is nontrivial component in that does not intersect the one containing , yielding a contradiction.
Since , there exists such that
and has at most one nontrivial
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 nontrivial 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 nontrivial 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 nontrivial component.
Since , there exists such that
and has at most one nontrivial
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 nontrivial 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 nontrivial 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 nontrivial 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 pathpartitions.
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 vertexset , 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 cliquewidth expression , and let be a node in the syntactic tree. Let be the labeled graph constructed at , and let and be labeled pathpartitions of whose labelings are induced by the labeling of . If , then the following are equivalent.

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

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 pathpartition 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 nontrivial connected component, and
Since by the assumption, has at most one nontrivial connected component and
Therefore, by Lemma 3.1, admits an Eulerian trail where the edges in and the edges in are alternatively used.
Now, we show that has a Hamiltonian cycle