1 Introduction

The Graph Isomorphism problem, which is that of deciding whether two given graphs are isomorphic, is a central problem in Computer Science. It is not known whether Graph Isomorphism is polynomial-time solvable. However, it is not NP-complete unless the polynomial hierarchy collapses [29]. Analogously to the use of the notion of NP-completeness, we can say that a problem is Graph Isomorphism-complete (abbreviated to GI-complete). Babai [1] proved that Graph Isomorphism can be solved in quasi-polynomial time.

In order to increase understanding of the computational complexity of Graph Isomorphism, it is natural to place restrictions on the input. This approach has established that on many graph classes Graph Isomorphism is polynomial-time solvable, but that on many others the problem remains GI-complete. We refer to [16] for a survey, but some recent examples include a polynomial-time algorithm for unit square graphs [26], a complexity dichotomy for H-induced-minor-free graphs [3] and a polynomial-time algorithm for graphs of bounded maximum degree [18] (improving on the runtime of previous polynomial-time algorithms on graphs of bounded maximum degree [2, 25]).

In this paper we consider the Graph Isomorphism problem for hereditary graph classes, which are the classes of graphs that are closed under vertex deletion. It is readily seen that a graph class \(\mathcal{G}\) is hereditary if and only if there exists a family of graphs \({\mathcal{F}}_{\mathcal{G}}\), such that the following holds: a graph G belongs to \(\mathcal{G}\) if and only if G does not contain any graph from \({\mathcal{F}}_{\mathcal{G}}\) as an induced subgraph. We implicitly assume that \({\mathcal{F}}_{\mathcal{G}}\) is a family of minimal forbidden induced subgraphs, in which case \({\mathcal{F}}_{\mathcal{G}}\) is unique. We note that \({\mathcal{F}}_{\mathcal{G}}\) may have infinite size. For instance, if \(\mathcal{G}\) is the class of bipartite graphs, then \({\mathcal{F}}_{\mathcal{G}}\) consists of all odd cycles.

A natural direction for a systematic study of the computational complexity of Graph Isomorphism is to consider graph classes \(\mathcal{G}\), for which \({\mathcal{F}}_{\mathcal{G}}\) is small, starting with the case where \({\mathcal{F}}_{\mathcal{G}}\) has size 1. A graph is H-free if it does not contain H as induced subgraph; conversely, we write \(H \subseteq _iG\) to denote that H is an induced subgraph of G. The classification for H-free graphs can be found in a technical report of Booth and Colbourn [6], who credit the result to an unpublished manuscript of Colbourn and Colbourn; another proof of it appears in a paper of Kratsch and Schweitzer [22].

Theorem 1

(see [6, 22]) Let H be a graph. Then Graph Isomorphism on H-free graphs is polynomial-time solvable if \(H \subseteq _i P_4\) and GI-complete otherwise.

Later, Colbourn [10] proved that Graph Isomorphism is polynomial-time solvable even for the class of permutation graphs, which form a superclass of the class of \(P_4\)-free graphs. Classifying the case where \({\mathcal{F}}_{\mathcal{G}}\) has size 2 is much more difficult than the size-1 case. Kratsch and Schweitzer [22] initiated this classification. Schweitzer [30] later extended the results of [22] and proved that only a finite number of cases remain open. This leads to our research question:

Is it possible to determine the computational complexity of Graph Isomorphism for \((H_1,H_2)\)-free graphsFootnote 1for all pairs \(H_1,H_2\)?

The analogous research question for H-induced-minor-free graphs was fully answered by Belmonte, Otachi and Schweitzer [3], who also determined all graphs H for which the class of H-induced-minor-free graphs has bounded clique-width. Similar classifications for Graph Isomorphism [28] and boundedness of clique-width [15] are also known for H-minor-free graphs.

Lokshtanov et al. [23] recently gave an FPT algorithm for Graph Isomorphism with parameter k on graph classes of treewidth at most k, and this has since been improved by Grohe et al. [19]. Whether an FPT algorithm exists when parameterized by clique-width is still open. Grohe and Schweitzer [20] proved membership of XP.

Theorem 2

[20] For every constant c, Graph Isomorphism is polynomial-time solvable on graphs of clique-width at most c.

Grohe and Neuen [17] have since improved this result by showing that the more general Canonisation problem is also in XP when parameterized by clique-width.

1.1 Our Results

By combining known results with Theorem 2 we narrow the list of open cases for Graph Isomorphism on \((H_1,H_2)\)-free graphs to 14. Of these 14 cases, we prove that three of them are polynomial-time solvable (Sect. 3) and five others are GI-complete (Sect. 4). Thus we reduce the number of open cases to six.

Besides Theorem 2, there is another reason why results for clique-width are of importance for Graph Isomorphism. Namely, Schweitzer [30] pointed out great similarities between proving unboundedness of clique-width of some graph class \(\mathcal{G}\) and proving that Graph Isomorphism stays GI-complete for \(\mathcal{G}\). We will illustrate these similarities by showing that our construction demonstrating that Graph Isomorphism is GI-complete for \(({{\mathrm{gem}}},P_1+2P_2)\)-free graphs can also be used to show that this class has unbounded clique-width. This reduces the number of pairs \((H_1,H_2)\) for which we do not know if the class of \((H_1,H_2)\)-free graphs has bounded clique-width from six [14] to five. As such, our paper also continues a project [4, 8, 11, 12, 14, 15] aiming to classify the boundedness of clique-width of \((H_1,H_2)\)-free graphs for all pairs \((H_1,H_2)\); see Sect. 5 (or a recent survey on clique-width [13]) for an overview of the known and open cases.

In Sect. 6 we present our main theorem, which states exactly for which classes of \((H_1,H_2)\)-free graphs Graph Isomorphism is known to be polynomial-time solvable, for which it is GI-complete and for which six cases the complexity remains open.

2 Preliminaries

We consider only finite, undirected graphs without multiple edges or self-loops. An isomorphism from a graph G to a graph H is a bijection \(f:V(G) \rightarrow V(H)\) such that \(vw \in E(G)\) if and only if \(f(v)f(w) \in E(H)\). For a function \(f:X \rightarrow Y\), if \(X^{\prime } \subseteq X\), we define \(f(X^{\prime }):=\{f(x) \in Y \;|\; x \in X^{\prime }\}\). The Graph Isomorphism problem is defined as follows.

Graph Isomorphism

      Instance: Graphs G and H.

      Question: Is there an isomorphism from G to H?

The disjoint union \((V(G)\cup V(H), E(G)\cup E(H))\) of two vertex-disjoint graphs G and H is denoted by \(G+H\) and the disjoint union of r copies of a graph G is denoted by rG. For a subset \(S\subseteq V(G)\), we let G[S] denote the subgraph of G induced by S, which has vertex set S and edge set \(\{uv\; |\; u,v\in S, uv\in E(G)\}\). If \(S=\{s_1,\ldots ,s_r\}\), then we may write \(G[s_1,\ldots ,s_r]\) instead of \(G[\{s_1,\ldots ,s_r\}]\). Recall that for two graphs G and \(G^{\prime }\) we write \(G^{\prime }\subseteq _iG\) to denote that \(G^{\prime }\) is an induced subgraph of G. For a set of graphs \(\{H_1,\ldots ,H_p\}\), a graph G is \((H_1,\ldots ,H_p)\)-free if it has no induced subgraph isomorphic to a graph in \(\{H_1,\ldots ,H_p\}\); recall that if \(p=1\), we may write \(H_1\)-free instead of \((H_1)\)-free.

Let G be a graph. The set \(N(u)=\{v\in V\; |\; uv\in E\}\) denotes the (open) neighbourhood of \(u\in V(G)\) and \(N[u]=N(u) \cup \{u\}\) denotes the closed neighbourhood of u. The degree \(d_G(v)\) of a vertex v in a graph G is the number of vertices in G that are adjacent to v. A vertex \(v\in V(G)\) is dominating if every vertex in \(V(G) \setminus \{v\}\) is adjacent to v. If X is a set of vertices in G, then X is dominating if every vertex in \(V(G) \setminus X\) has a neighbour in X. A vertex and an edge are incident if the vertex is one of the two end-vertices of the edge. A (connected) component of G is a maximal subset of vertices that induces a connected subgraph of G; it is non-trivial if it has at least two vertices, otherwise it is trivial. The complement \({\overline{G}}\) of a graph G has vertex set \(V({\overline{G}})=V(G)\) such that two vertices are adjacent in \({\overline{G}}\) if and only if they are not adjacent in G.

The graphs \(C_t\), \(K_t\), \(K_{1,t-1}\) and \(P_t\) denote the cycle, complete graph, star and path on t vertices, respectively. Let \(K_{1,t}^+\) and \(K_{1,t}^{++}\) be the graphs obtained from \(K_{1,t}\) by subdividing one edge once or twice, respectively. The graphs \(K_{1,3}\), \(\overline{2P_1+P_2}\), \(\overline{P_1+P_3}\), \(\overline{P_1+P_4}\) and \(\overline{2P_1+P_3}\) are also called the \({{\mathrm{claw}}}\), \({{\mathrm{diamond}}}\), \({{\mathrm{paw}}}\), \({{\mathrm{gem}}}\) and \({{\mathrm{crossed\ house}}}\), respectively. The graph \(S_{h,i,j}\), for \(1\le h\le i\le j\), denotes the subdivided claw, that is, the tree that has only one vertex x of degree 3 and exactly three leaves, which are at distance hi and j from x, respectively. Observe that \(S_{1,1,1}=K_{1,3}\). We use \(\mathcal{S}\) to denote the set of graphs every component of which is either a subdivided claw or a path on at least one vertex. A subdivided star is a graph obtained from a star by subdividing its edges an arbitrary number of times. A graph is a path star forest if all of its connected components are subdivided stars. A graph is a linear forest if every component of G is a path (on at least one vertex).

We will need the following results.

Lemma 1

[30] For every fixed t, Graph Isomorphism is polynomial-time solvable on \((2K_{1,t},K_t)\)-free graphs.

Lemma 2

[30] For every fixed t, Graph Isomorphism is polynomial-time solvable on \((K_t,P_5)\)-free graphs.

Let G be a graph and let \(X,Y \subseteq V(G)\) be disjoint sets. The edges between X and Y form a perfect matching if every vertex in X is adjacent to exactly one vertex in Y and vice versa. A vertex \(x \in V(G) \setminus Y\) is complete (resp. anti-complete) to Y if it is adjacent (resp. non-adjacent) to every vertex in Y. Similarly, X is complete (resp. anti-complete) to Y if every vertex in X is complete (resp. anti-complete) to Y. A graph is bipartite if its vertex set can be partitioned into two (possibly empty) independent sets. A graph is split if its vertex set can be partitioned into a clique and an independent set. A graph is complete multipartite if its vertex set can be partitioned into independent sets \(V_1,\ldots ,V_k\) such that \(V_i\) is complete to \(V_j\) whenever \(i \ne j\); if \(k=2\), then the graph is complete bipartite. We will need the following result.

Lemma 3

[27] Every connected \((\overline{P_1+P_3})\)-free graph is either complete multipartite or \(K_3\)-free.

2.1 Clique-width

The clique-width of a graph G, denoted by \({{\mathrm{cw}}}(G)\), is the minimum number of labels needed to construct G using the following four operations:

  1. (i)

    create a new graph consisting of a single vertex v with label i;

  2. (ii)

    take the disjoint union of two labelled graphs \(G_1\) and \(G_2\);

  3. (iii)

    join each vertex with label i to each vertex with label j (\(i\ne j\));

  4. (iv)

    rename label i to j.

A class of graphs \(\mathcal{G}\) has bounded clique-width if there is a constant c such that the clique-width of every graph in \(\mathcal{G}\) is at most c; otherwise the clique-width of \(\mathcal{G}\) is unbounded.

Let G be a graph. We define the following operations. For an induced subgraph \(G^{\prime }\subseteq _iG\), the subgraph complementation operation (acting on G with respect to \(G^{\prime }\)) replaces every edge present in \(G^{\prime }\) by a non-edge, and vice versa, that is, the resulting graph has vertex set V(G) and edge set \((E(G) \setminus E(G^{\prime })) \cup \{xy\;|\; x,y \in V(G^{\prime }), x \ne y, xy \notin E(G^{\prime })\}\). Similarly, for two disjoint vertex subsets S and T in G, the bipartite complementation operation with respect to S and T acts on G by replacing every edge with one end-vertex in S and the other in T by a non-edge and vice versa.

We now state some useful facts about how these two operations (and some others) influence the clique-width of a graph. We will use these facts throughout the paper. Let \(k\ge 0\) be a constant and let \(\gamma \) be some graph operation. We say that a graph class \({\mathcal{G}}^{\prime}\) is \((k,\gamma )\)-obtained from a graph class \(\mathcal{G}\) if the following two conditions hold:

  1. (i)

    every graph in \({\mathcal{G}}^{\prime}\) is obtained from a graph in \(\mathcal{G}\) by performing \(\gamma \) at most k times, and

  2. (ii)

    for every \(G\in \mathcal{G}\) there exists at least one graph in \({\mathcal{G}}^{\prime}\) obtained from G by performing \(\gamma \) at most k times.

We say that \(\gamma \) preserves boundedness of clique-width if for any finite constant k and any graph class \(\mathcal{G}\), any graph class \(\mathcal{G}^{\prime }\) that is \((k,\gamma )\)-obtained from \(\mathcal{G}\) has bounded clique-width if and only if \(\mathcal{G}\) has bounded clique-width.

Fact 1.:

Vertex deletion preserves boundedness of clique-width [24].

Fact 2.:

Subgraph complementation preserves boundedness of clique-width [21].

Fact 3.:

Bipartite complementation preserves boundedness of clique-width [21].

We need the following two lemmas on clique-width.

Lemma 4

[7] The class of \(\overline{2P_1+P_3}\)-free split graphs has bounded clique-width.

Lemma 5

[9] The class of \((K_3,P_6)\)-free graphs has bounded clique-width.

Since complete multipartite graphs have clique-width at most 2, and the clique-width of a graph is equal to the maximum clique-width of its components, we can use Lemma 3 to extend Lemma 5 into the following (previously-known) corollary.

Corollary 1

The class of \(({{\mathrm{paw}}},P_6)\)-free graphs has bounded clique-width.

We also need the special case of [15, Theorem 3] when \(V_{0,i}=V_{i,0}=\emptyset \) for \(i \in \{1,\ldots ,n\}\).

Lemma 6

