Finding Cactus Roots in Polynomial Time

A graph H is a square root of a graph G, or equivalently, G is the square of H, if G can be obtained from H by adding an edge between any two vertices in H that are of distance 2. The Square Root problem is that of deciding whether a given graph admits a square root. The problem of testing whether a graph admits a square root which belongs to some specified graph class \documentclass[12pt]{minimal} \usepackage{amsmath} \usepackage{wasysym} \usepackage{amsfonts} \usepackage{amssymb} \usepackage{amsbsy} \usepackage{mathrsfs} \usepackage{upgreek} \setlength{\oddsidemargin}{-69pt} \begin{document}$\mathcal {H}$\end{document}ℋ is called the \documentclass[12pt]{minimal} \usepackage{amsmath} \usepackage{wasysym} \usepackage{amsfonts} \usepackage{amssymb} \usepackage{amsbsy} \usepackage{mathrsfs} \usepackage{upgreek} \setlength{\oddsidemargin}{-69pt} \begin{document}$\mathcal {H}$\end{document}ℋ-Square Root problem. By showing boundedness of treewidth we prove that Square Root is polynomial-time solvable on some classes of graphs with small clique number and that \documentclass[12pt]{minimal} \usepackage{amsmath} \usepackage{wasysym} \usepackage{amsfonts} \usepackage{amssymb} \usepackage{amsbsy} \usepackage{mathrsfs} \usepackage{upgreek} \setlength{\oddsidemargin}{-69pt} \begin{document}$\mathcal {H}$\end{document}ℋ-Square Root is polynomial-time solvable when \documentclass[12pt]{minimal} \usepackage{amsmath} \usepackage{wasysym} \usepackage{amsfonts} \usepackage{amssymb} \usepackage{amsbsy} \usepackage{mathrsfs} \usepackage{upgreek} \setlength{\oddsidemargin}{-69pt} \begin{document}$\mathcal {H}$\end{document}ℋ is the class of cactuses.


Introduction
Squares and square roots are well-known concepts in graph theory that have been studied first from a structural perspective [27,30] and later also from an algorithmic perspective (as we will discuss). The square G = H 2 of a graph H = (V H , E H ) is the graph with vertex set V G = V H , such that any two distinct vertices u, v ∈ V H are adjacent in G if and only if u and v are of distance at most 2 in H . A graph H is a square root of G if G = H 2 . It is a straightforward exercise to check that there exist graphs with no square root, graphs with a unique square root as well as graphs with many square roots.
In this paper we consider square roots from an algorithmic point of view. The corresponding recognition problem, which asks whether a given graph admits a square root, is called the SQUARE ROOT problem. Our research is motivated by the result of Motwani and Sudan [26] who proved in 1994 that SQUARE ROOT is NP-complete. Afterwards, SQUARE ROOT was shown to be polynomial-time solvable for various graph classes, such as planar graphs [23], or more generally, any non-trivial minor-closed graph class [28]; block graphs [21]; line graphs [24]; trivially perfect graphs [25]; threshold graphs [25]; graphs of maximum degree 6 [4] and graphs of maximum average degree smaller than 46 11 [14]. It was also shown that SQUARE ROOT is NP-complete for chordal graphs [18]. We refer to [4,5,14] for a number of parameterized complexity results on SQUARE ROOT.
The computational hardness of SQUARE ROOT also led to a variant, which asks whether a given graph has a square root that belongs to some specified graph class H. We denote this problem by H-SQUARE ROOT. The H-SQUARE ROOT problem is known to be polynomial-time solvable if H is the class of trees [23], proper interval graphs [18], bipartite graphs [17], block graphs [21], strongly chordal split graphs [22], graphs with girth at least g for any fixed g ≥ 6 [11], ptolemaic graphs [19], 3-sun-free split graphs [19] (see [20] for an extension of the latter result to other subclasses of split graphs). In contrast, NP-completeness of this problem has been shown if H is the class of split graphs [18], chordal graphs [18], graphs of girth at least 4 [11] or graphs of girth at least 5 [10].
It follows from a result of Harary, Karp and Tutte [16] that every square root H of a planar square has maximum degree at most 3 and only contains blocks that are of size 4 or isomorphic to an even cycle. It follows from this that such graphs H have bounded treewidth. By "blowing up" each bag of a tree decomposition by adding all neighbours of every vertex u to every bag that contains u, we get a tree decomposition of H 2 . Hence, planar squares have bounded treewidth. As such we may use Courcelle's Theorem [6] to obtain an alternative (but comparable) proof for the polynomial-time result of Lin and Skiena [23] for SQUARE ROOT restricted to planar graphs. We note that the polynomial-time algorithms for solving SQUARE ROOT for graphs of maximum degree at most 6 [4] and graphs of maximum average degree less than 46 11 [14] are also based on showing that the graphs which permit square roots also have bounded treewidth. Nestoridis and Thilikos [28] proved their result for minorclosed graph classes by showing boundedness of carving width. It is also possible, by using the graph minor decomposition of Robertson and Seymour [29], to show that squares of graphs from minor-closed classes have in fact bounded treewidth.
Hence, it is a natural question to ask whether the technique of showing boundedness of treewidth can be used for recognizing some other squares as well. This is the main focus of our paper.

