Vertex links and the Grushko decomposition

We develop an algorithm of polynomial time complexity to construct the Grushko decomposition of fundamental groups of graphs of free groups with cyclic edge groups. Our methods rely on analysing vertex links of certain CAT(0) square complexes naturally associated with a special class of the above groups. Our main result transforms a one-ended CAT(0) square complex of the above type to one whose vertex links satisfy a strong connectivity condition, as first studied by Brady and Meier.


Introduction
The Grushko decomposition theorem [Gru40] states that a finitely generated group is a free product of finitely many freely indecomposable non-free groups and a finite rank free group.This decomposition is unique in the sense that the freely indecomposable groups appearing in this decomposition are unique up to reordering and conjugation, and the rank of the free group is invariant.
Given a finitely presented group, there is no algorithm in general to compute its Grushko decomposition.Even when algorithms do exist, they are often not tractable.In this article, we develop an algorithm, with polynomial time complexity, to compute the Grushko decomposition of fundamental groups of graphs of free groups with cyclic edge groups (see Theorem F).
Our algorithm is obtained as a consequence of Corollary C, which gives an algorithm to obtain the Grushko decomposition of fundamental groups of compact nonpositively curved square complexes that we call tubular graphs of graphs.A tubular graph of graphs (see Definition 2.8 for the precise definition) is a square complex obtained by attaching finitely many tubes (a tube is the Cartesian product of a circle and the unit interval) to a finite collection of finite graphs.Tubular graphs of graphs are thus nonpositively curved VH-complexes (in the sense of Wise [Wis96]) in which vertical hyperplanes are homeomorphic to circles (see Section 2).
In [Sta99], Stallings built on work by Whitehead [Whi36] and developed an algorithm that takes a free group and finitely many cyclic subgroups as input and decides whether or not the free group splits freely relative to the cyclic subgroups.We use the machinery of tubular graphs of graphs in this article to develop an alternative algorithm.
In fact, we also obtain an analogue for tubular graphs of graphs of a result by Jaco [Jac69] in 3-manifold theory which states that if the fundamental group of a 3-manifold splits as a free product, then each free factor is itself the fundamental group of a 3-manifold.
Our approach is geometric and in fact we are more interested in nonpositively curved square complexes than groups.We show how to construct the Grushko Date: March 16, 2022.
decomposition by cutting along contractible subspaces of tubular graphs of graphs which induce free splittings.
Crucial to our methods is the following key result by Brady and Meier: Theorem 1.1 ( [BM01]).Let X be a finite connected nonpositively curved cube complex.Suppose that (BM1) for each vertex v ∈ X, the link of v is connected and (BM2) for each vertex v ∈ X and each simplex σ in link(v), link(v)\σ is (non-empty and) connected.
Then X is one-ended.
We say that a cube complex is Brady-Meier if it satisfies the conditions (BM1) and (BM2) above.Note that the Brady-Meier conditions are local and hence preserved by covering maps.The converse of Theorem 1.1 is not true in general.The main result of the article gives a geometric/combinatorial procedure that modifies a given tubular graph of graphs to a homotopy equivalent tubular graph of graphs which is Brady-Meier if and only if the fundamental group is one-ended: Theorem A (Theorem 5.3).There is an algorithm of polynomial time complexity which takes a tubular graph of graphs as input and returns a homotopy equivalent tubular graph of graphs which is either a Brady-Meier complex or contains a locally disconnecting vertex which splits the fundamental group as a free product.
For this and the corollaries below, the running times of the algorithms are polynomial in the number of squares of the input square complex.A major application of the above theorem is in the development of an algorithm to obtain the JSJ decomposition of one-ended hyperbolic fundamental groups of tubular graphs of graphs [MS20].The main point is that one can work with a Brady-Meier tubular graph of graphs (obtained in polynomial time) when the fundamental group is one-ended, thanks to Theorem A.
The key step in the construction of our algorithm involves a simplification of the input tubular graph of graphs by 'opening-up' at a vertex which does not satisfy (BM2).This opening-up keeps the number of squares in the complex constant, while simplifying certain vertex links.We call such an opening procedure as an SL-move ('SL' stands for simplified link).We thus obtain a partial converse to Theorem 1.1: Corollary B. A tubular graph of graphs has a one-ended universal cover if and only if it can be simplified in finitely many SL-moves to a Brady-Meier tubular graph of graphs with isomorphic fundamental group.
We also obtain the Grushko decomposition of these groups using Theorem A. In fact, we obtain a stronger result: Corollary C (Corollary 5.4).There is an algorithm of polynomial time complexity which takes as input a tubular graph of graphs and returns a homotopy equivalent tubular graph of graphs obtained by gluing together certain vertices of a finite collection of Brady-Meier tubular graphs of graphs and finite graphs.Further, the free product decomposition induced by cutting along the glued vertices is the Grushko decomposition of the fundamental group of the input tubular graph of graphs.
We point out that our proof neither uses Stallings' theorem on ends of finitely generated groups nor assumes the existence of a Grushko decomposition.In fact, our procedure yields a new proof of Stallings' theorem for fundamental groups of tubular graphs of graphs as well as the existence of a Grushko decomposition for these groups.
The analogue of Jaco's result immediately follows: Corollary D (Corollary 5.6).Let X be a tubular graph of graphs with fundamental group G.If G = A * B, then there exist tubular graphs of graphs X 1 and X 2 such that A and B are fundamental groups of X 1 and X 2 respectively.Moreover, X 1 and X 2 can be so chosen such that the total number of squares in X 1 and X 2 is bounded by the number of squares in X.
The Grushko decomposition may be found algorithmically in other situations.Jaco, Letscher and Rubinstein [JLR02] gave an algorithm of polynomial time complexity to compute the prime decomposition of a 3-manifold from a triangulation.Gerasimov [Ger99] showed that the Grushko decomposition can be computed for hyperbolic groups.But there is no known bound on the complexity of his algorithm.Dahmani and Groves [DG08] extended Gerasimov's ideas to groups which are hyperbolic relative to abelian subgroups.Diao and Feighn [DF05] gave an algorithm for graphs of free groups.Their algorithm relies on certain simplifications of a given graph of free groups which depend on finding Gersten representatives of the incident edge groups in each vertex group, which is algorithmic.More recently, Touikan [Tou18] presented an important algorithm which returns the Grushko decomposition of finitely presented groups with solvable word problem and no 2-torsion.However, the time complexity of his algorithm is not known.
We note that our algorithm is explicit and neither uses the Rips machine nor requires solutions of equations in free groups, as some of the above algorithms do.
We mention another application of our algorithm, before stating our result for general graphs of free groups with cyclic edge groups.As defined by Stallings in [Sta99], a finite set of words W of a finite rank free group F is separable if there exists a nontrivial free splitting of F such that each word of W conjugates into a free factor.
Stallings obtained an algorithm to detect separability in [Sta99].In a related result, Roig, Ventura and Weil [RVW07] obtained a polynomial time algorithm to solve the Whitehead minimization problem and therefore the primitivity problem.We give an alternate version of Stallings' algorithm using Theorem A: Corollary E (Corollary 6.2).There exists an algorithm of polynomial time complexity that takes a finite set of words in a finite rank free group as input and decides whether it is separable.
Stallings obtains his algorithm by constructing a Whitehead graph for the given set of words in a chosen basis.He then uses a Whitehead automorphism to modify the basis whenever there is a cut vertex in the Whitehead graph to reduce the total length of the given set of words.We first give a new proof of Whitehead's cut vertex theorem (Proposition 6.4).We then obtain our algorithm by first constructing the tubular graph of graphs associated to a 'double' of the free group with the given set of words.We then apply the algorithm of Theorem A.
By combining a result of Wilton [Wil12] (see Theorem 6.7) with Corollary C, we obtain the advertised result: Theorem F (Theorem 7.1).There exists an algorithm of polynomial time complexity which takes a graph of free groups with cyclic edge groups as input and returns as output the Grushko decomposition of its fundamental group.
The running time of the algorithm is polynomial in the sum of the lengths of the words induced by the generators of the edge groups in the respective vertex groups.
Acknowledgements.I thank my advisors Frédéric Haglund and Thomas Delzant for suggesting the problem and for several important discussions.Part of this work was done when I was visiting IRMA, Strasbourg.This work was supported by a French public grant for research, as part of the Investissement d'avenir project, reference ANR-11-LABX-0056-LMH, LabEx LMH.I am grateful to the referee for their suggestions to improve the paper.Definition 2.1.A square complex is a two dimensional CW complex in which each 2-cell is attached to a combinatorial loop of length 4 and is isometric to the standard Euclidean unit square All our square complexes will be locally finite.
Definition 2.2 (Vertex links).Let v ∈ X be a vertex of a square complex.The link of v, denoted by link(v) is a graph whose vertex set is the set {e | e is a half-edge incident to v}.The number of edges between two vertices e, f is the number of squares of X in which e, f are adjacent half-edges.Definition 2.3.A square complex is nonpositively curved if the length of a closed path in the link of any of its vertices is at least four.
By a result of Gromov [Gro87], a simply connected nonpositively curved square complex is CAT(0) in the metric sense.