[15] For \(m\ge 1\) and \(n >m+1\) the clique-width of a graph G is at least \(\lfloor \frac{n-1}{m+1}\rfloor +1\) if V(G) has a partition into sets \(V_{i,j}\; (i,j \in \{1,\ldots ,n\})\) with the following properties:

  1. 1.

    \(|V_{i,j}|\ge 1\) for all \(i,j\ge 1\).

  2. 2.

    \(G[\cup ^n_{j=1}V_{i,j}]\) is connected for all \(i\ge 1\).

  3. 3.

    \(G[\cup ^n_{i=1}V_{i,j}]\) is connected for all \(j\ge 1\).

  4. 4.

    For \(i,j,k,\ell \ge 1\), if a vertex of \(V_{i,j}\) is adjacent to a vertex of \(V_{k,\ell }\), then \(|k-i|\le m\) and \(|\ell -j| \le m\).

3 New Polynomial-Time Results

In this section we prove Theorems 3 and 4, which state that Graph Isomorphism is polynomial-time solvable on \((\overline{2P_1+P_3},P_5)\)-free graphs and \((\overline{2P_1+P_3},P_2+P_3)\)-free graphs, respectively (see also Fig. 1). The complexity of Graph Isomorphism on \((\overline{2P_1+P_3},2P_2)\)-free graphs was previously unknown, but since this class is contained in the classes of \((\overline{2P_1+P_3},P_5)\)-free graphs and \((\overline{2P_1+P_3},P_2+P_3)\)-free graphs, Theorems 3 and 4 both imply that Graph Isomorphism is also polynomial-time solvable on this class.

Fig. 1
figure 1

Forbidden induced subgraphs from Theorems 3 and 4

Before proving Theorems 3 and 4, we first prove a useful lemma (see also Fig. 2).

Fig. 2
figure 2

An example of Lemma 7 applied to a \(\overline{2P_1+P_3}\)-free graph. White vertices denote the vertices of \(K^G\) and thick edges between two sets of vertices indicate that these sets are complete to each other

Lemma 7

Let G be a \(\overline{2P_1+P_3}\)-free graph containing an induced \(K_5\) with vertex set \(K^G\). Then V(G) can be partitioned into sets \(A^G_1,\ldots ,A^G_p,N^G_1,\ldots ,N^G_p,B^G\) for some \(p \ge 5\) such that:

  1. (i)

    \(K^G \subseteq \bigcup A^G_i\);

  2. (ii)

    \(G[\bigcup A^G_i]\) is a complete multipartite graph, with partition \(A^G_1,\ldots ,A^G_p\);

  3. (iii)

    For every \(i \in \{1,\ldots ,p\}\), every vertex of \(N^G_i\) has a neighbour in \(A^G_i\), but is anti-complete to \(A^G_j\) for every \(j \in \{1,\ldots ,p\} \setminus \{i\}\); and

  4. (iv)

    \(B^G\) is anti-complete to \(\bigcup A^G_i\).

Furthermore, given \(K^G\), this partition is unique (up to permuting the indices on the \(A^G_i\)s and corresponding \(N^G_i\)s) and can be found in polynomial time.

Proof

Let G be a \(\overline{2P_1+P_3}\)-free graph containing an induced \(K_5\) with vertex set \(K^G\). If a vertex \(v \in V(G) \setminus K^G\) has two neighbours \(x,x^{\prime } \in K^G\) and two non-neighbours \(y,y^{\prime } \in K^G\), then \(G[x,x^{\prime },y,v,y^{\prime }]\) is a \(\overline{2P_1+P_3}\), a contradiction. Therefore every vertex in \(V(G) \setminus K^G\) has either at most one non-neighbour in \(K^G\) or at most one neighbour in \(K^G\). Let \(L^G\) denote the set of vertices that are either in \(K^G\) or have at most one non-neighbour in \(K^G\) and note that \(L^G\) is uniquely defined by the choice of \(K^G\).

We claim that \(G[L^G]\) is a complete multipartite graph. Suppose, for contradiction, that \(G[L^G]\) is not complete multipartite. Then \(G[L^G]\) contains an induced \(P_1+P_2=\overline{P_3}\), say on vertices \(v,v^{\prime },v^{\prime \prime }\) (note that some of these vertices may be in \(K^G\)). Now each of \(v,v^{\prime },v^{\prime \prime }\) has at most one non-neighbour in \(K^G\) and if a vertex \(w \in \{v,v^{\prime },v^{\prime \prime }\}\) is in \(K^G\), then it is adjacent to every vertex in \(K^G \setminus \{w\}\). Therefore, since \(|K^G|=5\), there must be distinct vertices \(u,u^{\prime }\in K^G\setminus \{v,v^{\prime },v^{\prime \prime }\}\) that are complete to \(\{v,v^{\prime },v^{\prime \prime }\}\). Now \(G[u,u^{\prime },v^{\prime },v,v^{\prime \prime }]\) is a \(\overline{2P_1+P_3}\). This contradiction completes the proof that \(G[L^G]\) is complete multipartite.

We let \(A^G_1,\ldots ,A^G_p\) be the partition classes of the complete multipartite graph \(G[L^G]\). Note that \(p \ge 5\), since each \(A^G_i\) contains at most one vertex of \(K^G\). We claim that each vertex not in \(L^G\) has neighbours in at most one set \(A^G_i\). Suppose, for contradiction, that there is a vertex \(v \in V(G) \setminus L^G\) with neighbours in two distinct sets \(A^G_i\), say v is adjacent to \(u \in A^G_1\) and \(u^{\prime } \in A^G_2\). Since \(v \notin L^G\), the vertex v has at most one neighbour in \(K^G\). Since \(|K^G|=5\), there must be two vertices \(y,y^{\prime } \in K^G \setminus (A^G_1 \cup A^G_2)\) that are non-adjacent to v. Now \(G[u,u^{\prime },y,v,y^{\prime }]\) is a \(\overline{2P_1+P_3}\), a contradiction. Therefore every vertex not in \(L^G\) has neighbours in at most one set \(A^G_i\). Let \(N^G_i\) be the set of vertices in \(V(G) \setminus L^G\) that have neighbours in \(A^G_i\) and let \(B^G\) be the set of vertices in \(V(G) \setminus L^G\) that are anti-complete to \(L^G\). Finally, note that the partition of V(G) into sets \(A^G_1,\ldots ,A^G_p,N^G_1,\ldots ,N^G_p,B^G\) can be found in polynomial time and is unique (up to permuting the indices on the \(A^G_i\)s and corresponding \(N^G_i\)s).\(\square \)

For the \((\overline{2P_1+P_3},P_5)\)-free case, we will use the following observation.

Observation 1

If G is a graph containing a vertex x and \(G^x\) is the graph obtained from G by adding a new vertex \(x^{\prime }\) with the same neighbourhood as x in G, then \(G^x\) is \((\overline{2P_1+P_3},P_5)\)-free if and only if G is \((\overline{2P_1+P_3},P_5)\)-free.

Proof

Since G is an induced subgraph of \(G^x\), if \(G^x\) is \((\overline{2P_1+P_3},P_5)\)-free then G is \((\overline{2P_1+P_3},P_5)\)-free. Suppose, for contradiction, that \(G^x\) contains a set of vertices X that induce a \(\overline{2P_1+P_3}\) or a \(P_5\), but that G is \((\overline{2P_1+P_3},P_5)\)-free. Since neither \(\overline{2P_1+P_3}\) nor \(P_5\) has two vertices with the same neighbourhood, it follows that either \(x \notin X\) or \(x^{\prime } \notin X\). By symmetry, we may assume that \(x^{\prime } \notin X\), in which case \(X \subseteq V(G)\), so G contains an induced \(\overline{2P_1+P_3}\) or \(P_5\), a contradiction.\(\square \)

Theorem 3

Graph Isomorphism is polynomial-time solvable on \((\overline{2P_1+P_3},P_5)\)-free graphs.

Proof

Since Graph Isomorphism can be solved component-wise, we need only consider connected graphs. Therefore, since Graph Isomorphism is polynomial-time solvable on \((K_5,P_5)\)-free graphs by Lemma 2, and we can test whether a graph is \(K_5\)-free in polynomial time, it only remains to consider the class of connected \((\overline{2P_1+P_3},P_5)\)-free graphs G that contain an induced \(K_5\). Let \(K^G\) be the vertices of such a \(K_5\) in G. Let \(A^G_1,\ldots ,A^G_p,N^G_1,\ldots ,N^G_p,B^G\) be defined as in Lemma 7 and let \(L^G = \bigcup A^G_i\). We start by proving the following claim.

Claim 1

If at least three \(N^G_i\)s are non-empty, then G has bounded clique-width.

Suppose, for contradiction, that we can find vertices xyz with \(x \in N^G_i, y \in N^G_j, z \in N^G_k\) with ijk pairwise distinct such that z is adjacent to y, but not to x. Let \(x^{\prime } \in A^G_i\) be a neighbour of x, let \(y^{\prime } \in A^G_j\) be a neighbour of y and let \(x^{\prime \prime } \in K^G \setminus (A^G_i \cup A^G_j \cup A^G_k)\) (which exists since the sets \(A^G_i\), \(A^G_j\) and \(A^G_k\) each contain at most one vertex of \(K^G\), while \(|K^G|=5\)). Then \(G[x^{\prime \prime },x^{\prime },x,y,z]\) or \(G[x,x^{\prime },y^{\prime },y,z]\) is a \(P_5\) if x is adjacent or non-adjacent to y, respectively. It follows that the \(N^G_i\)’s are either pairwise anti-complete or pairwise complete. We consider these two cases separately.

Case 1

At least three \(N^G_i\)s are non-empty and the \(N^G_i\)s are pairwise anti-complete.

Suppose, for contradiction, that there is a vertex \(x \in B^G\). Since G is connected, x must have a neighbour \(y \in N^G_i\) for some i. Choose a vertex \(z \in N^G_j\) for some \(j \ne i\) and note that z is non-adjacent to y. Let \(y^{\prime } \in A^G_i\) and \(z^{\prime } \in A^G_j\) be neighbours of y and z, respectively, and let \(w \in K^G \setminus (A^G_i \cup A^G_j)\). Then \(G[w,y^{\prime },y,x,z]\) or \(G[x,y,y^{\prime },z^{\prime },z]\) is a \(P_5\) if x is adjacent or non-adjacent to z, respectively. This contradiction implies that \(B^G = \emptyset \).

Suppose, for contradiction, that there are two adjacent vertices \(y,y^{\prime } \in N^G_i\) that have different neighbourhoods in \(A^G_i\), say y is adjacent to \(z \in A^G_i\), but \(y^{\prime }\) is not. Let \(x \in N^G_j\) for some \(j \ne i\) and let \(x^{\prime } \in A^G_j\) be a neighbour of x; note that x is non-adjacent to y and \(y^{\prime }\). Then \(G[x,x^{\prime },z,y,y^{\prime }]\) is a \(P_5\). This contradiction implies that if two vertices in some set \(N^G_i\) are in the same component of \(G[N^G_i]\), then they must have the same neighbourhood in \(A^G_i\).

Suppose, for contradiction, that for some i there are vertices \(x,y \in N^G_i\) with incomparable neighbourhoods in \(A^G_i\). Note that in this case x and y must be in different components of \(G[N^G_i]\), so they must be non-adjacent to each other. Let \(x^{\prime } \in A^G_i\) be a neighbour of x that is non-adjacent to y, let \(y^{\prime } \in A^G_i\) be a neighbour of y that is non-adjacent to x and let \(z \in K^G \setminus A^G_i\). Then \(G[x,x^{\prime },z,y^{\prime },y]\) is a \(P_5\). This contradiction implies that the components of \(G[N^G_i]\) can be ordered by containment of their neighbourhoods in \(A^G_i\).

We will now show that \(G_i:=G[A^G_i \cup N^G_i]\) has bounded clique-width. We may order the vertices of \(A^G_i\), say \(a_1,\ldots ,a_r\), in decreasing order of neighbourhoods in \(N^G_i\) (breaking ties arbitrarily); note that every vertex of \(N^G_i\) is adjacent to \(a_1\). We partition \(N^G_i\) into sets \(X_1,\ldots ,X_r\) such that the vertices of \(X_j\) are adjacent to \(a_k\) if and only if \(k \le j\). Since \(a_1\) dominates \(N^G_i\), and \(G[N^G_i\cup \{a_1\}]\) is \(\overline{2P_1+P_3}\)-free, it follows that \(G[N^G_i]\) is \({{\mathrm{paw}}}\)-free (recall that the \({{\mathrm{paw}}}\) is \(\overline{P_1+P_3}\)). By Corollary 1, it follows that \(G[N^G_i]\) has bounded clique-width. Therefore, for some constant c, we can construct each of \(G[X_1],\ldots ,G[X_r]\) using only labels from \(\{1,\ldots ,c\}\). We will now construct \(G_i\) using two new labels \(1^{\prime }\) and \(2^{\prime }\) in addition to the labels from \(\{1,\ldots ,c\}\). For \(j \in \{1,\ldots ,r\}\), suppose we have constructed \(G_i[X_1,\ldots ,X_{j-1} \cup \{a_1,\ldots ,a_{j-1}\}]\) such that the vertices in \(X_1,\ldots ,X_{j-1}\) have label \(1^{\prime }\) and the vertices in \(\{a_1,\ldots ,a_{j-1}\}\) have label \(2^{\prime }\) (if \(j=1\), this means we have constructed the empty graph). We then construct \(G[X_j]\) using labels from \(\{1,\ldots ,c\}\) and construct \(a_j\) with label \(2^{\prime }\) and take the disjoint union of these and the graph constructed so far. We join vertices with labels in \(\{1,\ldots ,c\}\) to the vertices with label \(2^{\prime }\) and then relabel the vertices with label \(\{1,\ldots ,c\}\) to have label \(1^{\prime }\). We have now constructed \(G_i[X_1,\ldots ,X_j \cup \{a_1,\ldots ,a_j\}]\) such that the vertices in \(X_1,\ldots ,X_j\) have label \(1^{\prime }\) and the vertices in \(\{a_1,\ldots ,a_j\}\) have label \(2^{\prime }\). By induction, we can therefore construct \(G_i\) with \(c+2\) labels. It follows that \(G_i\) has bounded clique-width.