Our Results
Our results are twofold. First, in Section 3 we focus on the H-SQUARE ROOT problem for a specific class H of graphs, namely we let H be the class of cactuses. A connected graph is a cactus if every edge of it is contained in at most one cycle. We give an O(n 4 )-time algorithm for solving H-SQUARE ROOT on n-vertex graphs where H is the class of cactuses. Our research is motivated by the nontrivial question as to whether H-SQUARE ROOT is polynomial-time solvable if H is the class of planar graphs, that is, whether squares of planar graphs can be recognized in polynomial time. The known result that squares of trees, which form a subclass of the class of cactuses, can be recognized in polynomial time [23] can be seen as a first step towards solving this problem. As every cactus is planar, our result can be seen as a second step towards solving it. As a side note, cactuses are not a subclass of any of the other aforementioned classes of which the squares can be recognized in polynomial time.
If a graph has a square root that is a cactus, we say that G has a cactus root. We observe that a general technique applied in several papers [1,10,11,23] is not applicable for finding cactus roots. In these papers the aim is to find some type of sparse square root and it can be shown that such a square root (if it exists) is unique or unique up to isomorphism. This uniqueness can be exploited and as such is very helpful for finding the square root. However, this is not the case for cactus roots; Fig. 1 shows a graph that has two non-isomorphic cactus roots. Instead, we prove our result by showing boundedness of treewidth.
We first analyze, in Section 3.1, the structure of squares of cactuses. This helps us to recognize vertices of the input graph G that are cut-vertices in any cactus root (if such a square root exists) and sets of compulsory and forbidden edges of any cactus root of G. In this way we can reduce, in Section 3.2, the graph G to a number of smaller instances such that G has a cactus root if and only if each of these smaller instances has a cactus root. Showing that each of the smaller instances has bounded treewidth, the aforementioned observation that we can solve the problem in polynomial time on any graph class of bounded treewidth completes the proof.
In Section 4 we focus on the SQUARE ROOT problem restricted to some classes of graphs that have a small clique number. Our motivation for doing so comes from the observation that SQUARE ROOT is readily seen to be polynomial-time solvable for graphs with clique number at most 3 (the only square roots a connected graph on n vertices with clique number 3 may have are the cycle or path on n vertices). Moreover, by identifying such classes of graphs, our results complement existing polynomial-time results for other classes of graphs with a small clique number, such as planar graphs [23] and graphs of maximum degree 6 [4]. We prove that SQUARE ROOT is polynomial-time solvable for the classes of 3-degenerate graphs and (K r , P t )-free graphs by showing that squares in these two graph classes have bounded treewidth. In Section 5 we present two tables that incorporate both new and old results and there we also discuss some directions for future work.