Definition 2.4 ([Sag95]
).Let X be a square complex.A mid-edge of a square s in X is an edge (after subdivision of s) running through the center of s and parallel to two of the edges of s.Declare two edges e and f to be equivalent if there exists a sequence e = e 1 , • • • , e n = f of edges such that e i and e i+1 are opposite edges of some square of X.Given an equivalence class [e] of edges, the hyperplane dual to e, denoted by h e , is the collection of mid-edges which intersect edges in [e].

Definition 2.5 ([Wis96]
).A VH-complex is a square complex in which every 1-cell is labelled as either vertical or horizontal in such a way that each 2-cell is attached to a loop which alternates between horizontal and vertical 1-cells.
The labelling of the edges of a VH-complex as horizontal and vertical induces a labelling of the vertices in the link of any vertex as horizontal and vertical, thus making the link a bipartite graph.Similarly, the hyperplanes of a VH complex are also labelled as vertical and horizontal, with a vertical hyperplane being dual to an equivalence class of horizontal edges and a horizontal hyperplane being dual to an equivalence class of vertical edges.
Remark 2.6.Since the link of any vertex of a VH-complex is bipartite, the length of a closed path is even.Thus a VH-complex is nonpositively curved if there exists no bigon in any vertex link.
2.2.Graphs of spaces.Graphs of groups are the basic objects of study in Bass-Serre theory [Ser80].It was studied from a topological perspective in [SW79] by looking at graphs of spaces instead of graphs of groups.We will adopt this point of view.
Definition 2.7.By a graph of spaces, we mean the following data: Γ is a connected graph, called the underlying graph.For each vertex s (edge a) of Γ, X s (X a ) is a topological space.Further, whenever a is incident to s, ∂ a,s : X a → X s is a π 1 -injective continuous map.The geometric realisation of the above graph of spaces is the space X = ( s∈Γ (0) X s a∈Γ (1) X a × [0, 1])/ ∼, where (x, 0) and (x, 1) are identified respectively with ∂ a,s (x) and ∂ a,s (x).Here, s and s are the two endpoints of a.
Note that the universal cover of X has the structure of a tree of spaces, a graph of spaces whose underlying graph is the Bass-Serre tree of the associated graph of groups structure of X [SW79].