Now, for every i, let \(G_i^*\) be the graph obtained from \(G_i\) by complementing \(A^G_i\) and note that \(G_i^*\) has bounded clique-width by Fact 2. Let \(G^*\) be the disjoint union of the \(G_i^*\) graphs and note that \(G^*\) has bounded clique-width (since the clique-width of a graph is the maximum of the clique-width of its components). Note that G is the graph obtained from \(G^*\) by complementing \(L^G\). By Fact 2, it follows that G has bounded clique-width. This completes Case 1.

Case 2

At least three \(N^G_i\)s are non-empty and the \(N^G_i\)s are pairwise complete.

We first claim that \(B^G\) is complete to \(\bigcup N^G_i\). Suppose, for contradiction, that there is a vertex in \(x \in B^G\) that has both a neighbour y and a non-neighbour z in \(\bigcup N^G_i\). Since there is more than one non-empty set \(N^G_i\), we may assume that \(y \in N^G_i\) and \(z \in N^G_j\) for some \(i \ne j\); note that this means y is adjacent to z. Let \(z^{\prime } \in A^G_j\) be a neighbour of z and let \(z^{\prime \prime } \in K^G \setminus (A^G_i \cup A^G_j)\). Then \(G[x,y,z,z^{\prime },z^{\prime \prime }]\) is a \(P_5\), a contradiction, and so every vertex of \(B^G\) is either complete or anti-complete to \(\bigcup N^G_i\). Since G is connected, if not every vertex of \(B^G\) is complete to \(\bigcup N^G_i\), then there must be adjacent vertices \(x,x^{\prime } \in B^G\) that are complete and anti-complete to \(\bigcup N^G_i\), respectively. Let \(y \in N^G_i\) for some i, let \(y^{\prime } \in A^G_i\) be a neighbour of y and let \(z \in K^G \setminus A^G_i\). Then \(G[x^{\prime },x,y,y^{\prime },z]\) is a \(P_5\). This contradiction implies that \(B^G\) is indeed complete to \(\bigcup N^G_i\).

Now suppose, for contradiction, that for some i there is a vertex \(z \in N^G_i\) that has a non-neighbour \(x \in A^G_i\). Let \(x^{\prime } \in A^G_i\) be a neighbour of z, let \(z^{\prime } \in N^G_j\) for some \(j \ne i\) and let \(y \in K^G \setminus (A^G_i \cup A^G_j)\). Then \(G[x,y,x^{\prime },z,z^{\prime }]\) is a \(P_5\), a contradiction. It follows that for every i, \(N^G_i\) is complete to \(A^G_i\).

Now \(B^G\) is dominated by a vertex of \(N^G_i\) for some i. Moreover, for every i the set \(N^G_i\) is dominated by a vertex in \(A^G_i\). Since G is a \(\overline{2P_1+P_3}\)-free graph, it follows that \(G[B^G]\) and, for every i\(G[N^G_i]\) are \({{\mathrm{paw}}}\)-free graphs and thus have bounded clique-width by Corollary 1. Since \(G[A^G_i]\) is an edgeless graph for every i, it has clique-width 1. The graph \(G_i:=G[N^G_i \cup A^G_i]\) can be obtained from \(G[N^G_i]\) and \(G[A^G_i]\) by taking their disjoint union and applying a bipartite complementation between \(N^G_i\) and \(A^G_i\). By Fact 3, it follows that \(G_i\) has bounded clique-width.

Let \(G^*_i\) be the graph obtained from \(G_i\) by complementing \(A^G_i\) and \(N^G_i\). Then \(G^*_i\) has bounded clique-width by Fact 2. Let \(G^*\) be the disjoint union of \(G[B^G]\) and the \(G_i^*\) graphs and note that \(G^*\) has bounded clique-width (since the clique-width of a graph is the maximum of the clique-width of its components). Now, if we complement \(L^G\) and \(\bigcup N^G_i\) and apply a bipartite complementation between \(B^G\) and \(\bigcup N^G_i\) we obtain the graph G. By Facts 2 and 3, it follows that G has bounded clique-width. This completes Case 2 and therefore completes the proof of Claim 1. \(\diamond\)

We now describe an algorithm to prove Theorem 3. Suppose G and H are \((\overline{2P_1+P_3},P_5)\)-free graphs. We can enumerate all sets \(K^G\) that induce a \(K_5\) in G in polynomial time. By Lemma 7, we can therefore test in polynomial time whether there is a \(K^G\) such that at least three \(N^G_i\) sets are non-empty; if so, then G has bounded clique-width by Claim 1 and we apply Theorem 2.

We may now assume that for every \(K^G\) at most two sets \(N^G_i\) are non-empty. We may also assume that the same is true for every \(K^H\) in H (otherwise we immediately output that G and H are not isomorphic). We will now explain how to transform G into a graph \(G^{\prime }\) that is \(K_5\)-free.

First note that if \(x \in A^G_i\) for some i such that \(N^G_i=\emptyset \), then \(L^G=A^G_i \cup N(x)\). Since \(A^G_i\) is the set of vertices in G with the same neighbourhood as x, every set \(L^G\) can be written as \(N(x)\cup \{y \;|\; N(y)=N(x)\}\) for some vertex x of G. Moreover, for every choice of \(L^G\), there are at least three sets \(A^G_i\) such that \(N_i^G=\emptyset \). Now \(L^G=N(x)\cup \{y \;|\; N(y)=N(x)\}\) holds for every vertex x in such a set \(A_i^G\), so every \(L^G\) can be obtained in this way from at least three possible vertices x. We conclude that there are at most \(\frac{n}{3}\) possible sets \(L^G\).

Given a set \(L^G\), recall that the sets \(A_i^G\) are uniquely determined (up to reordering). Let \(L^{\prime G}\) denote the set \(\bigcup _{i \; | \; N^G_i=\emptyset }A^G_i\); we say that the multiset \(\{|A^G_i| \; | \; N^G_i=\emptyset \}\) is the type of \(L^G\). We consider all possibilities for \(L^G\) in G and number the different types that occur \(1,\ldots ,t\); note that the possible sets \(L^{\prime G}\) are pairwise vertex-disjoint. Suppose that for \(j \in \{1,\ldots ,t\}\) we replace the vertices of \(L^{\prime G}\) in each set \(L^G\) of type j by a copy of \(K_{n+j,n+j}\) that is complete to \(L^G \setminus L^{\prime G}\), where n denotes the number of vertices in the original graph G. Note that since \(L^{\prime G}\) is a complete multipartite graph with at least three parts, this would change the graph in the same way as deleting all but two parts of this multipartite graph and then expanding the remaining two parts by adding false twins of vertices already in the graph. By Observation 1, the resulting graph \(G^{\prime }\) is still \((\overline{2P_1+P_3},P_5)\)-free. Furthermore, applying this operation removes every \(K_5\) from the graph, so \(G^{\prime }\) is a \((K_5,P_5)\)-free graph. We can apply the same transformation to H to obtain a \((K_5,P_5)\)-free graph \(H^{\prime }\). For G and H we can enumerate all possible sets \(L^{\prime G}\) and \(L^{\prime H}\) (using Lemma 7), and, as observed above, there are at most \(\frac{n}{3}\) such sets in each graph. For each type of an \(L^{\prime G}\) in G, H must have the same number of sets \(L^{\prime H}\) with this type as G does (and vice verse), otherwise we output that G and H are not isomorphic. We therefore number the types of \(L^{\prime G}\) in G and the types \(L^{\prime H}\) in H in the same way. Since \(G^{\prime }\) and \(H^{\prime }\) are \((K_5,P_5)\)-free graphs, by Lemma 2, we can test whether they are isomorphic in polynomial time.

It therefore suffices to show that \(G^{\prime }\) and \(H^{\prime }\) are isomorphic if and only if G and H are isomorphic. By construction, if G and H are isomorphic, then \(G^{\prime }\) and \(H^{\prime }\) are isomorphic. Now suppose that there is an isomorphism f from \(G^{\prime }\) to \(H^{\prime }\). For a vertex \(x \in V(G^{\prime })\), let \(V^{G^{\prime }}_x=\{v \in V(G^{\prime }) \; | \; N(v)=N(x)\}\). Note that \(|V^{H^{\prime }}_{f(x)}|=|f(V^{G^{\prime }}_x)|=|V^{G^{\prime }}_x|\). Now \(x \in V(G^{\prime }) \setminus V(G)\) if and only if \(|V^{G^{\prime }}_x|>n\). By construction, two sets of the form \(V^{G^{\prime }}_x\) with \(|V^{G^{\prime }}_x|>n\) are either complete or anti-complete to each other and each such set is complete to exactly one other such set. Therefore, for each \(j \in \{1,\ldots ,t\}\), the isomorphism f maps the copies of \(K_{n+j,n+j}\) from the construction of \(G^{\prime }\) to copies of \(K_{n+j,n+j}\) from the construction of \(H^{\prime }\) and f maps \(V(G) \cap V(G^{\prime })\) to \(V(H) \cap V(H^{\prime })\). We may therefore replace each copy of \(K_{n+j,n+j}\) in \(G^{\prime }\) and \(H^{\prime }\) by an \(L^{\prime G}\) and \(L^{\prime H}\) of the corresponding type. Since it is trivial to find an isomorphism from a set \(L^{\prime G}\) to a set \(L^{\prime H}\) of the same type, we can construct an isomorphism from G to H. \(\square \)

We are now ready to prove Theorem 4. Note that as \(P_2+P_3\) contains two vertices with the same neighbourhood, we do not have an analogue of Observation 1 for the \((\overline{2P_1+P_3},P_2+P_3)\)-free case. Because of this, the proof of Theorem 4 is slightly more involved than that of Theorem 3.

Theorem 4

Graph Isomorphism is polynomial-time solvable on \((\overline{2P_1+P_3},P_2+P_3)\)-free graphs.

Proof

Since Graph Isomorphism can be solved component-wise, we need only consider connected graphs. Therefore, as Graph Isomorphism is polynomial-time solvable on \((K_5,P_2+P_3)\)-free graphs by Lemma 1, and we can test whether a graph is \(K_5\)-free in polynomial time, it only remains to consider the class of connected \((\overline{2P_1+P_3},P_2+P_3)\)-free graphs G that contain an induced \(K_5\). Let \(K^G\) be the vertices of an induced \(K_5\) in G (note that such a set \(K^G\) can be found in polynomial time, but it is not necessarily unique). Let \(A^G_1,\ldots ,A^G_p,N^G_1,\ldots ,N^G_p,B^G\) be defined as in Lemma 7 and let \(L^G = \bigcup A^G_i\) and \(D^G = V(G) \setminus L^G\).

Now suppose that G and H are connected \((\overline{2P_1+P_3},P_2+P_3)\)-free graphs that each contain an induced \(K_5\). If G and H have bounded clique-width (which happens in Case 1 below), then by Theorem 2 we are done. Otherwise, note that if \(K^G\) and \(K^H\) are vertex sets that induce a \(K_5\) in G and H, respectively, then Lemma 7 implies that \(L^G, D^G, L^H\) and \(D^H\) are uniquely defined. Therefore, we fix one choice of \(K^G\) and, for each choice of \(K^H\), test whether there is an isomorphism \(f:G \rightarrow H\) such that \(f(L^G)=L^H\) (we use this approach in Cases 2 and 3 below). Clearly, we may assume that the vertex partitions given by Lemma 7 for G and H have the same value of p and that \(|A^G_i|=|A^H_i|\) and \(|N^G_i|=|N^H_i|\) for all \(i\in \{1,\ldots ,p\}\) and \(|B^G|=|B^H|\). Furthermore, for any claims we prove about G and its vertex sets, we may assume that the same claims hold for H (otherwise such an isomorphism f does not exist). We start by proving the following four claims.

Claim 1

\(G[D^G]\) is \(P_3\)-free.

Indeed, suppose, for contradiction, that \(G[D^G]\) contains an induced \(P_3\), say on vertices \(u,u^{\prime },u^{\prime \prime }\). Since \(|K^G|=5\) and each vertex in \(D^G\) has at most one neighbour in \(K^G\), there must be vertices \(v,v^{\prime } \in K^G\) that are anti-complete to \(\{u,u^{\prime },u^{\prime \prime }\}\). Then \(G[v,v^{\prime },u,u^{\prime },u^{\prime \prime }]\) is a \(P_2+P_3\), a contradiction. \(\diamond\)

Claim 2

If \(v \in N^G_j\) for some \(j \in \{1,\ldots ,p\}\) and there are two adjacent vertices \(u,u^{\prime } \in D^G\setminus N^G_j\), then v is complete to \(\{u,u^{\prime }\}\).

Since \(G[D^G]\) is \(P_3\)-free by Claim 1, the vertex v must be either complete or anti-complete to \(\{u,u^{\prime }\}\). Suppose, for contradiction, that v is anti-complete to \(\{u,u^{\prime }\}\). Since \(v \in N^G_j\), v has a neighbour \(v^{\prime } \in A^G_j\). Since \(|K^G\setminus A^G_j|\ge 4\) and each vertex in \(D^G\) has at most one neighbour in \(K^G\), there is a vertex \(v^{\prime \prime } \in K^G \setminus A^G_j\) that is non-adjacent to both u and \(u^{\prime }\). Since \(v^{\prime \prime } \notin A^G_j\), \(v^{\prime \prime }\) is also non-adjacent to v, but is adjacent to \(v^{\prime }\). Now \(G[u,u^{\prime },v,v^{\prime },v^{\prime \prime }]\) is a \(P_2+P_3\), a contradiction. \(\diamond\)

Claim 3

If \(G[D^G]\) has at least two components and one of these components C has at least three vertices, then there is an \(i \in \{1,\ldots ,p\}\) such that \(D^G \setminus C \subset N^G_i \cup B^G\) and all but at most one vertex of C belongs to \(N^G_i\).

By Claim 1, \(G[D^G]\) is a disjoint union of cliques. Since G is connected, \(D^G \setminus C\) cannot be a subset of \(B^G\). Hence, for some \(i \in \{1,\ldots ,p\}\), there must be a vertex \(x \in N^G_i \setminus C\). Therefore, by Claim 2, at most one vertex of C can lie outside of \(N^G_i\). Since \(|C|\ge 3\), it follows that \(C \cap N^G_i\) contains at least two vertices. Since the vertices in C are pairwise adjacent, by Claim 2 it follows that \(D^G \setminus C \subset N^G_i \cup B^G\). \(\diamond\)

Claim 4

Let \(i \in \{1,\ldots ,p\}\). If \(G[D^G]\) contains at least two non-trivial components and there is a vertex v in \(A^G_i\) with two non-neighbours in the same component of \(G[D^G]\), then v is anti-complete to \(D^G\). Furthermore, there is at most one vertex in \(A^G_i\) with this property.