Preliminaries
We consider only finite undirected graphs without loops and multiple edges. We refer to the textbook of Diestel [8] for any undefined graph terminology.
We denote the vertex set of a graph G by V G and the edge set by E G . The subgraph of G induced by a subset U ⊆ V G is denoted by G[U ]. The graph G −U is the graph obtained from G after removing the vertices of U . If U = {u}, we also write G − u. Similarly, we denote the graph obtained from G after deleting a set of edges S (an edge e) by G − S (G − e respectively).
Let G be a graph. A connected component of G is a maximal connected subgraph. The distance dist G (u, v) between a pair of vertices u and v of G is the number of edges of a shortest path between them. The diameter diam(G) of G is the maximum distance between two vertices of G.
The open neighbourhood of a vertex u ∈ V G is defined as N G (u) = {v | uv ∈ E G }, and its closed neighbourhood is defined as is a clique, that is, if there is an edge between any two vertices of N G [v]. The clique number of G is the size of a largest clique of G.
If v is a pendant vertex, then we say that the unique edge incident to u is a pendant edge. For a non-negative integer d, the graph G is said to be d-degenerate if every subgraph H of G has a vertex of degree at most d.
Let {H 1 , . . . , H p } be a family of graphs. Then a graph G is called (H 1 , . . . , H p )free if G contains no induced subgraph isomorphic to a graph in {H 1 , . . . , H p }. We denote the complete graph and path on r vertices by K r and P r , respectively.
A vertex u is a cut vertex of a connected graph G with at least two vertices if G −u is disconnected. An inclusion-maximal induced subgraph of G that has no cut vertex is called a block. Recall that a connected graph G is a cactus if each edge of G is contained in at most one cycle. This implies the following well-known property.

Observation 1 Each block of a cactus with at least two vertices is either a K 2 (an edge) or a cycle.
A tree decomposition of a graph G is a pair (T, X ) where T is a tree and X = {X i | i ∈ V T } is a collection of subsets (called bags) of V G such that the following three conditions hold: The treewidth tw(G) of a graph G is the minimum width over all tree decompositions of G. We will make use of the following result of Bodlaender.