Tubular graphs of graphs.
Definition 2.8.A tubular graph of graphs is a finite graph of spaces in which each vertex space is a finite connected simplicial graph and each edge space is a simplicial graph homeomorphic to a circle.Further, the attaching maps are simplicial immersions.We will always assume that the underlying graph is connected.
We note that no vertex graph is a tree, as a consequence of the definition.We also remark that asking for each vertex graph to be simplicial is not a serious restriction as every one dimensional CW complex is a simplicial graph after subdivision.
Remark 2.9.Tubular graphs of graphs are topological versions of certain graphs of free groups with cyclic edge groups (see Section 7 for a definition).We note that any graph of free groups with cyclic edge groups in which the underlying graph is a tree can be realised topologically as a tubular graph of graphs.If the underlying graph contains a loop such that the generator of the edge group is attached to words of different lengths in the incident vertex group, then such a graph of free groups with cyclic edge groups cannot be realised as a tubular graph of graphs.In particular, this rules out non-Euclidean Baumslag-Solitar groups.
We also have Proposition 2.10 ( [Wis96]).The geometric realisation of a tubular graph of graphs is a finite (hence compact), connected nonpositively curved VH-complex whose vertical hyperplanes are circles.
Convention.Throughout this text, we will use the same notation for a graph of graphs and the VH-complex which is its geometric realisation.X will denote a tubular graph of graphs with underlying graph Γ X .Let s ∈ Γ X be a vertex.Then X s will denote the vertex graph at s and if a is an edge of Γ X , we will denote the edge graph at a by X a .Thus, every edge of any vertex graph X s will be a vertical edge in the VH-complex X while horizontal edges in X are the edges of the form {v} × [0, 1], for vertices v in the edge graphs X a .
Definition 2.11 (Thickness).For an edge e in X, the thickness of e is the number of squares of X which contain e.
Observe that a horizontal edge of X always has thickness equal to two.Definition 2.12.Let X s be a vertex graph of a tubular graph of graphs X.We say that X s (and hence X) has a hanging tree if X s is a wedge of two subgraphs A and B such that one of them, say A, is a tree.Here, A is called a hanging (sub)tree of X s .
Remark 2.13.Since the attaching maps of edge graphs are immersions, an edge in a hanging tree of X has thickness zero.
We thus have that Lemma 2.14.A tubular graph of graphs is homotopy equivalent to a tubular graph of graphs with no hanging trees.Definition 2.15.An edge e in X s is a rudimentary edge if it is of thickness one and moreover X s is a circle.Lemma 2.16.A tubular graph of graphs is homotopically equivalent to a tubular graph of graphs with no rudimentary edges.
Proof.Let e be a rudimentary graph in a vertex graph X s of a tubular graph of graphs X.Since X s is a circle and attaching maps of edge graphs to X s are graph immersions, there exists exactly one edge a incident to s in the underlying graph Γ X and the attaching map from X a to X s is a graph isomorphism (see Figure 1).Thus X is homotopic to X obtained by removing X a and the open tube containing X a .Γ X is the graph obtained from Γ X by collapsing a = (s, s ) to s .Repeating this procedure at each rudimentary edge gives the result.
2.4.Ends.The theory of ends of a topological space was first studied by Freudenthal [Fre31].The notion we require is that of "one-endedness".We will use the following definition due to Specker (see [Spe49] or [Ray60]).
Definition 2.17.A locally finite CW complex X is one-ended if for every compact set K, X \ K has exactly one unbounded component.
It is a well-known fact that being one-ended is a quasi-isometry invariant (see Proposition I.8.29 of [BH99], for instance).Then by an application of the Švarc-Milnor Lemma (see Proposition I.8.19 of [BH99]), for instance), we have the following definition of one-endedness of a finitely presented group.
Proposition 2.18.Let G be a finitely presented group and X be a finite connected CW complex such that G ∼ = π 1 (X).G is one-ended if and only if X is one-ended.