Suppose \(v \in A^G_i\) has two non-neighbours \(x,x^{\prime }\) in some component C of \(G[D^G]\). By Claim 1, \(G[D^G]\) is a disjoint union of cliques, so x must be adjacent to \(x^{\prime }\). We claim that v is anti-complete to \(D^G \setminus C\). Suppose, for contradiction, that v has a neighbour \(y \in D^G \setminus C\). Since every vertex of \(D^G\) has at most one neighbour in \(K^G\), there must be a vertex \(z \in K^G \setminus A_i^G\) that is non-adjacent to \(x,x^{\prime }\) and y and so \(G[x,x^{\prime },y,v,z]\) is a \(P_2+P_3\). This contradiction implies that v is indeed anti-complete to \(D^G \setminus C\). Now \(G[D^G \setminus C]\) contains another non-trivial component \(C^{\prime }\) and we have shown that v is anti-complete to \(C^{\prime }\). Repeating the same argument with \(C^{\prime }\) taking the place of C, we find that v is anti-complete to \(D^G \setminus C^{\prime }\), and therefore v is anti-complete to \(D^G\). Finally, suppose, for contradiction, that there are two vertices \(v,v^{\prime } \in A^G_i\) that are both anti-complete to \(D^G\). Let \(x,x^{\prime }\) be adjacent vertices in \(D^G\) and let \(z \in K^G\setminus A^G_i\) be a vertex non-adjacent to x and \(x^{\prime }\). Then \(G[x,x^{\prime },v,z,v^{\prime }]\) is a \(P_2+P_3\), a contradiction. \(\diamond\)

We now start a case distinction and first consider the following case.

Case 1

\(G[D^G]\) contains at most one non-trivial component.

In this case we will show that G has bounded clique-width, and so we will be done by Theorem 2. By Claim 1, every component of \(G[D^G]\) is a clique. Since \(G[D^G]\) contains at most one non-trivial component, we may partition \(D^G\) into a clique C and an independent set I (note that C or I may be empty). If \(|C| \ge 3\) and \(|I| \ge 1\), then by Claim 3 there is an \(i \in \{1,\ldots ,p\}\) such that at most one vertex of \(C \cup I\) is outside \(N^G_i\); if such a vertex exists, then by Fact 1 we may delete it. Now if \(|C| \le 3\), then by Fact 1 we may delete the vertices of C. Thus we may assume that either \(C=\emptyset \) or \(|C|\ge 4\) and furthermore, if \(|C|\ge 4\) and \(|I|\ge 1\), then \(C \cup I \subseteq N^G_i\) for some \(i \in \{1,\ldots ,p\}\). Note that \(I \cap B^G = \emptyset \) since G is connected, so \(B^G \subset C\). Therefore \(G[B^G]\) is a complete graph, so it has clique-width at most 2. Applying a bipartite complementation between \(B^G\) and \(C \setminus B^G\) removes all edges between \(B^G\) and \(V(G) \setminus B^G\). By Fact 3, we may therefore assume that \(B^G=\emptyset \).

Let M be the set of vertices in \(L^G\) that have neighbours in I. We claim that M is complete to all but at most one vertex of C. We may assume that \(|C|\ge 4\) and \(|I|\ge 1\), otherwise the claim follows trivially. Therefore, as noted above, \(C \cup I \subseteq N^G_i\) for some \(i \in \{1,\ldots ,p\}\). Suppose \(u \in M\) has a neighbour \(u^{\prime } \in I\) and note that this implies \(u \in A^G_i\), \(u^{\prime } \in N^G_i\). Suppose, for contradiction, that u has two non-neighbours \(v,v^{\prime } \in C\) and let \(w \in K^G \setminus A^G_i\). Then \(G[v,v^{\prime },u^{\prime },u,w]\) is a \(P_2+P_3\), a contradiction. Therefore if \(u \in M\), then u has at most one non-neighbour in C. Now suppose that there are two vertices \(u,u^{\prime } \in M\). It follows that \(u,u^{\prime }\in A^G_i\), so these vertices must be non-adjacent. Furthermore, each of these vertices has at most one non-neighbour in C. If u and \(u^{\prime }\) have different neighbourhoods in C, then without loss of generality we may assume that there are vertices \(x,y,y^{\prime } \in C\) such that u is adjacent to xy and \(y^{\prime }\) and \(u^{\prime }\) is adjacent to y and \(y^{\prime }\), but not to x. Now \(G[y,y^{\prime },u,u^{\prime },x]\) is a \(\overline{2P_1+P_3}\), a contradiction. Therefore every vertex in M has the same neighbourhood in C, which consists of all but at most one vertex of C and the claim holds. If the vertices of M are not complete to C, then we delete one vertex of C (we may do so by Fact 1), after which M will be complete to C. We may therefore assume that M is complete to C.

Now note that for all \(i \in \{1,\ldots ,p\}\), the graph \(G_i=G[(A^G_i\setminus M) \cup (N^G_i \cap C)]\) is a \(\overline{2P_1+P_3}\)-free split graph, so it has bounded clique-width by Lemma 4. Furthermore \(G_i^{\prime }=G[(A^G_i\cap M) \cup (N^G_i \cap I)]\) is a \((P_2+P_3)\)-free bipartite graph, so it has bounded clique-width by Lemma 5. Let \(G_i^{\prime \prime }\) be the graph obtained from the disjoint union \(G_i+G_i^{\prime }\) by complementing \(A^G_i\) and \((N^G_i \cap C)\). By Fact 2, \(G_i^{\prime \prime }\) also has bounded clique-width. Therefore the disjoint union \(G^*\) of all the \(G_i^{\prime \prime }\)s has bounded clique-width. Now G can be constructed from \(G^*\) by complementing \(L^G\), complementing C and applying a bipartite complementation between C and M. Hence, by Facts 2 and 3, G has bounded clique-width. This completes Case 1.

We may now assume that Case 1 does not apply, that is, \(G[D^G]\) has at least two non-trivial components. This leads us to our second and third cases.

Case 2

\(G[D^G]\) contains at least two non-trivial components, but is \(K_4\)-free.

Recall that \(G[D^G]\) is \(P_3\)-free by Claim 1, so every component of \(G[D^G]\) is a clique. Let C be a non-trivial component of \(G[D^G]\) and let \(x,y \in C\). Then x is adjacent to y and \(x,y \in N^G_i \cup N^G_j \cup B^G\) for some (not necessarily distinct) \(i,j \in \{1,\ldots ,p\}\). By Claim 2, every vertex z in a component of \(G[D^G]\) other than C must also be in \(N^G_i \cup N^G_j \cup B^G\). Since \(G[D^G]\) contains at least two non-trivial components, repeating this argument with another non-trivial component implies that every vertex of \(D^G\) lies in \(N^G_i \cup N^G_j \cup B^G\). Without loss of generality, we may therefore assume that \(N^G_k = \emptyset \) for \(k \ge 3\).

Since \(G[D^G]\) is \(K_4\)-free, for each \(i \in \{1,\ldots ,p\}\) the graph \(G[D^G \cup A^G_i]\) is \(K_5\)-free. This means that every \(K_5\) in G is entirely contained in \(L^G\). By Claim 4, for \(i \ge 3\), \(|A^G_i|=1\) and so \(L^G \setminus (A^G_1 \cup A^G_2)\) must be a clique. The vertices of \(L^G \setminus (A^G_1 \cup A^G_2)\) have no neighbours outside \(L^G\) and are adjacent to every other vertex of \(L^G\), so these vertices are in some sense interchangeable. Indeed, \(N[v]=L^G\) for every \(v \in L^G \setminus (A^G_1 \cup A^G_2)\), and so every bijection that permutes the vertices of \(L^G \setminus (A^G_1 \cup A^G_2)\) and leaves the other vertices of G unchanged is an isomorphism from G to itself. Let \(G^{\prime }\) be the graph obtained from G by deleting all vertices in \(A^G_i\) for \(i \ge 6\) (if any such vertices are present). Now \(G^{\prime }\) is \(K_6\)-free, so it is a \((K_6,P_2+P_3)\)-free graph. Therefore we can test isomorphism of such graphs \(G^{\prime }\) in polynomial time by Lemma 1. If there is an isomorphism between two such graphs \(G^{\prime }\) and \(H^{\prime }\), then, because the vertices of \(L^G \setminus (A^G_1 \cup A^G_2)\) are interchangeable, we can extend it to a full isomorphism of G and H by mapping the remaining vertices of \(L^G \setminus (A^G_1 \cup A^G_2)\) to \(L^H \setminus (A^H_1 \cup A^H_2)\) arbitrarily. This completes Case 2.

Case 3

\(G[D^G]\) contains at least two non-trivial components and contains an induced \(K_4\).

Recall that \(G[D^G]\) is \(P_3\)-free by Claim 1, so every component of \(G[D^G]\) is a clique. We claim that \(D^G \subseteq N^G_i \cup B^G\) for some \(i \in \{1,\ldots ,p\}\). Let C be a component of \(G[D^G]\) that contains at least four vertices, and let \(C^{\prime }\) be a component of \(G[D^G]\) other than C, and note that such components exist by assumption. By Claim 3, there is an \(i \in \{1,\ldots ,p\}\) such that \(D^G \setminus C \subset N^G_i \cup B^G\) and all but at most one vertex of C belongs to \(N^G_i\). In particular, this implies that \(C^{\prime } \subset N^G_i \cup B^G\). By Claim 2, it follows that C cannot have a vertex in \(N^G_j\) for some \(j \in \{1,\ldots ,p\} \setminus \{i\}\), and so \(C \subset N^G_i \cup B^G\). Without loss of generality, we may therefore assume that \(N^G_j=\emptyset \) for \(j \in \{2,\ldots ,p\}\) and so \(D^G=N^G_1 \cup B^G\). Now if \(j \in \{2,\ldots ,p\}\), then the vertices of \(A^G_j\) are anti-complete to \(D^G\), so Claim 4 implies that \(|A^G_j|=1\). This implies that \(L^G\setminus A^G_1\) is a clique.

By Claim 4 there is at most one vertex \(x^G \in A^G_1\) that has two non-neighbours in the same non-trivial component C of \(G[D^G]\) and if such a vertex exists, then it must be anti-complete to \(D^G\). Let \(A^{*G}_1=A^G_1 \setminus \{x^G\}\) if such a vertex \(x^G\) exists and \(A^{*G}_1=A^G_1\) otherwise. Then every vertex in \(A^{*G}_1\) has at most one non-neighbour in each component of \(G[D^G]\). Note that \(A^{*G}_1\) is non-empty, since \(D^G\) is non-empty and G is connected.

Suppose C is a component of \(G[D^G]\) on at least four vertices. Now suppose, for contradiction, that there are two vertices \(y,y^{\prime } \in A^{*G}_1\) with different neighbourhoods in C. Then without loss of generality there is a vertex \(x \in C\) that is adjacent to y, but not to \(y^{\prime }\). Since \(|C| \ge 4\) and every vertex in \(A^{*G}_1\) has at most one non-neighbour in C, there must be two vertices \(z,z^{\prime } \in C\) that are adjacent to both y and \(y^{\prime }\). Now \(G[z,z^{\prime },x,y^{\prime },y]\) is a \(\overline{2P_1+P_3}\), a contradiction. We conclude that every vertex in \(A^{*G}_1\) has the same neighbourhood in C. This implies that every vertex of C is either complete or anti-complete to \(A^{*G}_1\). If a vertex of C is anti-complete to \(A^{*G}_1\), then it is anti-complete to \(A^G_1\), and so it lies in \(B^G\).

Let \(D^{*G}\) be the set of vertices in \(D^G\) that are in components of \(G[D^G]\) that have at most three vertices. Then every vertex of \(D^G \setminus D^{*G}\) is complete or anti-complete to \(A^{*G}_1\) and anti-complete to \(A^G_1 \setminus A^{*G}_1\).

Now let \(G^{\prime }=G[D^{*G} \cup L^G \setminus (A^G_1 \setminus A^{*G}_1)]\) and note that this graph is uniquely defined by G and \(K^G\). Then \(G^{\prime }[D^{*G}]\) is \(K_4\)-free, so \(G^{\prime }[D^{*G}\cup A^{*G}_1]\) is \(K_5\)-free, so every induced \(K_5\) in \(G^{\prime }\) is entirely contained in \(L^G\setminus (A^G_1 \setminus A^{*G}_1)\). Furthermore, since \(p \ge 5\), every vertex in \(L^G \setminus (A^G_1 \setminus A^{*G}_1)\) is contained in an induced \(K_5\) in \(G^{\prime }\). Therefore every isomorphism q from \(G^{\prime }\) to \(H^{\prime }\) satisfies \(q(L^G \setminus (A^G_1 \setminus A^{*G}_1))=L^H \setminus (A^H_1 \setminus A^{*H}_1)\). Therefore a bijection \(f:V(G) \rightarrow V(H)\) is an isomorphism from G to H such that \(f(L^G)=L^H\) if and only if all of the following hold:

  1. 1.

    The restriction of f to \(V(G^{\prime })\) is an isomorphism from \(G^{\prime }\) to \(H^{\prime }\) such that \(f(A^{*G}_1)=A^{*H}_1\).

  2. 2.

    \(f(A^G_1 \setminus A^{*G}_1)=A^H_1 \setminus A^{*H}_1\).

  3. 3.

    For every component C of \(G[D^G]\) with at least four vertices, f(C) is a component of \(H[D^H]\) on the same number of vertices and \(|C \cap B^G|=|f(C) \cap B^H|\).

It is therefore sufficient to test whether there is a bijection from G to H with the above properties. Note that these properties are defined on pairwise disjoint vertex sets, and the edges in G and H between these sets are completely determined by the definition of the sets. Thus it is sufficient to independently test whether there are bijections satisfying each of these properties. If \(D^{*G}\) is empty, then \(G^{\prime }\) is a complete multipartite graph, so we can easily test if Property 1 holds in this case. Otherwise, since \(A^G_j\) has no neighbours outside \(L^G\) for \(j \in \{2,\ldots ,p\}\), every isomorphism from \(G^{\prime }\) to \(H^{\prime }\) satisfies \(f(A^{*G}_1)=A^{*H}_1\), so it is sufficient to test if \(G^{\prime }\) and \(H^{\prime }\) are isomorphic, and we can do this by applying Case 1 or Case 2. The sets \(A^G_1 \setminus A^{*G}_1\) and \(A^H_1 \setminus A^{*H}_1\) consist of at most one vertex, so we can test if Property 2 can be satisfied in polynomial time. To satisfy Property 3, we only need to check whether there is a bijection q from the components of \(G[D^G\setminus D^{*G}]\) to the components of \(H[D^H\setminus D^{*H}]\) such that \(|q(C)|=|C|\) and \(|q(C) \cap B^H|=|C \cap B^G|\) for every component of \(G[D^G\setminus D^{*G}]\) and this can clearly be done in polynomial time. This completes the proof of Case 3. \(\square \)