Cactus Roots
Recall that a graph H is called a cactus root of a graph G if H is a cactus and a square root of G. If H is the class of cactuses, we may denote the H-SQUARE ROOT as the following problem: We also need to define the following more general variant introduced in [ By choosing R = B = ∅ we see that CACTUS ROOT is indeed a special case of CACTUS ROOT WITH LABELS.
In Section 3.1 we analyze the structure of squares of cactuses. We use the information obtained in this way for the design of our algorithm, which we describe in Section 3.2.

A Number of Structural Observations and Lemmas
In this section we state three observations and prove seven lemmas. We will use these results, which are all structural, for the design of our O(n 4 ) time algorithm for CACTUS ROOT presented in Section 3.2.
The first observation is known and easily follows from the definition of the treewidth.

Observation 2 For a cactus G, tw(G) ≤ 2.
The second observation gives an upper bound for the treewidth of the square of a graph; it follows from the well-known fact that we can transform every tree decomposition (T, X ) of a graph G into a tree decomposition of G 2 by adding, to each bag X i of T , all the neighbours of every vertex from X i .

Observation 3 For a graph G, tw(G
Let H be a square root of a graph G. We say that H is a minimal square root of G if H 2 = G but any proper subgraph of H is not a square root of G. Note that the two cactus roots displayed in Fig. 1 are both minimal. Since any connected subgraph of a cactus is a cactus, we can make the following observation.

Observation 4 If a graph G has a cactus root, then G has a minimal cactus root.
A block of a graph G is called a leaf block if it contains at most one cut vertex of G. This leads to our first lemma.

Lemma 2 If a cactus H is a minimal square root of a graph G, then H has no leaf block that is a triangle.
Proof Suppose that a cactus H is a minimal square root of G such that a triangle with vertices x, y, z is a leaf block of H . As a leaf block contains at most one cut vertex of H by definition, we may assume that y and z are not cut vertices of H . Let H = H − yz. It is straightforward to verify that H 2 = G, contradicting the minimality of H .
Suppose that u and v are pendant vertices of a square root H of G and that u and v are adjacent to the same vertex of H − {u, v}. Then, in G, u and v are simplicial vertices and true twins. We use this observation in the proof of the following lemma.

Lemma 3 Let H be a minimal cactus root of a graph G. If G contains at least six simplicial vertices that are pairwise true twins, then at least one of these vertices is a pendant vertex of H .
Proof Let H be a minimal cactus root of a graph G that contains a set X of six simplicial vertices that are pairwise true twins. The vertices of X cannot all belong to the same block of H , because such a block would be a cycle with at least six vertices (by Observation 1) and any two vertices of this block could not be true twins of G. Hence, there is a cut vertex u of H such that there exist two vertices x, y ∈ X that are in distinct connected components of H − u. Let H be a connected component of H − u that contains x. If x is not a pendant vertex of H then, by the minimality of H and Lemma 2, there exists a vertex z ∈ V H that is adjacent to x and that is at distance 2 from u in H . Then, as every path from y to z in H contains u, we find that yz / ∈ E G . This is a contradiction since x and y are true twins of G and xz ∈ E G . We conclude that x is a pendant vertex of H .
The following definition plays a crucial role in our paper.

Definition 1
Let u be a cut vertex of a connected graph H . We say that (i) u is important if H − u has three vertices that belong to three distinct connected components of H − u and that are each at distance at least 2 from u in H ; (ii) u is essential if H − u has two vertices that belong to two distinct connected components of H − u and that are both at distance at least 2 from u in H .
Definition 1(i) immediately implies the following lemma.

Lemma 4 If u is an important cut vertex of a cactus root H of a graph G, then there
are three vertices x, y, z ∈ N G (u) such that x, y and z are at distance at least 3 from each other in G − u.
Although we have no implication in the opposite direction, we can show the following (which explains why we need the second and weaker part of Definition 1).

Lemma 5 Let G be a graph with a cactus root H . If u ∈ V G has three neighbours
x, y and z in G that are at distance at least 3 from each other in G − u, then u is an essential cut vertex of H . Moreover, at least two vertices of {x, y, z} belong to distinct connected components of H − u.
Proof Assume that G has a cactus root H . Let u ∈ V G be such that u has three neighbours x, y and z in G that are at distance at least 3 from each other in G − u. Notice that because x, y and z are at distance at least 3 from each other in G − u, these vertices are all at distance 2 from u in H .
For contradiction, assume that u is not a cut vertex of H . Then u has at most two adjacent vertices in H , since H is a cactus (see Observation 1). Then at least two vertices of {x, y, z} are adjacent to the same vertex of H (which is one of the two neighbours of u) implying that these two vertices of {x, y, z} are adjacent in G and thus in G − u; a contradiction. Hence u is a cut vertex of H . Now suppose that x, y and z are all in the same connected component H of H −u. Since H is a cactus, we find, by Observation 1, that H contains at most two vertices that are adjacent to u in H . Again, we obtain that at least two vertices of {x, y, z} are adjacent to the same vertex of H ; a contradiction. Hence, at least two vertices of {x, y, z} belong to distinct connected components of H − u. Since x, y and z are at distance 2 from u in H , this implies that u is an essential cut vertex of H .
We now show that we can recognize edges of a cactus root that are incident to an essential cut vertex. Proof Let u be an essential cut vertex of a cactus root H of a graph G. Let x ∈ N G (u). First suppose that ux ∈ E H . Let y ∈ N G (u). If uy ∈ E H , then x y ∈ E G . If uy / ∈ E H , then there exist a vertex z ∈ V H and edges uz, zy ∈ E H , as y ∈ N G (u). As zy ∈ E H , we find that zy ∈ E G . As ux, uz ∈ E H , we also deduce that xz ∈ E G . In both cases x and y are at distance at most 2 in G − u.
Now suppose that ux / ∈ E H . Then, as x ∈ N G (u), we find that x is at distance 2 from u in H . Let H be the connected component of H − u containing x. Since u is an essential cut vertex of H , H − u has another connected component H containing a vertex y at distance 2 from u in H . It remains to observe that y ∈ N G (u) and x and y are at distance 3 in G − u.
The next lemma is used to recognize vertices adjacent to an essential cut vertex that belong to the same block of a minimal cactus root. Proof Let x, y ∈ N H (u). First suppose that x and y are in distinct blocks of H . Then x and y are readily seen to be in distinct connected components of G . Now suppose that x and y are in the same block C of H . If x y ∈ E G then x and y are in the same connected component of G . Suppose x y / ∈ E G . Then C is a cycle by Observation 1. If C is not a triangle, then C has a unique (x, y)-path in H (avoiding u) of length at least 2. This path is an (x, y)-path in G as well. Hence x and y are in the same connected component of G . Suppose that C is a triangle.Then x y ∈ E H . As H is a minimal cactus root, x or y has at least one neighbour z = u in H due to Lemma 2. Assume without loss of generality that z is a neighbour of x. Then the edges x y, xz ∈ E H imply that zy ∈ E G . We establish that xzy is an (x, y)-path in G , that is, also in this case x and y are in the same connected component of G .

The Algorithm
In this section we use the structural results from the previous section to obtain a polynomial-time algorithm for CACTUS ROOT. The main idea is to reduce a given instance of CACTUS ROOT to a set of smaller instances of CACTUS ROOT WITH LABELS, each having bounded treewidth. We therefore need the following lemma which show, together with Lemma 1 and Observations 2 and 3, that we are done if we manage to achieve this goal.

Lemma 9 CACTUS ROOT WITH LABELS can be solved in time f (t) · n for n-vertex graphs of treewidth at most t.
Proof It is not difficult to construct a dynamic programming algorithm for the problem (for details see [4] in which such an algorithm is sketched for the general SQUARE ROOT problem). For simplicity we give a non-constructive proof based on Courcelle's theorem [6]. By this theorem, it suffices to show that the existence of a cactus root can be expressed in monadic second-order logic.
Let (G, R, B) be an instance of CACTUS ROOT WITH LABELS. We observe that the existence of a cactus H such that G = H 2 , R ⊆ E H and B∩E H = ∅ is equivalent to the existence of a subset X ⊆ E G such that the following four properties hold: (i) R ⊆ X and B ∩ X = ∅; (ii) for every uv ∈ E G , uv ∈ X or there exists a vertex w such that uw, wv ∈ X ; (iii) for every two distinct edges uw, vw ∈ X , uv ∈ E G ; (iv) for every uv ∈ X and for every two (u, v)-paths P 1 and P 2 in G such that E P 1 , E P 2 ⊆ X \ {uv}, it holds that P 1 = P 2 .
Each of these properties can be expressed in monadic second-order logic. In particular, with respect to property (iv), expressing that a subgraph P of G is a (u, v)-path in G can be done in monadic second-order logic in a standard way (see, for example, [7]). Hence the lemma follows.
Now we are ready to prove the main result.

Theorem 1 CACTUS ROOT can be solved in time O(n 4 ) for n-vertex graphs.
Proof We first give an overview of our algorithm. As we can consider each connected component separately, we may assume without loss of generality that the input graph G is connected. First, we use Lemma 3 to recognize sets of pendant vertices in a (potential) cactus root adjacent to the same vertex that have size at least 7. For each of these sets, we show that it is safe to delete some vertices without changing the answer for the considered instance. After performing this step, we obtain a graph G such that in any cactus root of G each vertex is adjacent to at most six pendants. Further, we use Lemmas 4 and 5 to construct a set U of essential cut vertices in a (potential) cactus root such that U contains all important cut vertices. Next, we apply Lemma 6 to recognize which edges incident to the vertices of U are in any cactus root and which edges are not included in any cactus root. We label them red and blue respectively and obtain an instance of CACTUS ROOT WITH LABELS. Now we can use Lemmas 7 and 8 to determine for each u ∈ U , the partition of the set of vertices of G − u into the sets of vertices of the connected components of H − u, where H is a cactus root of G . This allows us to split G via the vertices of U as shown in Fig. 2. Due to the presence of labelled edges incident to the vertices of U , we obtain an equivalent instance. Finally, we observe that the obtained graph has bounded treewidth using Observations 2 and 3, so we can use Lemmas 1 and 9 to solve the problem, as we pointed out already. Now we formally explain the details of our algorithm. Let G be a connected graph. First, we preprocess G using Lemma 3 to reduce the number of pendant vertices adjacent to the same vertex in a (potential) cactus root of G. To do so, we exhaustively apply the following rule.

Pendants Reduction
If G has a set X of simplicial true twins of size at least 7, then delete an arbitrary u ∈ X from G.
The following claim shows that this rule is safe.

Claim A If G = G − u is obtained from G by the application of Pendant reduction, then G has a cactus root if and only if G has a cactus root.
We prove Claim A as follows. Suppose that H is a minimal cactus root of G. By Lemma 3, H has a pendant vertex u ∈ X . It is easy to verify that H = H − u is a cactus root of G . Assume now that H is a minimal cactus root of G . By Lemma 3, H has a pendant vertex w ∈ X \ {u}, since the vertices of X \ {u} are simplicial true twins of G and |X \ {u}| ≥ 6. Let v be the unique neighbour of w in H . We construct H from H by adding u and making it adjacent to v. It is readily seen that H is a cactus root of G. This completes the proof of Claim A.
For simplicity, we call the graph obtained by exhaustive application of the pendants rule G again. The following property is important for us.

Claim B Every cactus root of G has at most six pendant vertices adjacent to the same vertex.
Now we construct an instance of CACTUS ROOT WITH LABELS together with a set U of cut vertices of a (potential) cactus root.
Labelling Set U = ∅, R = ∅ and B = ∅. For each u ∈ V G such that there are three distinct vertices x, y, z ∈ N G (u) that are at distance at least 3 from each other in G − u do the following: Lemmas 4-6 immediately imply the following claim. (ii) for each x ∈ R(u), put y ∈ B(y) in the same set with x if x y ∈ E G , (iii) if at least one of the following holds, then return a no-answer and stop:

Claim C If G has a cactus root, then Labelling does not stop in Step (v), and if H is a minimal cactus root of G, then R ⊆ E H and B ∩ E H = ∅. Moreover, every vertex u ∈ U is an essential cut vertex of any cactus root of G, and any important cut vertex u of any cactus root of G is contained in U .
• P(u) is not a partition of N G (u), • there is a set of P(u) with at least three vertices of R(u), • there is a vertex of B(u) that is not in a set of P(u) with a vertex of R(u), • there are distinct S, S ∈ P(u) such that for some x ∈ S and y ∈ S , x y ∈ R, • there are distinct S, S ∈ P(u) such that for some x ∈ S and y ∈ S , x y ∈ E G but ux / ∈ R or uy / ∈ R, • there are distinct S, S ∈ P(u) such that for some x ∈ S and y ∈ S , x y / ∈ E G but ux ∈ R and uy ∈ R, • the graph G − E G[R(u)] − u has a path connecting vertices of distinct sets of P(u).
By Lemmas 7, 8 and Claim C, we have the following. Let G 1 , . . . , G r be the connected components of the obtained graph. For i ∈ {1, . . . , r }, let R i = R ∩ E G i and B i = B ∩ E G i . By Claims B and D, we establish the following crucial claim.

is a yes-instance, then G i has a cactus root H with R i ⊆ E H and B i ∩ E H = ∅ such that every cut vertex of H belongs to at most eight blocks and to at most two blocks not being a K 2 .
By Claim E, if G has a cactus root, then (G i ) ≤ 10 for i ∈ {1, . . . , k}. By Observations 2 and 3, we obtain that tw(G i ) ≤ 32 in this case. We use Lemma 1 to check whether this holds for each i ∈ {1, . . . , r }. If the algorithm reports that tw(G i ) ≥ 33 for some i ∈ {1, . . . , r }, then we return a no-answer and stop. Otherwise, we solve CACTUS ROOT WITH LABELS for each instance (G i , R i , B i ) using Lemma 9 for i ∈ {1, . . . , r }.
It remains to evaluate the running time of our algorithm. We can find all simplicial vertices and sort them into the equivalence classes with the true twin

Squares of Low Clique Number
We first consider the class of 3-degenerate graphs. We will show that 3-degenerate squares have bounded treewidth. In order to do this we need the following two known lemmas. We call the tree decomposition (T, X ) of Lemma 11 the H -tree decomposition of G and are now ready to prove the following lemma.

Lemma 12 If G is a 3-degenerate graph with a square root, then tw(G) ≤ 3.
Proof Without loss of generality we assume that G is connected and has at least one edge. Let H be a square root of G. Let C be the set of cut vertices of H , and let B be the set of blocks of H . We construct the H -tree decomposition (T, X ) of G (cf. Lemma 11). We will show that (T, X ) has width at most 3.
We start with two useful observations. If v ∈ V H , then N H [v] is a clique in G. Because G is 3-degenerate, this means that (H ) ≤ 3. For the same reason H contains no cycles of length at least 5 as a subgraph, because a square of a cycle of length at least 5 has minimum degree 4.
We claim that X Q has size at most 4 for every Q ∈ B. In order to see this, let Q be a block of H , and let u ∈ V Q . Suppose that Q has a vertex v at distance at least 3 from u. Because Q is 2-connected, Q has two internally vertex disjoint paths that join u and v and, therefore, Q (and thus H ) contains a cycle of length at least 6 which, as we saw, is not possible. We find that each vertex v ∈ V Q is at distance at most 2 from u. Hence, u is adjacent to all other vertices of Q in G. By the same reasoning any two vertices in Q are of distance at most 2 of each other. Hence, Q is a clique in G. As G is 3-degenerate, this means that Q is a clique in G of size at most 4. Consequently, X Q , has size at most 4. As (H ) ≤ 3, we find that X u has size at most 4 for every cut vertex u of H .
Lemma 12, combined with Lemmas 1 and 10, leads to the following result.

Theorem 2 SQUARE ROOT can be solved in O(n) time for 3-degenerate graphs on n vertices.
Proof Let G be an 3-degenerate graph on n vertices. By Lemma 1 we can check in O(n) time whether tw(G) ≤ 3. If tw(G) > 3, then G has no square root by Lemma 12. If not we solve SQUARE ROOT in O(n) time by using Lemma 10.
Remark We cannot claim any upper bound for the treewidth of 4-degenerate graphs with a square root. In order to see this, take a wall (see Fig. 3) and subdivide each edge three times, that is, replace each edge uv by a path uabcv where a, b, c are three new vertices. This gives us a graph H , such that H 2 is 4-degenerate. In order to see the latter, note that every "b-type" vertex has degree 4 in H 2 and that after removing all degree-4 vertices, we obtain a disjoint number of copies of K 4 , each of which is 4-degenerate. A wall of height h has treewidth (h) (see, for example, [8]). As subdividing an edge and adding edges does not decrease the treewidth of a graph, this means that the graph H 2 can have arbitrarily large treewidth.
We now consider (K r , P t )-free graphs (that is, graphs with no induced path P t and no complete subgraph K r ). We let K s,s denote the complete bipartite graph in which both partition classes have s vertices. We need a result of Atminas, Lozin and Razgon.

Lemma 13 ([2]) For any two integers s and t, there exists an integer b(s, t) such that any graph of treewidth at least b(s, t) contains the path P t as an induced subgraph or the complete bipartite graph K s,s as a (not necessarily induced) subgraph.
Lemma 13, together with Ramsey's Theorem, enables us to prove the following lemma.

Lemma 14
For every two integers r, t ≥ 1, the class of (K r , P t )-free graphs with a square root has bounded treewidth.
Proof Let r, t ≥ 1. For contradiction, assume that the class of (K r , P t )-free graphs with a square root has unbounded treewidth. Then there exists a (K r , P t )-free graph G with a square root such that G has treewidth at least b(s, t), where b(s, t) is the constant in Lemma 13 for a sufficiently large integer s. Then, by Lemma 13, we find that G contains a subgraph F isomorphic to K s,s . As we have chosen the fixed integer s to be large enough, Ramsey's Theorem implies, together with the K r -freeness of G, that F is in fact an induced subgraph of G. This means that no two vertices in the same bipartition class of F may have a common neighbour in H . In particular, this implies that for each u ∈ V F , H contains at most one edge of F incident to u (as otherwise u would be a common neighbour of two vertices of F in H ).
Let A and B be the bipartition classes of F. Let u ∈ A. As s is sufficiently large, there exist at least r vertices v 1 , . . . , v r in B that are not adjacent to u in H . Then there must exist r distinct vertices w 1 , . . . , w r with edges uw i and w i v i for i = 1, . . . , r (to enforce the edges uv i in G for i = 1, . . . , r ). As the vertices w 1 , . . . , w q all have common neighbour u in H , they form a clique of size r in G, a contradiction with the K r -freeness of G.
Using a similar reasoning as before, we find that Lemma 14, combined with Lemmas 1 and 10, leads to the following result.
Theorem 3 For every two integers r, t ≥ 1, SQUARE ROOT can be solved in time O(n) for (K r , P t )-free graphs on n vertices.

Conclusions
We proved that the problem of testing whether a graph has a cactus root is O(n 4 )-time solvable. In fact, our algorithm can be modified to find a cactus root in the same time (if it exists). Every cactus is outerplanar, and recently Golovach et al. [12] proved that squares of outerplanar graphs can be recognized in polynomial time. Determining the complexity of H-SQUARE ROOT when H is the class of planar graphs is still a wide open problem. Golovach et al. [12] also proved that squares of graphs of pathwidth at most 2 can be recognized in polynomial time. We recall that every cactus has treewidth at most 2. This leads to the open problem of determining the complexity of H-SQUARE ROOT when H is the class of graphs of treewidth at most 2. We also Graphs of girth at least 4 [11] NP-complete Split graphs [18] NP-complete Chordal graphs [18] NP-complete The result for 3-sun-free split graphs has been extended to a number of other subclasses of split graphs in [20] recall that a cactus is a connected graph, in which each block is either a cycle or an edge. This leads to the following (known) generalization: a cactus block graph is a connected graph, in which each block is a cycle or a complete graph. Recently,

NP-complete
Note that the row for planar graphs is absorbed by the row directly below it. Results marked with a * are results shown in this paper Ducoffe [9] gave a polynomial-time algorithm for the problem of recognizing squares of cactus block graphs. In Table 1 we summarize all known results on H-SQUARE ROOT.
We observed that SQUARE ROOT is polynomial-time solvable for graphs with clique number 3 (or equivalently, K 4 -free graphs) and proved the same result for 3degenerate graphs and (K r , P t )-free graphs for every r, t ≥ 1. We summarize the known results for SQUARE ROOT in Table 2. As can be seen from this table, the computational complexity of SQUARE ROOT is unknown for several well-known graph classes. In particular, we recall the open problems of Milanič and Schaudt [25], who asked about the complexity of SQUARE ROOT restricted to split graphs and cographs. We also do not know the computational complexity of SQUARE ROOT for K r -free graphs for r ≥ 5 and for graphs of maximum degree at most s for s ≥ 7.