Not one-ended
In this section, we will collect a few results that help determine when the fundamental group of a tubular graph of graphs is not one-ended.Definition 3.1.Let Z be a CW complex and v ∈ Z be a vertex.Let ṽ denote a lift of v in the universal cover Z of Z.The star of v, denoted by star(v), is the smallest subcomplex of Z which contains all cells σ such that ṽ ∈ σ.The open star of v, denoted by s tar(v), is the interior of star(v).
We first recall a classical result due to Hopf: Hop44]).Let G be a torsion-free finitely generated group such that either (1) G = H * K is a nontrivial free splitting of G, or (2) G = H * 1 is an HNN extension of a finitely generated group H over its trivial subgroup.Then G is not one-ended.
We remark that the two conditions above are cases of an edge of groups with trivial edge group.We make a distinction between them because of the following standard lemma.
Lemma 3.3.Let Z be a connected CW complex.Let c ∈ Z be a vertex.Suppose that either (1) Z = Z 1 ∨ {c} Z 2 , with neither Z 1 nor Z 2 simply connected, or (2) star(c) \ {c} is not connected, but Z \ {c} is connected.
Then Z is not one-ended.
Proposition 3.4.Let X be a tubular graph of graphs with no hanging trees.Suppose there exists an edge of thickness zero.Then X is not one-ended.
Proof.Since all horizontal edges have thickness two, an edge of thickness zero has to be vertical.Let e in X s be such an edge with midpoint c.Subdivide e so that c is a vertex of X.Either X \ {c} is connected, or X = X 1 ∨ c X 2 is a wedge of two subcomplexes.Let X s = A ∨ c B be the induced decomposition of X s .Since e is not in a hanging tree, neither A nor B is a tree.Thus, X 1 and X 2 are not simply connected (as π 1 (A) → π 1 (X 1 ) and π 1 (B) → π 1 (X 2 ) in the graph of groups setup [Ser80]).Lemma 3.3 then gives the result.
Proposition 3.5.Let X be a tubular graph of graphs with no hanging trees and no rudimentary edges.Suppose there exists an edge of thickness one.Then X is not one-ended.
Proof.Let e be an edge in X s → X of thickness one and s be the lone square containing e.We will show that X is homotopic to a wedge of two non-simply connected square complexes.Note that X is homotopic to a complex obtained by removing the open square s and the open edge e (Figure 2).Removing s decreases the thickness of a horizontal edge f adjacent to e.We remove the only square that contains f , which in turn creates another horizontal edge of thickness one.We continue removing until we end up with a horizontal edge f (adjacent to e, see Figure 2) of thickness zero.
Removing squares containing thickness-one edges.
Call the resulting subcomplex as X .Either the midpoint of f does not disconnect X , or X is a wedge of two subcomplexes X 1 and X 2 , say (Figure 2).Note that X 1 is not simply connected as X had neither hanging trees nor rudimentary edges.Also X 2 is not simply connected as X 2 is a subcomplex of X which is not simply connected.By Lemma 3.3, X is not one-ended.
Proposition 3.6.Suppose that every edge of X has thickness at least two.If X is one-ended, then the link of every vertex of X is connected.
We will need the following result.
Lemma 3.7.Let Z be a compact, connected nonpositively curved square complex which has at least one edge.If each edge of Z is contained in at least two squares, then π 1 (Z) is infinite.
Proof.Let e be an edge of Z .The hyperplane h e dual to e is a finite connected graph in which every vertex is of valence at least two, by the hypothesis on Z .This implies that π 1 (h e ) is a free group of positive rank.Any lift of h e embeds as a hyperplane in Z, since Z is CAT(0) (Theorem 4.10 of [Sag95]).This implies that π 1 (h e ) → π 1 (Z).Hence the result.
Proof of Proposition 3.6.Let u ∈ X s be a vertex whose link is not connected.This implies that star(u) \ {u} is not connected.The result then follows from Lemma 3.3.Indeed, if X = X 1 ∨ u X 2 , then X i is not simply connected by Lemma 3.7.