4 New GI-complete Results

We state Theorems 56 and 7, which establish that Graph Isomorphism is GI-complete on \(({{\mathrm{diamond}}},2P_3)\)-free, \(({{\mathrm{diamond}}},P_6)\)-free and \(({{\mathrm{gem}}},P_1+2P_2)\)-free graphs, respectively (see Fig. 3). The complexity of Graph Isomorphism on \((\overline{2P_1+P_3},2P_3)\)-free graphs and \(({{\mathrm{gem}}},P_6)\)-free graphs was previously unknown, but since these classes contain the classes of \(({{\mathrm{diamond}}},2P_3)\)-free graphs and \(({{\mathrm{diamond}}},P_6)\)-free graphs, respectively, Theorems 5 and 6, respectively, imply that Graph Isomorphism is also GI-complete on these classes. In Theorems 5 and 6, GI-completeness follows from the fact that the constructions used in our proofs fall into the framework of so-called simple path encodings (see [30]). For brevity, we do not explain this general notion here, but instead include direct proofs of GI-completeness for both cases. The construction used in the proof of Theorem 7 does not fall into this framework and we give a direct proof of GI-completeness in this case.

Fig. 3
figure 3

Forbidden induced subgraphs from Theorems 56 and 7

Theorem 5

Graph Isomorphism is GI-complete on \(({{\mathrm{diamond}}},2P_3)\)-free graphs.

Proof

Let G be a graph. We construct a graph q(G) as follows:

  1. 1.

    Create a clique with vertex set \(A^G=V(G)\).

  2. 2.

    For every edge \(vw \in E(G)\), add vertices \(v_w\) and \(w_v\) and edges \(vv_w,v_ww_v\) and \(w_vw\). Let \(B^G\) be the set of vertices added in this step.

Note that every vertex in \(B^G\) has exactly two neighbours in q(G) and that these neighbours are non-adjacent. Therefore no induced \(K_3\) in q(G) contains a vertex of \(B^G\). Also note that \(|A^G|=|V(G)|\) and \(|B^G|=2|E(G)|\).

We claim that q(G) is \(({{\mathrm{diamond}}},2P_3)\)-free for every graph G. First suppose, for contradiction, that the \({{\mathrm{diamond}}}\) is an induced subgraph of q(G). Since no vertex in \(B^G\) is in an induced \(K_3\) in q(G), it follows that no vertex of this \({{\mathrm{diamond}}}\) can be in \(B^G\). This is a contradiction, since \(A^G\) is a clique. Therefore q(G) is \({{\mathrm{diamond}}}\)-free. Now suppose, for contradiction, that \(2P_3\) is an induced subgraph of q(G). Since \(q(G)[B^G]\) is a disjoint union of \(P_2\)’s, every \(P_3\) in q(G) must contain at least one vertex in \(A^G\). Therefore, the two components of the \(2P_3\) must each contain a vertex of \(A^G\) and so there must be two non-adjacent vertices in \(A^G\). Since \(A^G\) is a clique, this is a contradiction. Therefore q(G) is \(2P_3\)-free.

Given two graphs G and H, we claim that G is isomorphic to H if and only if q(G) is isomorphic to q(H). Clearly, if G is isomorphic to H, then q(G) is isomorphic to q(H). Now suppose that there is an isomorphism f from q(G) to q(H). Let us show that this implies G is isomorphic to H. If G or H contains at most two vertices, then this can be verified by inspection, so we may assume \(|V(G)|,|V(H)| \ge 3\). It follows that every vertex of \(A^G\) (resp. \(A^H\)) is in an induced \(K_3\) in q(G) (resp. q(H)). Since no vertex of \(B^G\) (resp. \(B^H\)) is in an induced \(K_3\) in q(G) (resp. q(H)), it follows that \(f(A^G)=A^H\) and \(f(B^G)=B^H\). Now two vertices v and w in G are adjacent if and only if v and w are connected in q(G) via a path of vertices in \(B^G\) if and only if f(v) and f(w) are connected in q(H) via a path of vertices in \(B^H\) if and only if f(v) and f(w) are adjacent in H. Therefore G is isomorphic to H. This completes the proof.\(\square \)

Theorem 6

Graph Isomorphism is GI-complete on \(({{\mathrm{diamond}}},P_6)\)-free graphs.

Proof

Let G be a graph. We construct a graph q(G) as follows:

  1. 1.

    Create an independent set with vertex set \(A^G=V(G)\).

  2. 2.

    Create an independent set with vertex set \(C^G=E(G)\).

  3. 3.

    Add every possible edge between \(A^G\) and \(C^G\).

  4. 4.

    For every edge \(e=vw \in E(G)\), add vertices \(v_w\) and \(w_v\) and edges \(vv_w,v_we,ew_v\) and \(w_vw\) (note that \(e \in C^G\)). Let \(B^G\) be the set of vertices added in this step.

Note that every vertex in \(B^G\) has exactly two neighbours in q(G) and these neighbours are adjacent. Furthermore, note that \(A^G,B^G\) and \(C^G\) are independent sets with \(|A^G|=|V(G)|\) and \(|B^G|=2|E(G)|=2|C^G|\).

We claim that q(G) is \(({{\mathrm{diamond}}},P_6)\)-free for every graph G. First suppose, for contradiction, that the \({{\mathrm{diamond}}}\) is an induced subgraph of q(G). Since \(A^G,B^G\) and \(C^G\) are independent sets, every induced \(K_3\) in q(G) must have exactly one vertex from each of these sets. Therefore, since the vertices of \(B^G\) have degree-2 in q(G), one of the degree-3 vertices of the \({{\mathrm{diamond}}}\) must be in \(A^G\) and the other in \(C^G\), and so both degree-2 vertices of the \({{\mathrm{diamond}}}\) must be in \(B^G\). However no pair of vertices in \(B^G\) has the same neighbour in \(A^G\) and the same neighbour in \(C^G\), a contradiction. We conclude that q(G) is \({{\mathrm{diamond}}}\)-free. Now suppose, for contradiction, that \(P_6\) is an induced subgraph of q(G). Since the two neighbours of every vertex in \(B^G\) are adjacent, the internal vertices of the \(P_6\) cannot lie in \(B^G\). Therefore \(q(G)[A^G \cup C^G]\) contains an induced \(P_4\). Since \(q(G)[A^G \cup C^G]\) is a complete bipartite graph, it is \(P_4\)-free. This contradiction implies that q(G) is \(P_6\)-free.

Now let G and H be graphs. Let \(G^*\) and \(H^*\) be the graphs obtained from G and H, respectively, by adding four pairwise adjacent vertices that are adjacent to every vertex of G and H, respectively. Given two graphs G and H, we claim that G is isomorphic to H if and only if \(q(G^*)\) is isomorphic to \(q(H^*)\). Clearly if G is isomorphic to H, then \(q(G^*)\) is isomorphic to \(q(H^*)\). Furthermore, G is isomorphic to H if and only if \(G^*\) is isomorphic to \(H^*\). Now suppose that there is an isomorphism f from \(q(G^*)\) to \(q(H^*)\). It suffices to show that \(G^*\) is isomorphic to \(H^*\). Note that \(|V(G^*)| \ge 4\) and \(|E(G^*)| \ge 6\) by construction. Thus every vertex in \(A^{G^*} \cup C^{G^*}\) has degree greater than 2 in \(q(G^*)\). Since every vertex in \(B^{G^*}\) has degree 2 in \(q(G^*)\), it follows that a vertex of \(q(G^*)\) has degree exactly 2 if and only if it is in \(B^{G^*}\). Similarly, a vertex of \(q(H^*)\) has degree 2 if and only if it is in \(B^{H^*}\). Therefore \(f(B^{G^*})=B^{H^*}\), and so \(|B^{G^*}|=|B^{H^*}|\). Since \(B^{G^*}=2|E(G^*)|\) and \(|B^{H^*}|=2|E(H^*)|\), it follows that \(|E(G^*)|=|E(H^*)|\). Since \(q(G^*)\) has \(|V(G^*)|+3|E(G^*)|\) vertices and \(q(H^*)\) has \(|V(H^*)|+3|E(H^*)|\) vertices, it follows that \(|V(G^*)|=|V(H^*)|\). Now \(q(G^*) \setminus B^{G^*}\) is a complete bipartite graph with parts of size \(|V(G^*)|\) and \(|E(G^*)|\), respectively. Since we obtained \(G^*\) from G by adding four vertices that are complete to every other vertex of \(G^*\), it follows that \(|E(G^*)| = |E(G)|+4(|V(G^*)|-4)+6\ge 3(|V(G^*)|-4) + |V(G^*)|+2 > |V(G^*)|\). We conclude that \(f(A^{G^*})=f(A^{H^*})\) and \(f(C^{G^*})=C^{H^*}\). Now two vertices v and w in \(G^*\) are adjacent if and only if v and w are connected in \(q(G^*)\) via a path of vertices in \(B^{G^*},C^{G^*}\) and \(B^{G^*}\), respectively if and only if f(v) and f(w) are connected in \(q(H^*)\) via a path of vertices in \(B^{H^*},C^{H^*}\) and \(B^{H^*}\), respectively, if and only if f(v) and f(w) are adjacent in \(H^*\). Therefore \(G^*\) is isomorphic to \(H^*\).

Combining the above with the fact that \(q(G^*)\) and \(q(H^*)\) are \(({{\mathrm{diamond}}},P_6)\)-free shows that Graph Isomorphism is GI-complete on \(({{\mathrm{diamond}}},P_6)\)-free graphs.\(\square \)

Theorem 7

Graph Isomorphism is GI-complete on \(({{\mathrm{gem}}},P_1+2P_2)\)-free graphs. Furthermore, \(({{\mathrm{gem}}},P_1+2P_2)\)-free graphs have unbounded clique-width.

Proof

Let G be a graph. Let \(v^G_1,\ldots ,v^G_n\) be the vertices of G and let \(e^G_1,\ldots ,e^G_m\) be the edges of G. For the proof of both statements of the theorem, we construct a graph q(G) from G as follows:

  1. 1.

    Create a complete multipartite graph with partition \((A^G_1,\ldots ,A^G_n)\), where \(|A^G_i|=d_G(v^G_i)\) for \(i \in \{1,\ldots ,n\}\) and let \(A^G=\bigcup A^G_i\).

  2. 2.

    Create a complete multipartite graph with partition \((B^G_1,\ldots ,B^G_m)\), where \(|B^G_i|=2\) for \(i \in \{1,\ldots ,m\}\) and let \(B^G=\bigcup B^G_i\).

  3. 3.

    Take the disjoint union of the two graphs above, then for each edge \(e^G_i=v^G_{i_1}v^G_{i_2}\) in G in turn, add an edge from one vertex of \(B^G_i\) to a vertex of \(A^G_{i_1}\) and an edge from the other vertex of \(B^G_i\) to a vertex of \(A^G_{i_2}\). Do this in such a way that the edges added between \(A^G\) and \(B^G\) form a perfect matching.

We claim that q(G) is \(({{\mathrm{gem}}},P_1+2P_2)\)-free. Since \(q(G)[A^G]\) and \(q(G)[B^G]\) are complete multipartite graphs, they must both be \((P_1+P_2)\)-free, so every induced \(P_1+P_2\) in q(G) must contain at least one vertex in \(A^G\) and at least one vertex in \(B^G\). Suppose, for contradiction, that the \({{\mathrm{gem}}}\) is an induced subgraph of q(G). Let \(X \in \{A^G,B^G\}\) be the set that contains the dominating vertex v of the \({{\mathrm{gem}}}\) and let Y be the other set. Since \({{\mathrm{gem}}}-v\) is isomorphic to \(P_4\), which contains an induced \(P_1+P_2\), at least one vertex w of the \({{\mathrm{gem}}}\) must be in Y. Since v has only one neighbour in Y, all other vertices of the \({{\mathrm{gem}}}\) must be in X. However, w has only one neighbour in X, but at least two neighbours in the \({{\mathrm{gem}}}\). This contradiction shows that q(G) is indeed \({{\mathrm{gem}}}\)-free. Now suppose, for contradiction, that \(P_1+2P_2\) is an induced subgraph of q(G). First suppose that one of the \(P_2\)’s in this \(P_1+2P_2\) either has both vertices in \(A^G\) or both vertices in \(B^G\); let \(X\in \{A^G,B^G\}\) be the set that contains this \(P_2\) and let Y be the other set. Then since q(G)[X] is \((P_1+P_2)\)-free, the remaining three vertices of the \(P_1+2P_2\) must be in Y. This means that q(G)[Y] contains \(P_1+P_2\) as an induced subgraph. This contradiction means that each of the \(P_2\)’s in the \(P_1+2P_2\) must have exactly one vertex in \(A^G\) and exactly one vertex in \(B^G\). Therefore there must be non-adjacent vertices \(x_1,x_2 \in A^G\) and non-adjacent vertices \(y_1,y_2 \in B^G\) such that \(x_i\) is adjacent to \(y_j\) if and only if \(i=j\). Therefore \(x_1\) and \(x_2\) must be in the same set \(A^G_i\) and \(y_1\) and \(y_2\) must be in the same set \(B^G_j\). This is a contradiction as the two vertices in \(B^G_j\) cannot both have neighbours in the same set \(A^G_i\). Therefore q(G) is indeed \(({{\mathrm{gem}}},P_1+2P_2)\)-free.

We are now ready to prove that Graph Isomorphism is GI-complete on \(({{\mathrm{gem}}},P_1+2P_2)\)-free graphs. Now let G and H be graphs. Let \(G^*\) and \(H^*\) be the graphs obtained from G and H, respectively, by adding four pairwise adjacent vertices that are adjacent to every vertex of G and H, respectively. Note that every vertex of \(G^*\) and \(H^*\) has degree at least 3. We claim that G is isomorphic to H if and only if \(q(G^*)\) is isomorphic to \(q(H^*)\). Clearly if G is isomorphic to H, then \(q(G^*)\) is isomorphic to \(q(H^*)\). Furthermore, G is isomorphic to H if and only if \(G^*\) is isomorphic to \(H^*\). Now suppose that there is an isomorphism f from \(q(G^*)\) to \(q(H^*)\). It suffices to show that \(G^*\) is isomorphic to \(H^*\). Note that \(q(G^*)[A^{G^*}]\) and \(q(G^*)[B^{G^*}]\) each contain an induced \(K_3\) (but there is no \(K_3\) in \(q(G^*)\) with vertices in both \(A^{G^*}\) and \(B^{G^*}\)). Furthermore, given such a \(K_3\) in \(q(G^*)[A^{G^*}]\) (resp. \(q(G^*)[B^{G^*}]\)), a vertex is in \(A^{G^*}\) (resp. \(B^{G^*}\)) if and only if it has at least two neighbours in this \(K_3\), so either \(f(A^{G^*})=A^{H^*}\) and \(f(B^{G^*})=B^{H^*}\) or \(f(A^{G^*})=B^{H^*}\) and \(f(B^{G^*})=A^{H^*}\). Since \(q(G^*)[A^{G^*}]\) contains an induced \(3P_1\), but \(q(G)[B^{G^*}]\) does not, it follows that \(f(A^{G^*})=A^{H^*}\) and \(f(B^{G^*})=B^{H^*}\). Furthermore, this implies that for all \(i \in \{1,\ldots ,n\}\), \(f(A^{G^*}_i)=A^{H^*}_j\) for some \(j \in \{1,\ldots ,n\}\) with \(|A^{H^*}_j|=|A^{G^*}_i|\) and for all \(i \in \{1,\ldots ,m\}\), \(f(B^{G^*}_i)=B^{H^*}_j\) for some \(j \in \{1,\ldots ,m\}\). Now two vertices \(v^{G^*}_i\) and \(v^{G^*}_j\) in \(G^*\) are adjacent if and only if there is a \(k \in \{1,\ldots ,m\}\) such that there are edges in \(q(G^*)\) from \(B^{G^*}_k\) to both \(A^{G^*}_i\) and \(A^{G^*}_j\) if and only if there is a \(k \in \{1,\ldots ,m\}\) such that there are edges in \(q(H^*)\) from \(f(B^{G^*}_k)\) to both \(f(A^{G^*}_i)\) and \(f(A^{G^*}_j)\) if and only if \(v^{H^*}_{i^{\prime }}\) and \(v^{H^*}_{j^{\prime }}\) are adjacent where \(f(A^{G^*}_i)=A^{H^*}_{i^{\prime }}\) and \(f(A^{G^*}_j)=A^{H^*}_{j^{\prime }}\). Therefore \(G^*\) is isomorphic to \(H^*\).

Combining the above with the fact that \(q(G^*)\) and \(q(H^*)\) are \(({{\mathrm{gem}}},P_1+2P_2)\)-free shows that Graph Isomorphism is GI-complete on \(({{\mathrm{gem}}},P_1+2P_2)\)-free graphs.

We now prove that the class of \(({{\mathrm{gem}}},P_1+2P_2)\)-free graphs has unbounded clique-width. Let \(H_n\) be the \(n \times n\) grid (see also Fig. 4). We claim that the set of graphs \(\{q(H_n) \;|\; n \in {\mathbb {N}}\}\) has unbounded clique-width and note that we have shown that every graph in this set is \(({{\mathrm{gem}}},P_1+2P_2)\)-free. Let \(H_n^{\prime }\) be the graph obtained from \(q(H_n)\) by complementing \(A^{H_n}\) and complementing \(B^{H_n}\) (see also Fig. 4). By Fact 2, it is sufficient to show that the set of graphs \(\{H_n^{\prime } \;|\; n \in {\mathbb {N}}\}\) has unbounded clique-width. We now partition \(V(H_n^{\prime })\) into sets \(V_{i,j}\) for \(i,j \in \{1,\ldots ,n\}\) as follows. For \(i,j \in \{1,\ldots ,n\}\) let \(V_{i,j}\) consist of the vertices in the set \(A^{H_n}_k\) that correspond to the vertex in the ith row and jth column of \(H_n\), along with the vertices in \(B^{H_n}\) that have a neighbour in \(A^{H_n}_k\). Note that every vertex of \(H_n^{\prime }\) is in exactly one set \(V_{i,j}\), so these sets form a partition of \(V(H_n^{\prime })\). Furthermore \(H_n^{\prime }[\cup ^n_{j=1}V_{i,j}]\) is connected for all \(i\ge 1\), \(H_n^{\prime }[\cup ^n_{i=1}V_{i,j}]\) is connected for all \(j\ge 1\), and for \(i,j,k,\ell \ge 1\), if a vertex of \(V_{i,j}\) is adjacent to a vertex of \(V_{k,\ell }\), then \(|k-i|\le 1\) and \(|\ell -j| \le 1\). Applying Lemma 6 with \(m=1\) we find that \(H_n^{\prime }\) has clique-width at least \(\lfloor \frac{n-1}{2}\rfloor +1\). This completes the proof.\(\square \)

Fig. 4
figure 4

The \(n\times n\) grid \(H_n\) and the graph \(H_n^{\prime }\), defined in the proof of Theorem 7, for \(n=4\). In the image of \(H_n^{\prime }\), the vertices in \(A^{H_n}\) are coloured black and the vertices in \(B^{H_n}\) are coloured white

5 Clique-Width for Hereditary Graph Classes

The following result (see [15] for a proof), combined with Theorem 1, shows that the classifications of the complexity of Graph Isomorphism and boundedness of clique-width are analogous for H-free graphs.

Theorem 8

Let H be a graph. The class of H-free graphs has bounded clique-width if and only if \(H \subseteq _iP_4\).

However, for \((H_1,H_2)\)-free graphs, the classifications no longer coincide. Below, we update the summary theorem and list of open cases from [14]. That is, we added the new case solved in Theorems 7 to 9 (Statement 2(vii)) and removed it from Open Problem 1. Given four graphs \(H_1,H_2,H_3,H_4\), the classes of \((H_1,H_2)\)-free graphs and \((H_3,H_4)\)-free graphs are equivalent if the unordered pair \(H_3,H_4\) can be obtained from the unordered pair \(H_1,H_2\) by some combination of the operations:

  1. (i)

    complementing both graphs in the pair, and

  2. (ii)

    if one of the graphs in the pair is \(K_3\), replacing it with the \({{\mathrm{paw}}}\) or vice versa.

If two classes are equivalent, then one of them has bounded clique-width if and only if the other one does [15].

Theorem 9

For a class \(\mathcal{G}\) of graphs defined by two forbidden induced subgraphs, the following holds:

  1. 1.

    \(\mathcal{G}\) has bounded clique-width if it is equivalent to a class of \((H_1,H_2)\)-free graphs such that one of the following holds:

    1. (i)

      \(H_1\) or \(H_2 \subseteq _iP_4\)

    2. (ii)

      \(H_1=K_s\) and \(H_2=tP_1\) for some \(s,t\ge 1\)

    3. (iii)

      \(H_1 \subseteq _i{{\mathrm{paw}}}\) and \(H_2 \subseteq _iK_{1,3}+3P_1,\; K_{1,3}+P_2,\;P_1+P_2+P_3,\;P_1+P_5,\;P_1+S_{1,1,2},\;P_2+P_4,\;P_6,\; S_{1,1,3}\) or \(S_{1,2,2}\)

    4. (iv)

      \(H_1 \subseteq _i{{\mathrm{diamond}}}\) and \(H_2\subseteq _iP_1+2P_2,\; 3P_1+P_2\) or \(P_2+P_3\)

    5. (v)

      \(H_1 \subseteq _i{{\mathrm{gem}}}\) and \(H_2 \subseteq _iP_1+P_4\) or \(P_5\)

    6. (vi)

      \(H_1\subseteq _iK_3+P_1\) and \(H_2 \subseteq _iK_{1,3}\)

    7. (vii)

      \(H_1\subseteq _i\overline{2P_1+P_3}\) and \(H_2\subseteq _i2P_1+P_3\).

  2. 2.

    \(\mathcal{G}\) has unbounded clique-width if it is equivalent to a class of \((H_1,H_2)\)-free graphs such that one of the following holds:

    1. (i)

      \(H_1\not \in \mathcal{S}\) and \(H_2 \not \in \mathcal{S}\)

    2. (ii)

      \(H_1\notin \overline{\mathcal{S}}\) and \(H_2 \not \in \overline{\mathcal{S}}\)

    3. (iii)

      \(H_1 \supseteq _iK_3+P_1\) or \(C_4\) and \(H_2 \supseteq _i4P_1\) or \(2P_2\)

    4. (iv)

      \(H_1 \supseteq _i{{\mathrm{diamond}}}\) and \(H_2 \supseteq _iK_{1,3},\; 5P_1,\; P_2+P_4\) or \(P_6\)

    5. (v)

      \(H_1 \supseteq _iK_3\) and \(H_2 \supseteq _i2P_1+2P_2,\; 2P_1+P_4,\; 4P_1+P_2,\; 3P_2\) or \(2P_3\)

    6. (vi)

      \(H_1 \supseteq _iK_4\) and \(H_2 \supseteq _iP_1 +P_4\) or \(3P_1+P_2\)

    7. (vii)

      \(H_1 \supseteq _i{{\mathrm{gem}}}\) and \(H_2 \supseteq _iP_1+2P_2\).

Open Problem 1

Does the class of \((H_1,H_2)\)-free graphs have bounded or unbounded clique-width when:

  1. (i)

    \(H_1=K_3\) and \(H_2 \in \{P_1+S_{1,1,3}, S_{1,2,3}\}\)

  2. (ii)

    \(H_1={{\mathrm{diamond}}}\) and \(H_2 \in \{P_1+P_2+P_3,P_1+P_5\}\)

  3. (iii)

    \(H_1={{\mathrm{gem}}}\) and \(H_2=P_2+P_3\).

6 Classifying the Complexity of Graph Isomorphism for \((H_1,H_2)\)-free Graphs

Recall that given four graphs \(H_1,H_2,H_3,H_4\), the classes of \((H_1,H_2)\)-free graphs and \((H_3,H_4)\)-free graphs are equivalent if the unordered pair \(H_3,H_4\) can be obtained from the unordered pair \(H_1,H_2\) by some combination of the operations:

  1. (i)

    complementing both graphs in the pair, and

  2. (ii)

    if one of the graphs in the pair is \(K_3\), replacing it with the \({{\mathrm{paw}}}\) or vice versa.

Note that two graphs G and H are isomorphic if and only if their complements \({\overline{G}}\) and \({\overline{H}}\) are isomorphic. Therefore, for every pair of graphs \(H_1,H_2\), the Graph Isomorphism problem is polynomial-time solvable or GI-complete for \((H_1,H_2)\)-free graphs if and only if the same is true for \((\overline{H_1},\overline{H_2})\)-free graphs. Since Graph Isomorphism can be solved component-wise, and it can easily be solved on complete multipartite graphs in polynomial time, Lemma 3 implies that for every graph \(H_1\), the Graph Isomorphism problem is polynomial-time solvable or GI-complete for \((H_1,K_3)\)-free graphs if and only if the same is true for \((H_1,{{\mathrm{paw}}})\)-free graphs. Thus if two classes are equivalent, then the complexity of Graph Isomorphism is the same on both of them.

Here is the summary of known results for the complexity of Graph Isomorphism on \((H_1,H_2)\)-free graphs (see Sect. 2 for notation).

Theorem 10

For a class \(\mathcal{G}\) of graphs defined by two forbidden induced subgraphs, the following holds:

  1. 1.

    Graph Isomorphism is solvable in polynomial time on \(\mathcal{G}\) if \(\mathcal{G}\) is equivalent to a class of \((H_1,H_2)\)-free graphs such that one of the following holds:

    1. (i)

      \(H_1\) or \(H_2 \subseteq _iP_4\)

    2. (ii)

      \(\overline{H_1}\) and \(H_2 \subseteq _iK_{1,t}+P_1\) for some \(t \ge 1\)

    3. (iii)

      \(\overline{H_1}\) and \(H_2 \subseteq _itP_1+P_3\) for some \(t \ge 1\)

    4. (iv)

      \(H_1 \subseteq _iK_t\) and \(H_2 \subseteq _i2K_{1,t}, K_{1,t}^+\) or \(P_5\) for some \(t \ge 1\)

    5. (v)

      \(H_1 \subseteq _i{{\mathrm{paw}}}\) and \(H_2 \subseteq _iP_2+P_4, P_6, S_{1,2,2}\) or \(K_{1,t}^{++}+P_1\) for some \(t \ge 1\)

    6. (vi)

      \(H_1 \subseteq _i{{\mathrm{diamond}}}\) and \(H_2 \subseteq _iP_1+2P_2\)

    7. (vii)

      \(H_1 \subseteq _i{{\mathrm{gem}}}\) and \(H_2 \subseteq _iP_1+P_4\) or \(P_5\)

    8. (viii)

      \(H_1 \subseteq _i\overline{2P_1+P_3}\) and \(H_2 \subseteq _iP_2+P_3\) or \(P_5\).

  2. 2.

    Graph Isomorphism is GI-complete on \(\mathcal{G}\) if \(\mathcal{G}\) is equivalent to a class of \((H_1,H_2)\)-free graphs such that one of the following holds:

    1. (i)

      neither \(H_1\) nor \(H_2\) is a path star forest

    2. (ii)

      neither \(\overline{H_1}\) nor \(\overline{H_2}\) is a path star forest

    3. (iii)

      \(H_1\supseteq _iK_3\) and \(H_2\supseteq _i2P_1+2P_2,P_1+2P_3,2P_1+P_4\) or \(3P_2\)

    4. (iv)

      \(H_1\supseteq _iK_4\) and \(H_2\supseteq _iK_{1,4}^{++}, P_1+2P_2\) or \(P_1+P_4\)

    5. (v)

      \(H_1\supseteq _iK_5\) and \(H_2\supseteq _iK_{1,3}^{++}\)

    6. (vi)

      \(H_1 \supseteq _iC_4\) and \(H_2 \supseteq _iK_{1,3}, 3P_1+P_2\) or \(2P_2\)

    7. (vii)

      \(H_1\supseteq _i{{\mathrm{diamond}}}\) and \(H_2 \supseteq _iK_{1,3}, P_2+P_4, 2P_3\) or \(P_6\)

    8. (viii)

      \(H_1\supseteq _i{{\mathrm{gem}}}\) and \(H_2\supseteq _iP_1+2P_2\).