The second Brady-Meier criterion
In this section, we will assume that each edge of X has thickness at least two and every vertex link is connected, but X does not satisfy the second Brady-Meier criterion (BM2).We will explain how to simplify X in this case by defining an opening of the complex at a vertex whose link does not satisfy (BM2).Fix one such vertex u ∈ X s ⊂ X.
A vertex of link(u) is vertical (horizontal) if it is a vertical (horizontal) half-edge incident to u in X. Observe that the horizontal vertices have valence exactly two.Lemma 4.1.X does not satisfy (BM2) at u if and only if a vertical vertex of link(u) disconnects link(u).
Proof.One direction is clear.For the converse, there are two cases to consider: either a horizontal vertex h or an edge e of link(u) disconnects link(u).
x 1k1 x 21 x 2k2 x n1 x nkn e x 1k1 x 21 x 2k2 x n1 x nkn e 2 e 1 e n f 11 In the first case, let v 1 and v 2 be the two vertical vertices adjacent to h.Let C be the component of link(u) \ {h} that contains v 1 .Let x = v 1 ∈ C be a vertex.Such a vertex exists as every edge of X has thickness at least two.Then any path in link(u) from x to v 2 meets h, and hence meets v 1 .Thus v 1 disconnects link(u).In the second case, since horizontal vertices have valence two, it is easy to see that the unique vertical vertex incident on e disconnects link(u).
The opening procedure.Throughout, we will denote an edge incident to u and the corresponding vertex in link(u) by the same notation.Let e be a vertical edge incident to u which disconnects link(u).Let C 1 , • • • , C n denote the maximal connected subgraphs of link(u) \ e (Figure 3), where maximality is by inclusion.We will denote by f i1 , • • • , f iki the vertical vertices in C i so that the vertical edges f i1 , • • • , f iki incident on u belong to star(u, X s ) (Figure 4).Let x ij denote the other endpoint of f ij .We will now explain how to open star(u, X s ): Definition 4.2.The opening of star(u, X s ) along e is a tree T u (Figure 4) defined as follows: There is one 'primary' vertex v out of which emit n edges e 1 , • • • , e n , one for each C i .For each i, we label the other endpoint of e i as u i .From each u i , we have k i edges to the vertices x i1 , • • • , x iki (compare with star(u, X s )).We label these edges as f i1 , • • • , f iki .The opened-up graph of X s along e is a graph X s obtained by replacing s tar(u, X s ) in X s by T u , with the obvious identifications.Clearly, X s is connected, X s \ s tar(u, X s ) → X s and T u → X s .There is a natural surjective map from X s to X s which sends each e i in T u to e.Note that the graphs X s and X s are homotopy equivalent.
Construction.We now construct a new tubular graph of graphs X with the same underlying graph Γ X as X and the only change is that X s replaces X s .An attaching map of an edge graph is unchanged if u is not in the image, as X s \ s tar(u, X s ) embeds in X s .If u is in the image, we do the obvious modification (see Figure 5 for an illustration).
Notation.The tubular graph of graphs X is called an SL-complex (simplified link complex) of X, simplified link in the sense that the vertex u has been replaced by u 1 , • • • , u n where for each i, link(u i ) is simpler than link(u).
There exists a natural map from X to X. Further, Proposition 4.3.The tubular graphs of graphs X and X are homotopy equivalent.
Since the number of edges of X s is strictly greater than the number of edges of X s , we have Lemma 4.4.X is not isomorphic to X as square complexes.
Lemma 4.5.Every edge of X belongs to at least one square and the number of squares in X is the same as the number of squares in X.
Proof.The number of squares in X is equal to the total number of edges in the cyclic edge graphs, which is equal to the number of squares of X.
If a vertical edge does not belong to T u , then since the attaching maps are unchanged from X, the vertical edge belongs to at least two squares.Similarly, each f ij belongs to at least two squares.The edge e i belongs to a square if and only if a pair of adjacent edges y λ1 , y λ2 in some edge graph is mapped to a pair e, f ij .Such a pair exists as there is an edge between e and f ij in link(u).
Remark 4.6.It is possible that an edge e i incident to a u i in T u is of thickness one in X .However, e i cannot be rudimentary as X s is not a circle.In that case, by Proposition 3.5, X is not one-ended.

The Algorithm
Definition 5.1.A tubular graph of graphs is wedge-like if (1) it has no hanging trees or rudimentary edges, and (2) either there exists a vertex whose link is not connected or there exists an edge of thickness one.
Remark 5.2.By Proposition 3.4, Proposition 3.5 and Proposition 3.6, the fundamental group of a wedge-like tubular graph of graphs is not one-ended.