Proof

In the proof of this theorem we will refer to theorems in a number of other papers, in some cases indicating the value some parameter given therein must take. Restating and fully explaining all these various theorems in detail is beyond the scope of this paper, but to aid the reader who refers to [22] or [30], we note that there H(abc) denotes \(K_{1,b}+cP_1\) if \(a=0\), H(abc) denotes \(K_{1,b+1}^{+}+cP_1\) if \(a=1\), and H(1, 0, b, 1) denotes \(K_{1,b+1}^{++}+P_1\).

We first consider the polynomial-time cases. Statement 1(i) follows from Theorem 1. Statement 1(ii) follows from the fact that for every \(t \ge 1\), Graph Isomorphism is solvable in polynomial-time on \((\overline{K_{1,t}+P_1},K_{1,t}+P_1)\)-free graphs [22, Theorem 4.2 with \(b=b^{\prime }=t\) and \(c=c^{\prime }=1\)]. Statement 1(iii) follows from the fact that for every \(t \ge 1\), Graph Isomorphism is solvable in polynomial-time on \((\overline{tP_1+P_3},tP_1+P_3)\)-free graphs [22, Theorem 4.2 and 4.3 with \(b=b^{\prime }=2\) and \(c=c^{\prime }=t\)]. Statement 1(iv) follows from the fact that for every \(t \ge 1\), Graph Isomorphism is solvable in polynomial-time on \((K_t,2K_{1,t})\)-free graphs [30, Corollary 3 with \(s=t\)] (see also Lemma 1), \((K_t,K_{1,t}^+)\)-free graphs [30, Theorem 16 with \(b=t-1\) and \(s=t\)] and \((K_t,P_5)\)-free graphs [30, Theorem 14]. Statement 1(v) follows from the fact that \(({{\mathrm{paw}}},H)\)-free graphs have bounded clique-width if \(H \in \{P_2+P_4, P_6, S_{1,2,2}\}\) (Theorem 9.1(iii)) combined with Theorem 2, along with the fact that for every \(t \ge 1\) Graph Isomorphism is solvable in polynomial-time on \((K_3,K_{1,t}^{++}+P_1)\)-free graphs [30, Theorem 15 with \(b=t-1\)] and this class is equivalent to the class of \(({{\mathrm{paw}}},K_{1,t}^{++}+P_1)\)-free graphs. Statement 1(vi) follows from the fact that \(({{\mathrm{diamond}}},P_1+2P_2)\)-free graphs have bounded clique-width (Theorem 9.1(iv)) combined with Theorem 2. Similarly, Statement 1(vii) follows from the fact that \(({{\mathrm{gem}}},H)\)-free graphs have bounded clique-width if \(H \in \{P_1+P_4,P_5\}\) (Theorem 9.1(v)) combined with Theorem 2. Statement 1(viii) follows from the fact that Graph Isomorphism is solvable in polynomial-time on \((\overline{2P_1+P_3},P_2+P_3)\)-free graphs (Theorem 4) and \((\overline{2P_1+P_3},P_5)\)-free graphs (Theorem 3).

Next, we consider the GI-complete cases. Statement 2(i) is [22, Lemma 2]. Statement 2(ii) follows from Statement 2(i) since the class of \((\overline{H_1},\overline{H_2})\)-free graphs is equivalent to the class of \((H_1,H_2)\)-free graphs. Statement 2(iii) follows from the fact that Graph Isomorphism is GI-complete on H-free bipartite graphs if \(H \in \{2P_1+2P_2,2P_1+P_4,3P_2\}\) [22, Lemma 5] or \(H=P_1+2P_3\) [30, Theorem 6]. Statement 2(iv) follows from the fact that Graph Isomorphism is GI-complete on \((K_4,H)\)-free graphs if \(H \in \{K_{1,4}^{++}, P_1+2P_2\}\) [30, Theorem 5] or \(H=2P_1+P_4\) [22, Theorem 3]. Statement 2(v) follows from the fact that Graph Isomorphism is GI-complete on \((K_5,K_{1,3}^{++})\)-free graphs [30, Theorem 7]. Statement 2(vi) follows from the fact that Graph Isomorphism is GI-complete on \((C_4,C_5,3P_1+P_2,2P_2)\)-free graphs [22, Lemma 6 with \(i=2\)] and for \((C_4,{{\mathrm{diamond}}},K_{1,3})\)-free graphs [22, Lemma 9]. Statement 2(vii) follows from the fact that Graph Isomorphism is GI-complete on \((C_4,{{\mathrm{diamond}}},K_{1,3})\)-free graphs [22, Lemma 9] and on \(({{\mathrm{diamond}}},H)\)-free graphs if H is \(P_2+P_4\) [12, Theorem 3], \(2P_3\) (Theorem 5) or \(P_6\) (Theorem 6). Statement 2(viii) follows from the fact that Graph Isomorphism is GI-complete on \((\overline{P_1+P_4},P_1+2P_2)\)-free graphs (Theorem 7).\(\square \)

Open Problem 2

What is the complexity of Graph Isomorphism on \((H_1,H_2)\)-free graphs in the following cases?

  1. (i)

    \(H_1=K_3\) and \(H_2 \in \{P_7,S_{1,2,3}\}\)

  2. (ii)

    \(H_1=K_4\) and \(H_2=S_{1,1,3}\)

  3. (iii)

    \(H_1={{\mathrm{diamond}}}\) and \(H_2 \in \{P_1+P_2+P_3,P_1+P_5\}\)

  4. (iv)

    \(H_1={{\mathrm{gem}}}\) and \(H_2=P_2+P_3\)

Note that all of the classes of \((H_1,H_2)\)-free graphs in Open Problem 2 are incomparable. The following theorem states that Open Problem 2 lists all open cases.

Theorem 11

Let \(\mathcal{G}\) be a class of graphs defined by two forbidden induced subgraphs. Then \(\mathcal{G}\) is not equivalent to any of the classes listed in Theorem 10if and only if it is equivalent to one of the six cases listed in Open Problem 2.

Proof

It is easy to verify that none of the classes in Open Problem 2 are equivalent to any of the classes in Theorem 10.

Let \(H_1,H_2\) be graphs and let \(\mathcal{G}\) be the class of \((H_1,H_2)\)-free graphs. Suppose \(\mathcal{G}\) is not equivalent to any class for which the complexity of Graph Isomorphism is implied by Theorem 10. We will show that \(\mathcal{G}\) is equivalent one of the classes in Open Problem 2. By Theorem 10.1(i), we may assume that \(H_1,H_2 \not \subseteq _iP_4\). Since \(P_4=\overline{P_4}\), this means that none of \(H_1,\overline{H_1},H_2,\overline{H_2}\) are induced subgraphs of \(P_4\).

By Theorem 10.2(i), at least one of \(H_1\) and \(H_2\) must be a path star forest. By Theorem 10.2(ii), at least one of \(\overline{H_1}\) and \(\overline{H_2}\) must be a path star forest. Suppose, for contradiction, that both \(H_1\) and \(\overline{H_1}\) are path star forests. Let n be the number of vertices in \(H_1\). Then \(H_1\) and \(\overline{H_1}\) each contain at most \(n-1\) edges. Since \(H_1\) and \(\overline{H_1}\) together have \(\left( {\begin{array}{c}n\\ 2\end{array}}\right) \) edges, it follows that \(\left( {\begin{array}{c}n\\ 2\end{array}}\right) \le 2(n-1)\) and so \(n \le 4\). It is easy to verify that if F is a forest on at most four vertices and \({\overline{F}}\) is also a forest, then F is an induced subgraph of \(P_4\). Therefore \(H_1\) is an induced subgraph of \(P_4\), a contradiction. By symmetry, we may therefore assume that \(\overline{H_1}\) and \(H_2\) are path star forests, but \(H_1\) and \(\overline{H_2}\) are not.

Also note that by definition of equivalence, the theorem is symmetric in \(\overline{H_1}\) and \(H_2\). We will consider a number of cases, depending on the possibilities for \(H_1\). First, we consider the cases when \(H_1=K_s\) for some \(s \ge 1\). Since \(H \not \subseteq _iP_4\), we may assume that \(s \ge 3\).

Case 1

\(H_1=K_3\).

By Theorem 10.2(iii), we may assume that \(H_2\) is \((2P_1+2P_2,P_1+2P_3,2P_1+P_4,3P_2)\)-free.

First consider the case when \(H_2\) is a \(P_4\)-free path star forest, or equivalently when \(H_2\) is a disjoint union of stars. Since \(H_2\) is \(3P_2\)-free, it has at most two non-trivial components. If \(H_2\) has at most one non-trivial component, then it is an induced subgraph of \(K_{1,t} +tP_1 \subseteq _i2K_{1,t}\) for some \(t \ge 1\) and so Theorem 10.1(iv) applies. If \(H_2\) has two non-trivial components, at least one of which is isomorphic to \(P_2\), then \(H_2\) has at most three components since it is \((2P_1+2P_2)\)-free, and so \(H_2\) is an induced subgraph of \(K_{1,t}+P_2 +P_1 \subseteq _iK_{1,t+1}^{++} +P_1\) for some \(t \ge 1\) and so Theorem 10.1(v) applies. If \(H_2\) has two non-trivial components, neither of which is isomorphic to \(P_2\), then both of these components contain an induced \(P_3\). In this case, since \(H_2\) is \((P_1+2P_3)\)-free, \(H_2\) contains exactly two components, so it is an induced subgraph of \(2K_{1,t}\) for some \(t \ge 1\) and thus Theorem 10.1(iv) applies. Therefore we may assume that \(H_2\) contains an induced \(P_4\).

Let C be the component of \(H_2\) that contains this induced \(P_4\). Since \(H_2\) is \((2P_1+P_4)\)-free, \(H_2\) contains at most one component apart from C. Furthermore, if it does contain a second component, then that component must isomorphic to \(P_1\) or \(P_2\). In other words, \(H_2\) is isomorphic to C, \(C+P_1\) or \(C+P_2\).

If \(H_2=C+P_2\), then since \(H_2\) is \((2P_1+2P_2,3P_2)\)-free, it follows that C is a \((2P_1+P_2,2P_2)\)-free tree that contains an induced \(P_4\). Since C is \(2P_2\)-free, the end-vertices of the induced \(P_4\) cannot have a neighbour outside the \(P_4\) and since it is \((2P_1+P_2)\)-free, the two internal vertices of the \(P_4\) cannot have a neighbour outside the \(P_4\). Therefore \(H_2=P_2+P_4\) and so Theorem 10.1(v) applies. We may therefore assume that \(H_2 \ne C+P_2\).

Suppose that \(H_2=C+P_1\). Since \(H_2\) is \((2P_1+2P_2,2P_1+P_4)\)-free, it follows that C is \((P_1+2P_2,P_1+P_4)\)-free. Since C is \((P_1+P_4)\)-free, the \(P_4\) dominates C and at most one of the end-vertices of the \(P_4\) has a neighbour outside this \(P_4\). Since \(H_2\) is a path star forest, it has at most one vertex of degree greater than 2. Therefore, since the \(P_4\) dominates C, it follows that C is obtained from \(P_4\) or \(P_5\) by attaching a (possibly empty) set of pendant edges to one of its internal vertices. Since C is \((P_1+2P_2)\)-free, it cannot be obtained from \(P_5\) by adding a non-zero number of pendant vertices adjacent to the central vertex. Therefore C is obtained from \(P_4\) or \(P_5\) by adding t pendant vertices to a vertex adjacent to an end-vertex of this path for some \(t \ge 0\). It follows that \(H_2=K_{1,t+2}^++P_1\) or \(H_2=K_{1,t+2}^{++}+P_1\), respectively and so Theorem 10.1(v) applies. We may therefore assume that \(H_2 \ne C+P_1\).

Finally, suppose that \(H_2=C\), in which case \(H_2\) is connected. Then it is obtained from \(K_{1,t}\) for some \(t \ge 2\) by subdividing edges. If \(t=2\), then \(H_2\) is isomorphic to \(P_k\) for some \(k \ge 4\), and \(k \le 7\) since \(H_2\) is \(3P_2\)-free. If \(k=7\), then Open Problem 2.(i) applies, and if \(k \le 6\), then Theorem 10.1(v) applies. We may therefore assume that \(t \ge 3\). Since \(H_2\) is \((2P_1+P_4)\)-free, each edge of this \(K_{1,t}\) can be subdivided at most twice. If \(t \ge 4\), then at most one of the edges of the \(K_{1,t}\) can be subdivided since \(H_2\) is \((2P_1+2P_2)\)-free and so in this case \(H_2 \subseteq _iK_{1,t}^{++}\) and Theorem 10.1(v) applies. We may therefore assume that \(t=3\), so \(H_2=S_{i,j,k}\) for some \(1 \le i \le j \le k\). Now \(k \ge 2\) since \(H_2\) contains an induced \(P_4\) and \(k \le 3\) since each edge of the \(K_{1,t}\) is subdivided at most twice. If \(k=2\) or \(j=1\), then \(H_2 \subseteq _iS_{1,2,2}\) or \(H_2 \subseteq _iS_{1,1,3}=K_{1,t}^{++}\) for \(t=3\), respectively and Theorem 10.1(v) applies, so we may assume \(j=2\) and \(k=3\). Therefore \(H_2=S_{1,2,3}\) and Open Problem 2.(i) applies. This completes the proof for Case 1.

Case 2

\(H_1=K_s\) for some \(s \ge 4\).

By Theorem 10.2(iv), we may assume that \(H_2\) is \((K_{1,4}^{++},P_1+2P_2,P_1+P_4)\)-free. Since \(H_2\) is \((P_1+2P_2)\)-free, if it contains two non-trivial components, then it contains no other components. Thus if every component of \(H_2\) is a star, then either \(H_2\) contains only two components, or \(H_2\) contains at most one non-trivial component and all other components are trivial. In the first case \(H_2 \subseteq _i2K_{1,t}\) for some \(t \ge 1\) and in the second case \(H_2 \subseteq _iK_{1,t}+tP_1 \subseteq _i2K_{1,t}\) for some \(t \ge 1\). Therefore, if every component of \(H_2\) is a star, then Theorem 10.1(iv) applies. We may therefore assume that \(H_2\) is not a disjoint union of stars. Since \(H_2\) is a forest, this implies that \(P_4\) is an induced subgraph of \(H_2\). Since \(H_2\) is \((P_1+P_4)\)-free, this \(P_4\) must dominate \(H_2\) and \(H_2\) cannot be isomorphic to \(P_k\) for \(k \ge 6\). In particular, note that this implies that \(H_2\) is connected. If \(H_2\) has maximum degree at most 2, then \(H_2 \subseteq _iP_5\) and Theorem 10.1(iv) applies. We may therefore assume that \(H_2\) is obtained by subdividing edges of \(K_{1,t}\) for some \(t \ge 3\). Since \(H_2\) is \((P_1+2P_2)\)-free, at most one edge of the \(K_{1,t}\) can be subdivided. Since \(H_2\) is \((P_1+P_4)\)-free, any edge of the \(K_{1,t}\) can be subdivided at most twice, and so \(H_2 \subseteq _iK_{1,t}^{++}\). If \(H_2\) is obtained from \(K_{1,t}\) by subdividing an edge at most once, then \(H_2 \subseteq _iK_{1,t}^+\) and Theorem 10.1(iv) applies, so we may assume that \(H_2=K_{1,t}^{++}\). Since \(H_2\) is \(K_{1,4}^{++}\)-free, it follows that \(t=3\) and so \(H_2=K_{1,3}^{++}=S_{1,1,3}\). Now Open Problem 2.(ii) or Theorem 10.2(v) applies if \(s=4\) or \(s \ge 5\), respectively. This completes the proof for Case 2.

For the remainder of the proof we may therefore assume that Cases 1 and 2 do not apply, so \(H_1\) is not a complete graph. By symmetry between \(\overline{H_1}\) and \(H_2\), we may thus assume that both these graphs contain an edge. Furthermore, by definition of equivalence, if \(\overline{H_1}\) or \(H_2\) is isomorphic to \(P_1+P_3={\overline{{{\mathrm{paw}}}}}\), then we can replace the graph in question by \(3P_1=\overline{K_3}\). Thus Case 1 completes the proof if \(\overline{H_1}\) or \(H_2\) is either \(3P_1\) or \(P_1+P_3\). Every induced subgraph of \(P_1+P_3\), other than \(3P_1\) and \(P_1+P_3\), is an induced subgraph of \(P_4\), and we assumed that neither \(\overline{H_1}\) nor \(H_2\) is an induced subgraph of \(P_4\). In the remainder of the proof we may therefore assume that neither \(\overline{H_1}\) nor \(H_2\) is an induced subgraph of \(P_1+P_3\) or of \(P_4\).

Case 3

\(\overline{H_1}\) not a linear forest.

In this case \(\overline{H_1}\) contains a vertex of degree at least 3, so it contains an induced \(K_{1,3}\). Note that \(\overline{C_4}=2P_2\) and \({\overline{{{\mathrm{diamond}}}}}=2P_1+P_2\). Therefore, by Theorems 10.2(vi) and 10.2(vii), respectively, we may assume that \(H_2\) is \(2P_2\)-free and \((2P_1+P_2)\)-free. Since \(H_2\) is \(2P_2\)-free, it has at most one non-trivial component. Furthermore, every non-trivial component of \(H_2\) must be a \(2P_2\)-free path star, so it must be isomorphic to \(K_{1,k}\) or \(K_{1,k}^+\) for some \(k \ge 1\). Recall that we may assume that \(H_2\) contains at least one non-trivial component, otherwise we reduce to Case 1 or 2. Therefore, since \(H_2\) is \((2P_1+P_2)\)-free, it can have at most one trivial component and we conclude that \(H_2 \in \{K_{1,k}, K_{1,k}^+,K_{1,k}+P_1,K_{1,k}^++P_1\}\) for some \(k \ge 1\). If \(k \le 2\), then either \(H_2\) is an induced subgraph of \(P_1+P_3\) or \(P_4\), or \(H_2 = K_{1,2}^++P_1=P_1+P_4\), in which case \(H_2\) contains an induced \(2P_1+P_2\), a contradiction. We may therefore assume that \(k\ge 3\), in which case \(H_2 \notin \{K_{1,k}^+,K_{1,k}^++P_1\}\) since \(H_2\) is \((2P_1+P_2)\)-free. Thus \(H_2\in \{K_{1,k},K_{1,k}+P_1\}\) for some \(k \ge 3\). In particular, this implies \(K_{1,3} \subseteq _iH_2\), so by the same argument with \(H_2\) taking the part of \(\overline{H_1}\), we may assume that \(\overline{H_1} \in \{K_{1,t}, K_{1,t}+P_1\}\) for some \(t \ge 3\). Therefore Theorem 10.1(ii) applies. This completes the proof for Case 3.

For the remainder of the proof we may therefore assume that Case 3 does not apply. By symmetry between \(\overline{H_1}\) and \(H_2\), we may thus assume that both these graphs are linear forests.

Case 4

\(\overline{H_1}\) contains \(P_5\) as an induced subgraph.

Recall that we may assume \(H_2\) contains a non-trivial component, otherwise we reduce to Case 1 or 2. Note that \(P_5 \supseteq _i2P_2=\overline{C_4}\). Therefore, by Theorem 10.2(vi), we may assume that \(H_2\) is \((3P_1+P_2,2P_2)\)-free. Since \(H_2\) is \(2P_2\)-free, it has exactly one non-trivial component, which must be isomorphic to \(P_t\), for some \(2 \le t \le 4\). Since \(H_2\) is not an induced subgraph of \(P_4\), it follows that \(H_2\) is isomorphic to \(sP_1+P_t\) for some \(s \ge 1\) and \(t \in \{2,3,4\}\). Since \(H_2\) is \((3P_1+P_2)\)-free, it follows that \(s \le 2\) and if \(t=4\), then \(s=1\). Since \(H_2\) is not an induced subgraph of \(P_1+P_3\), if \(s=1\), then \(t=4\). Therefore \(H_2 \in \{2P_1+P_2,2P_1+P_3,P_1+P_4\}\). First consider the case when \(H_2=P_1+P_4\). By Theorems 10.2(vii) and 10.2(viii), respectively, we may assume that \(\overline{H_1}\) is \(P_6\)-free and \((P_1+2P_2)\)-free. Since \(\overline{H_1}\) contains \(P_5\) as an induced subgraph, but is \((P_1+2P_2)\)-free, it follows that \(\overline{H_1}\) is connected. Since \(\overline{H_1}\) is \(P_6\)-free, it follows that \(\overline{H_1}=P_5\), and so Theorem 10.1(vii) applies. This completes the case when \(H_2=P_1+P_4\) and so we may assume that \(H_2 \in \{2P_1+P_2,2P_1+P_3\}\). By Theorems 10.2(iii) and 10.2(vii), respectively, we may assume that \(\overline{H_1}\) is \((2P_1+2P_2)\)-free and \((P_2+P_4,P_6)\)-free. Since \(\overline{H_1}\) is a \(P_6\)-free linear forest that contains \(P_5\) as an induced subgraph, it follows that \(\overline{H_1}\) contains a component isomorphic to \(P_5\). Since \(\overline{H_1}\) is \((2P_1+2P_2,P_2+P_4)\)-free, it follows that \(\overline{H_1}\) contains at most one vertex outside this component, so \(\overline{H_1} \in \{P_5,P_1+P_5\}\). If \(\overline{H_1}=P_5\), then Theorem 10.1(vii) applies if \(H_2=2P_1+P_2 \subseteq _iP_1+P_4\) and Theorem 10.1(viii) applies of \(H_2=2P_1+P_3\). If \(\overline{H_1}=P_1+P_5\), then Open Problem 2.(iii) applies if \(H_2=2P_1+P_2\) and Theorem 10.2(iv) applies if \(H_2=2P_1+P_3 \supseteq _i4P_1\). This completes the proof for Case 4.

Case 5

\(\overline{H_1}\) contains \(P_4\) as an induced subgraph.

By Case 3 we may assume that \(\overline{H_1}\) and \(H_2\) are linear forests and by Cases 1 and 2, we may assume they each contain at least one non-trivial component. By Case 4, we may assume that \(\overline{H_1}\) is \(P_5\)-free, so it contains a component isomorphic to \(P_4\). Since \(\overline{H_1}\) is not an induced subgraph of \(P_4\), it follows that \(\overline{H_1}\) contains at least one other component. First consider the case when \(\overline{H_1}\) contains a non-trivial component apart from this \(P_4\), so \(P_2+P_4 \subseteq _i\overline{H_1}\). In this case Theorems 10.2(vi) and 10.2(vii), respectively, imply that \(H_2\) is \(2P_2\)-free and \((2P_1+P_2)\)-free. Since \(H_2\) is \(2P_2\)-free, it has one non-trivial component, which must be isomorphic to \(P_t\) for some \(2 \le t \le 4\). Since \(H_2\) is \((2P_1+P_2)\)-free, it follows that \(H_2\) is an induced subgraph of \(P_1+P_3\) or \(P_4\), a contradiction. We conclude that \(\overline{H_1}\) cannot contain any non-trivial components apart from the \(P_4\) and so \(\overline{H_1}=tP_1+P_4\) for some \(t \ge 1\). If \(t \ge 2\), then by Theorem 10.2(iii) we may assume that \(H_2\) is \(3P_1\)-free. Since \(H_2\) is a linear forest that is not an induced subgraph of \(P_4\), this implies that \(H_2=2P_2\), in which case Theorem 10.2(vi) applies. We may therefore assume that \(t=1\) and so \(\overline{H_1}=P_1+P_4\). By symmetry, if \(H_2\) contains a \(P_4\) as an induced subgraph, then we may assume \(H_2=P_1+P_4\), in which case Theorem 10.1(vii) applies. We may therefore assume that \(H_2\) is \(P_4\)-free, so every component of \(H_2\) is isomorphic to \(P_1\), \(P_2\) or \(P_3\). By Theorems 10.2(iv), 10.2(vii) and 10.2(viii), respectively, we may assume that \(H_2\) is \(4P_1\)-free, \(2P_3\)-free and \((P_1+2P_2)\)-free. Since \(H_2\) is \(2P_3\)-free, it contains at most one component isomorphic to \(P_3\). Since \(H_2\) is \((P_1+2P_2)\)-free, if it contains two non-trivial components, then it contains no other components. In this case \(H_2=2P_2\subseteq _iP_5\) or \(H_2=P_2+P_3\), in which case Theorem 10.1(vii) or Open Problem 2.(iv), respectively, applies. We may therefore assume that \(H_2\) contains exactly one non-trivial component. Since \(H_2\) is \(4P_1\)-free, but not an induced subgraph of \(P_1+P_3\), it follows that \(H_2=2P_1+P_2\subseteq _iP_1+P_4\) and so Theorem 10.1(vii) applies. This completes the proof for Case 5.

Case 6

\(\overline{H_1}\) contains \(2P_2\) as an induced subgraph.

We may assume that \(H_2\) contains a non-trivial component, otherwise we reduce to Case 1 or 2. Furthermore, we may assume that \(H_2\) is a \(P_4\)-free linear forest, otherwise we reduce to Case 3 or 5. By Theorem 10.2(vi), we may assume that \(H_2\) is \((3P_1+P_2,2P_2)\)-free. Since \(H_2\) is \(2P_2\)-free, but contains at least one non-trivial component, it follows that \(H_2\) contains exactly one non-trivial component. Furthermore, since \(H_2\) is \(P_4\)-free, this non-trivial component is isomorphic to either \(P_2\) or \(P_3\). Since \(H_2\) is \((3P_1+P_2)\)-free, but not an induced subgraph of \(P_1+P_3\), it follows that \(H_2 \in \{2P_1+P_2,2P_1+P_3\}\). By Theorems 10.2(iii) and 10.2(vii), respectively, we may assume that \(\overline{H_1}\) is \((2P_1+2P_2,3P_2)\)-free and \(2P_3\)-free. Since \(\overline{H_1}\) is \(3P_2\)-free, it has at most two non-trivial components and since it contains \(2P_2\) as an induced subgraph, it must contain at least two non-trivial components. Since \(\overline{H_1}\) is \(2P_3\)-free, its non-trivial components must either both be isomorphic to \(P_2\), or one of these components is isomorphic to \(P_2\) and the other to \(P_3\). We may assume that \(\overline{H_1}\) has another component, otherwise \(\overline{H_1} \subseteq _iP_2+P_3\), in which case Theorem 10.1(viii) applies. Since \(\overline{H_1}\) is \((2P_1+2P_2)\)-free, it has at most one other component, which must be trivial. We conclude that \(\overline{H_1} \in \{P_1+2P_2, P_1+P_2 + P_3\}\). By Theorem 10.2(iv), we may assume that \(H_2\) is \(4P_1\)-free, so \(H_2=2P_1+P_2\). Theorem 10.1(vi) or Open Problem 2.(iii) applies if \(\overline{H_1}=2P_1+P_2\) or \(P_1+P_2 + P_3\), respectively. This completes the proof for Case 6.

By Case 3 we may assume that \(\overline{H_1}\) and \(H_2\) are both linear forests. By Cases 5 and 6, we may assume that they are both \((2P_2,P_4)\)-free. Since, \(\overline{H_1}\) and \(H_2\) are \(2P_2\)-free, they each contain at most one non-trivial component. Since they are \(P_4\)-free, any such non-trivial component must be isomorphic to \(P_2\) or \(P_3\). Therefore \(\overline{H_1}\) and \(H_2\) must both be induced subgraphs of \(tP_1+P_3\) for some \(t \ge 1\). In this case Theorem 10.1(iii) applies. This completes the proof. \(\square \)

7 Conclusions

By combining known and new results, we determined the complexity of Graph Isomorphism in terms of polynomial-time solvability and GI-completeness for \((H_1,H_2)\)-free graphs for all but six pairs \((H_1,H_2)\). This also led to a new class of \((H_1,H_2)\)-free graphs whose clique-width is unbounded. In particular, we developed a technique for showing polynomial-time solvability of Graph Isomorphism for \((\overline{2P_1+P_3},H)\)-free graphs, which we illustrated for the \(H=P_2+P_3\) and \(H=P_5\) cases, thus completing the classification for \((\overline{2P_1+P_3},H)\)-free graphs. To obtain full dichotomies for the complexity of Graph Isomorphism and the (un)boundedness of clique-width on \((H_1,H_2)\)-free graphs, we need to solve the six remaining open cases for Graph Isomorphism (see Open Problem 2) and five open cases for boundedness of clique-width (see Open Problem 1). We leave this as future work, but note that new techniques will be required to deal with these cases.