Theorem 5.3 (Main Theorem; Theorem A).
There is an explicit algorithm of polynomial time complexity that takes a tubular graph of graphs as input and returns a homotopy equivalent tubular graph of graphs which is either Brady-Meier, or is a point, or is wedge-like.
Proof.We will prove the theorem by constructing the algorithm.Let X = X 0 be the input tubular graph of graphs.Let k ∈ N ∪ {0}.
Step Step 7 Replace X k by X k+1 = X k , an SL-complex of X k , and go to Step 4.
We observe that for l k ≥ 1, (i) X k X l , as each opening increases the number of edges (Lemma 4.4).
(ii) X k and X l have the same number of squares (Lemma 4.5).
(iii) There is no edge of thickness zero in X k (Lemma 4.5).(i) implies that the procedure above does not return a tubular graph of graphs from an earlier step.Since there are only a finite number of connected square complexes with a fixed number of squares (ii) and no thickness zero edges (iii), the procedure stops in finite time.
Checking if a graph has hanging trees takes linear time in the number of vertices and edges of X.Similarly, checking for edges of thickness zero or one or for rudimentary edges takes linear time in the number of edges and squares of X.Thus steps 1 through 4 run in linear time in the number of vertices, edges and squares of X.
From step 5 onwards, the number of vertices and edges of X k is bounded by the number of squares of X k , as each edge is contained in a square.Steps 5 and 6 run in polynomial (quadratic) time in the number of squares: indeed, the size of a vertex link in X k is bounded by the number of squares of X k and checking for connectedness and disconnecting vertices in a vertex link is linear in the number of vertices and edges of the link (see [HT73] for details).
If n is the number of squares in X, we claim that the number of times the algorithm goes back to step 4 is at most n.Indeed, the algorithm performs the k th opening-up only if every square of X k−1 is of thickness at least two.When each edge is of thickness at least two, the number of vertical edges (as well as horizontal edges) of a tubular graph of graphs can be at most equal to the number of squares.Observe that the opening procedure in Step 7 increases the number of vertical edges of X k by at least one, while decreasing the thickness of certain vertical edges.Thus, the algorithm continues at most until each vertical edge is contained in exactly two squares.
As an immediate consequence, we have:

Corollary 5.4 (Corollary C).
There is an algorithm of polynomial time complexity which takes as input a tubular graph of graphs and returns a homotopy equivalent tubular graph of graphs obtained by gluing together certain vertices of a finite collection of Brady-Meier tubular graphs of graphs and finite graphs.Further, the free product decomposition induced by cutting along the glued vertices is the Grushko decomposition of the fundamental group of the input tubular graph of graphs.
Proof.Let X be the input tubular graph of graphs with fundamental group G. Apply the algorithm of Theorem 5.3 to X. Let X N be the output.
is a free product (Remark 5.2).We first remove every edge of thickness one in X N by the procedure of Figure 2.
Cut X N along an edge of thickness zero or a locally disconnecting vertex (in the obvious way).Either we get a connected tubular graph of graphs X 1 or we get a disconnected space with components X 1 , • • • , X n , where each X i is a tubular graph of graphs.In the first case, G = G 1 * Z.In the latter case, G = G 1 * • • • * G n .Apply the algorithm again to each X i .If each G i is one-ended, we are done.Otherwise, cut again at an X i with a many-ended G i and repeat.This procedure terminates in polynomial time.Indeed, at each step we get tubular graphs of graphs whose total number of squares is bounded by the number of squares of X.
Remark 5.5.We point out that we do not use Stallings' theorem on ends for our proof.In fact, our procedure yields an alternate proof of Stallings' theorem for fundamental groups of tubular graphs of graphs.Similarly, we do not assume the existence of the Grushko decomposition either.Our algorithm proves its existence for the groups under consideration.
By the uniqueness of the Grushko decomposition, we have: Corollary 5.6 (Corollary D).Let X be a tubular graph of graphs with fundamental group G. Suppose that G admits a free splitting as G = A * B. Then there exist tubular graphs of graphs X 1 and X 2 such that A and B are fundamental groups of X 1 and X 2 respectively.Moreover, X 1 and X 2 can be so chosen such that the total number of squares in X 1 and X 2 is bounded by the number of squares in X.

Whitehead graphs and separability
The goal of this section is to give an alternative proof of Stallings' algorithm to detect whether a finite set of words in a free group is separable (Corollary 6.2).We also give a new proof of Whitehead's cut vertex theorem (Proposition 6.4).
Let F n be a free group of rank n ≥ 2 and let W be a finite set of non-trivial elements of F n .Definition 6.1 ([Sta99]).W is separable if there exists a non-trivial free splitting of F n = H * K such that each element of W is either a conjugate of an element of H or a conjugate of an element of K.
In [Sta99], Stallings developed an algorithm that detects whether W is separable.We will use Theorem 5.3 to obtain an alternative algorithm: Corollary 6.2 (Stallings; Corollary E).There exists an algorithm of polynomial time complexity that detects whether a given finite set of words in a finite rank free goup is separable.
Our method is closely related to Stallings', which uses Whitehead graphs [Whi36] (defined below).Let H n denote the orientable 3 dimensional handlebody of genus n.Recall that if Y is a topological space, then a cut point y ∈ Y is a point such that Y \ {y} is not connected.There is a well-known result about the separability of W . Proposition 6.4 ( [Whi36]).If W is separable, then for any basis B, the Whitehead graph Γ Fn,B (W ) is either disconnected, or has a cut vertex.
More details can be found in [Sta99].We will re-prove Proposition 6.4 above using tubular graphs of graphs.Stallings constructs his algorithm to detect separability by choosing a Whitehead automorphism whenever there is a cut vertex in a Whitehead graph.Our strategy is to use the machinery of Theorem 5.3 when a Whitehead graph contains a cut vertex.6.1.Construction of a double.Let R n denote an oriented rose with petals {a 1 , • • • , a n }.Fix an identification of F n with the fundamental group of R n such that each petal of R n in the positive direction represents a distinct element of the basis denote a cycle from the circle C j such that φ j induces the word w j in F n .We assume that w j is cyclically reduced so that φ j is an immersion.Subdivide R n and each C j so that each φ j is a simplicial immersion between simplicial graphs.Denote the subdivided R n by X s .
We call the descendant v in X s of the unique vertex of R n as the special vertex of X s .
We define the double of X s along W to be the tubular graph of graphs X such that X s is a vertical graph of X with exactly k tubes attached to X s via the attaching maps φ j .Further, the underlying graph of X consists of exactly two vertices and k edges between them, where each vertex graph is isomorphic to X s and each edge graph is isomorphic to a unique C j with attaching map φ j on both sides.Lemma 6.5.The vertex link of every vertex of X s ⊂ X is connected with no cut vertices if and only if the link of the special vertex v is connected with no cut vertices.
Proof.The main case to consider is that of a vertex u = v ∈ X s whose vertex link is either not connected or has a cut vertex.Then there exists at most one path between the two vertical vertices e 1 , e 2 in link(u).There is a bijective correspondence between paths in link(u) between e 1 and e 2 and paths in link(v) between vertices that induce the petal in R n that contains u.Hence the result.
The main lemma of this section is the following: Lemma 6.6.The link in X of the special vertex v is isomorphic as graphs to the first subdivision of the Whitehead graph Γ Fn,B (W ).
Proof.Each petal of R n induces two vertical vertices in link(v) and hence there are 2n vertical vertices.Paths of length two in link(v) between these vertices correspond to the occurrence of the respective letters in a word w j of W .The isomorphism is then clear.
Proof of Proposition 6.4.Let X be the double of (X s , W ), with fundamental group G. G is not one-ended as W is separable.By Proposition 3.6, the link of some vertex of X s is either not connected or has a cut vertex.Lemma 6.5 and Lemma 6.6 then give the result.
We will need the following result by Wilton [Wil12, Theorem 18]: Theorem 6.7 (Wilton).The fundamental group of a graph of free groups with cyclic edge groups is freely indecomposable if and only if every vertex group is freely indecomposable relative to the incident edge groups.
Note that a vertex group is freely indecomposable relative to the incident edge groups if and only if the set of words induced by the generators of these edge groups is not separable.
Proof of Corollary 6.2.Let W be the given set of words of the free group F .Let X be the double of (X s , W ) and G its fundamental group.Apply the algorithm of Corollary 5.4 to detect whether G is one-ended.By Theorem 6.7 above, G is one-ended if and only if W is not separable.

The general case
We recall that by a graph of groups G, we mean the following data: Γ is a connected graph, called the underlying graph.For each vertex s (edge a) of Γ, G s (G a ) is a group.Further, whenever a is incident to s, ∂ a,s : G a → G s is an injective homomorphism.Given a graph of groups as above, one can naturally associate with it a graph of spaces X G with the same underlying graph Γ such that for each vertex s (edge a) of Γ, X a (X s ) is a connected topological space such that π 1 (X a ) ∼ = G a (π 1 (X s ) ∼ = G s ).The fundamental group of the graph of groups G is the fundamental group of the geometric realisation of X G (Section 2.2).We refer the reader to [SW79] for details.In this section, we freely switch between graphs of groups and graphs of spaces as required.
Theorem 7.1 (Theorem F).There is an algorithm of polynomial time complexity which takes a graph of free groups with cyclic edge groups as input and returns the Grushko decomposition of its fundamental group.
Before going into the proof, we recall the definitions of collapse and blow up.Given a graph of groups G, and an edge a of the underlying graph Γ with endpoints s 1 , s 2 , by a collapse of the edge s we mean a graph of groups G with the following data: the underlying graph Γ is a quotient of Γ with the edge s collapsed to a point (vertex) a s .The only change in vertex (edge) groups is the new vertex group G as .G as is the fundamental group of the graph of groups whose underlying graph is the edge s, the vertex groups are G s1 and G s2 respectively and the edge group is G a , with the injective homomorphisms from the edge group remaining the same as in G.
An elementary blow up is the inverse operation of a collapse of an edge.A blow up is an iterated process of finitely many elementary blow up operations.Note that a collapse or blow up operation does not change the fundamental group.
We will also recall the notion of a relative Grushko decomposition.Let F be a finite rank free group and let W be a finite set of words in F .The relative Grushko decomposition of the pair (F, W ) is a free splitting of F such that each element of W conjugates into a free factor of the splitting.Further, each free factor of the splitting is itself freely indecomposable relative to W .
Proof.Given a graph of free groups with cyclic edge groups G, for each vertex s of the underlying graph Γ, we have a pair (G s , W s ), where G s denotes the free vertex group at s and W s is the set of words induced by generators of the incident edge groups.The Grushko decomposition of the fundamental group of G can be obtained in two steps: (1) Obtain for each pair (G s , W s ) its relative Grushko decomposition G Gr s in the following way: For the pair (G s , W s ), let X s denote a suitable subdivision of an oriented rose with fundamental group G s (see Section 6.1) and let Y s denote its double.Apply Corollary 5.4 to obtain a tubular graph of graphs Y Gr s which induces the Grushko decomposition of π 1 (Y s ).Note that by Theorem 6.7, any free splitting of π 1 (Y s ) is a free splitting of G s relative to W s .Thus the obtained Grushko decomposition of π 1 (Y s ) is a double over W s of the relative Grushko decomposition G Gr s of (G s , W s ).Let Γ s denote the underlying graph of G Gr s .
(2) Modify G by blowing-up each vertex s to G Gr s .Let G be the new graph of groups.Note that the edge groups of G are either cyclic or trivial (trivial if and only if the edge belongs to some Γ s ).Collapse all edges with nontrivial edge group to obtain a new graph of groups G Gr .By Theorem 6.7, the fundamental group of G admits no other free splitting and hence G Gr is the required Grushko decomposition.
The running time of the above algorithm is of the order of the sum of the running times of the algorithms to obtain the relative Grushko decompositions in step (1).But each such algorithm runs in polynomial time in the number of squares of Y s .The number of squares of Y s is the sum of the lengths of the words of W s in X s .Thus, the algorithm runs in polynomial time in the lengths of the words defined by the incident edge groups (in the respective vertex groups) of the input graph of free groups with cyclic edge groups.

X s X a e Figure 1 .
Figure 1.Removing rudimentary edges.

Figure 4 .
Figure 4. Opening star(u, X s ) to T u

Figure 5 .
Figure 5.A highlighted path of each colour indicates a part of the image of an attaching map Fix an identification of F n with the fundamental group of H n .A basis B of F n corresponds to a system of embedded disks D = {d 1 , • • • , d n } such that for an element b i ∈ B, b i is represented by a closed path in H n which starts from the chosen basepoint, intersects d i transversely and returns to the basepoint without touching any other d j .Cutting open H n along these disks results in a 3-ball with 2n disks d ± i (such that the chosen representative b i enters along d + i and leaves along d − i ).W is represented by a set of curves in H n .After cutting, the set of curves is now a set of arcs between these discs.Definition 6.3 ([Whi36]).The Whitehead graph Γ Fn,B (W ) is the graph with 2n vertices labelled {b ± 1 , • • • , b ± n } and an edge between two vertices b + i (respectively, b − i ) and b + j (b − i ) for every arc coming from W between the corresponding discs d + i (d − i ) and d + j (d − j ) in the cut up handlebody.Figure 6 illustrates an example when n = 2, B = {b 1 , b 2 } and W = {b 1 b 2 b 1 }.
1 Check if X k has hanging subtrees.If yes, collapse each hanging subtree to a point and call the new complex also as X k .Go to the next step.Step 2 Check if X k has a rudimentary edge.If yes, remove tubes attached to rudimentary edges (Lemma 2.16) and call the resulting complex also as X k .Go to the next step.Step 3 Check if X k has at least one square.If yes, go to the next step.Otherwise, X k is either a point or wedge-like.Stop.Step 4 Check if X k has an edge of thickness zero or one.If yes, X k is wedge-like.Stop.If not, go to the next step.Step 5 Check if the link of every vertex of X k is connected.If yes, go to the next step.If not, X k is wedge-like.Stop.Step 6 Check if X k satisfies (BM2).If yes, X k is Brady-Meier.Stop.If not, go to the next step.