es s Stallings’ folding process is inherently sequential Jeffrey Finkelstein Computer Science Department, Boston University ro gr January 14, 2016 Abstract k- in -p Allowing many processors to work in parallel offers no significant speedup when computing the rank of a finitely generated free group. Stallings’ folding process, an algorithm for simplifying a directed edgelabeled graph, when applied to those graphs that represent finitely generated free groups, provides a graph-theoretic method for computing the rank of that group. Does adding more processors to Stallings’ folding process offer any significant speedup? We answer this question negatively, proving that Stallings’ folding process itself is an inherently sequential algorithm. This paper provides the proof along with the requisite mathematical background. We show how the problem of computing the rank of a finitely generated free group reduces to the problem of computing an arbitrary bit of the execution of Stallings’ folding process, thereby showing that the process satisfies the definition of an “inherently sequential algorithm” . Thus, although Stallings’ folding process is computable in polynomial time, its asymptotic running time cannot be improved by adding more processors. Since this process often appears in the theory of free groups, one may be able to use this fact to show that other problems and algorithms appearing in computational group theory are inherently sequential. Introduction W or 1 TODO Rephrase the main problem as the problem of computing a minimum equivalent graph language; relate this to other “Minimum Equivalent [Model of computation]” problems. TODO Explain why this problem should be hard to approximate: approximating a minimum equivalent 3CNF formula to within a constant factor is already NP ∪ coNP-hard [4, Proposition 2], Minimum Equivalent Copyright 2012, 2013, 2014, 2015, 2016 Jeffrey Finkelstein 〈jeffreyf@bu.edu〉. This document is licensed under the Creative Commons Attribution-ShareAlike 4.0 International License, which is available at https://creativecommons.org/licenses/by-sa/4.0/. The LATEX markup that generated this document can be downloaded from its website at https://github.com/jfinkels/stallings. The markup is distributed under the same license. 1 DNF is Σ2 -complete [Umans 2000], and Shortest DNF Implicant is in GC(log2 n, coNP)-complete. See also this stackexchange question. The problem of computing the minimum rank of a finitely generated subgroup of a free group is inherently sequential—that is, allowing many processors to work together in parallel offers no significant speedup when solving the problem. One way of computing the minimum rank of the subgroup is by computing the size of a Nielsen reduced set equivalent to the generating set of the subgroup. Although it is computable in polynomial time, the Nielsen reduction is relatively complicated and the polynomial is of relatively large degree. A more efficient solution is to instead reduce the problem to a more easily solved graph problem; a finitely generated subgroup of a free group has a very natural representation as a directed, labeled graph. Stallings’ process for “folding” a directed labeled graph [10, Algorithm 5.4] is an analog of the Nielsen reduction for computing a minimal generating set for a free group. Can Stallings’ folding process solve the problem of finding the rank of a subgroup more quickly than the Nielsen reduction can? This paper proves that it cannot by showing that the folding process is inherently sequential. We show that the problem of deciding whether the result of Stallings’ folding process satisfies a certain property is inherently sequential. We also show that counting the number of redundant steps in the process is inherently sequential. Finally, we show that the process itself is inherently sequential, using the definition of an “inherently sequential algorithm”. We conclude that asymptotically Stallings’ folding process does not benefit from added parallelism. We stop short of determining if Stallings’ folding process admits a highly parallel approximation algorithm. This is important for developing a thorough understanding of the computational complexity of this mathematical algorithm: a highly parallel approximation for Stallings’ folding process may yield a highly parallel approximation for the rank of a free group, which has applications in computational algebra systems. Finally, we briefly mention related problems about primitive elements in a free group. A primitive element is an element of some basis of a free group. Deciding whether an element is primitive is decidable in polynomial time [8, Corollary 3.10]. Also, stated implicitly in [2, Theorem 4.4], the more general problem of extending a finite set of elements to a basis of the free group has an exponential time algorithm. We conjecture that these problems are inherently sequential as well. 2 2.1 Preliminaries Languages and strings A finite set Σ is called an alphabet. If Σ is an alphabet, a word over Σ is a finite sequence of symbols from Σ. A language is a set of strings over a finite alphabet. If w is a word over Σ, the length of w, denoted |w|, is the length of its underlying sequence. 2 2.2 Computational complexity We assume some familiarity with two well-known models of computation: the Turing machine and the random access machine (RAM). For definitions and background information on these models, see [9]. We say a Turing machine M decides a language L in polynomial time if there is a polynomial p such that for all strings x, we have x ∈ L if and only if M accepts x, and M halts within time p(|x|). The complexity class P is the class of all languages that can be decided in polynomial time. A function f is computable if there is a Turing machine that, on any input x, always halts with f (x) on its tape. If furthermore the Turing machine runs in polynomial time, then the function is computable in polynomial time. If furthermore the Turing machine runs in logarithmic space, then the function is computable in logarithmic space. Let L and L0 be languages. There is a logarithmic space many-one reduction from L0 to L if there is a logarithmic space computable function f such that x ∈ L0 if and only if f (x) ∈ L. If for each language L0 in P there is a logarithmic space many-one reduction from L0 to L, then L is P-hard; if furthermore L is in P, then L is P-complete. Languages that are P-complete are considered “inherently sequential” , because a highly parallel algorithm for any one of them would imply a highly parallel algorithm for each language in P, a result considered unlikely. 2.3 Free groups If S is an alphabet, we define the set of formal inverses for S, denoted S −1 , by {s−1 | s ∈ S}. In this case, the symbol s−1 is the formal inverse of s and vice versa. Let S ±1 denote the set S ∪ S −1 . A word w of length n over S ±1 can be written as s1 s2 · · · sn where si ∈ S ±1 for each i ∈ {1, . . . , n}. If u and v are words over S ±1 , where u = u1 u2 · · · un and v = v1 v2 · · · vm , then the concatenation of u and v, denoted u ◦ v or simply uv, is the word u1 u2 · · · un v1 v2 · · · vm . A word is freely reduced if it contains no two adjacent symbols that are inverses. The free group on S is the set of freely reduced words on S ±1 under the operation which concatenates two words then freely reduces the result. In this free group, a word w where w = w1 w2 · · · wi−1 ss−1 wi+2 · · · wn (which is not freely reduced) is equivalent to the freely reduced word w0 = w1 w2 · · · wi−1 wi+2 · · · wn . Each word over S ±1 has a unique, freely reduced representation (see for example, [6, Section I.1]). We denote this freely reduced representative of the word w by ρ(w). If A is a set of words, we define ρ(A) by ρ(A) = {ρ(a) | a ∈ A}. A finitely generated subgroup of the free group on S is the closure of a finite set of words over S ±1 under the free group operation. If U is a finite set of words, the subgroup generated by U is denoted hU i. The rank of a finitely generated subgroup is the cardinality of a generating set of minimum size. 2.4 Graphs A two-tuple (V, E) is a directed graph if V is a set of vertices and E is a multiset of elements from V × V . In this work, we write “directed graph” instead of 3 “directed multigraph”; note that multiple, parallel edges are allowed. We also refer to the “edge set” of a directed graph when we mean “edge multiset”. If G is a directed graph, we denote the vertex set of G by V (G) and the edge set of G by E(G). The Euler characteristic of G, denoted χ(G), is defined by χ(G) = |V (G)| − |E(G)| for all graphs G. If e is an edge in a graph and e = (u, v), where u and v are vertices, then the origin of e, denoted o(e), is defined by o(e) = u and the terminus of e, denoted t(e), is defined by t(e) = v. Two edges (in a multigraph) are parallel if they have the same origin and terminus. A path from u to v in G, or more simply, a path, is a finite sequence of edges, (e1 , e2 , . . . , en ), such that o(e1 ) = u, t(en ) = v, and t(ei ) = o(ei+1 ) for all i ∈ {1, . . . , n − 1}. A rooted circle is a path from “root” vertex v ∈ V (G) to the same vertex, along which each intermediate vertex, except possibly v, is incident to exactly two edges (namely, the one preceding it in the path and the one following it in the path). The directed graph G is a flower graph with respect to a vertex v ∈ V (G) if it equals the union of circles rooted at v. If G is a directed graph, a tree T with root v is an acyclic subgraph of G in which there is a path in T from v to every vertex in V (T ). A tree T with root v is a spanning tree for G if there is a path in T from v to every vertex in V (G). A spanning tree with root v is geodesic if for each vertex w in the graph, the length of the (unique) path from v to w in the tree equals the length of the shortest path from v to w in the graph. We say G is labeled by S if there exists a function µ : E(G) → S. If G is a labeled, directed graph, then its inverse graph, denoted Ĝ, has the same vertex set and edge set, but wherever there is an edge (u, v) ∈ E(G) with label s we add the inverse edge (v, u) to E(Ĝ) with label s−1 . The positive edges of Ĝ are the edges with labels in S and the negative edges are those with labels in S −1 . If E is a set of directed, labeled edges, we denote the positive edges in E by pos(E) and the negative edges by neg(E). The label of a path p, denoted µ(p), is the sequence of labels of each of its constituent edges. We sometimes abuse notation for the sake of convenience and discuss a path in G when what we mean is a path in the subgraph induced by the positive edges of Ĝ in which edges e with the inverse orientation are allowed, but their labels µ(e) are read as the corresponding inverse label µ(e)−1 . Analogous to freely reduced words in the free group on S, a reduced path in G is a path which does not contain any adjacent pairs of edges such that their labels are inverses. 2.5 Languages of labeled graphs If G is a directed graph labeled by S and v ∈ V (G), then the language of G with respect to v, denoted L(G, v), is defined by L(G, v) = {µ(p) | p is a reduced path in G from v to v}. The reduced language, denoted ρ(L(G, v)), is defined by ρ(L(G, v)) = {ρ(w) | w ∈ L(G, v)}. The core of a labeled, directed graph G with respect to a vertex v ∈ V (G), denoted Core(G, v), is the subgraph of G induced by the set of all edges which are in some reduced path from v to v. A labeled, directed graph 4 G is a core graph with respect to a vertex v ∈ V (G) if Core(G, v) = G. A pair of edges is foldable if they have the same label and they share an origin or a terminus. A directed graph G labeled by S is folded if there are no foldable edges. In other words, for each vertex v ∈ V (G) and each symbol s ∈ S, there is at most one edge in E(G) with origin v and label s and there is at most one edge in E(G) with terminus v and label s. Stated another way, G is folded if there is no vertex v ∈ V (G) such that v has two (or more) in-edges with the same label or two (or more) out-edges with the same label. Informally, a fold is a function which identifies not only two foldable edges but also the vertex opposite from their shared incident vertex. Stallings’ folding process, defined in [10, Algorithm 5.4], is a function, denoted F , that operates on labeled, directed graphs. It proceeds by repeatedly choosing a foldable pair of edges (say, the lexicographically first pair) and folding them until there are no more foldable edges. See Figure 1 for an example execution of the algorithm. Theorem 2.1 ([7]). Stallings’ folding process, F , is computable in polynomial time. The input to F is a finite alphabet S, a directed graph G, and a label function µ : E(G) → S. The output of F is the same alphabet S, a directed graph G0 , and a label function µ0 : E(G0 ) → S. For the sake of brevity, instead of writing (S, G0 , µ0 ) = F (S, G, µ), we will write G0 = F (G), when the alphabet and the label function are clear from context. 3 Transforming a subgroup into a graph How can a simple graph algorithm be used to compute the rank of a finitely generated subgroup of a free group? First we need to prove that for each set of generators there is an “equivalent” graph that has the properties we desire. We restate a result implicit in [5] so that we can use this equivalence in a complexity theoretic proof. Lemma 3.1 is a summary and restatement of some results in [5]; please see the referenced lemmas and propositions for more information and complete proofs. According to the following lemma, each finitely generated subgroup of a free group can be represented as a flower graph whose “petals” are labeled with the words in the generating set. In this way, a word in the generating set corresponds to a cycle that begins at the root, proceeds around a petal, and terminates at the root. Concatenation of words then corresponds to a walk consisting of a concatenation of cycles, always returning to the root. Since this transformation from group to graph is efficiently computable, it allows to translate statements about labeled directed graphs to statements about free groups. With this transformation and the fact that Free Group Rank is P-complete, we can show that the graph theoretic problems concerning Stallings’ folding process are P-complete as well. Lemma 3.1. For each finite alphabet S and finite set U of freely reduced words over S ±1 , there is a graph G and a label function µ : E(G) → S such that 5 Figure 1: A step-by-step execution of Stallings’ folding process (read left-to-right, top-to-bottom) on the graph corresponding to the set of words U defined by U = {aab−1 , aba−1 , ba−1 ba} (this example is from [5, Figure 4]). Each picture shows the pair of edges to be folded in orange and the root node as a large black circle. b b a a a a b b a b a a a b a a a b b b a a a a b a b a a a a b b b b b a a a a a a b b b b a a 6 b 1. G and µ are computable in logarithmic space with respect to the size of S and U , 2. G is a flower graph and a core graph (with respect to the same vertex), 3. there is a set Y of words induced by paths in F (G) such that • the rank of hU i equals |Y |, • |Y | is computable in logarithmic space with respect to the size of F (G). Proof. Suppose U is a finite set of words {u1 , u2 , . . . , um } and for each i ∈ {1, . . . , m} we have ui = ui,1 ui,2 · · · ui,ni where ni is the length of ui . Construct the directed graph G as follows. Create a vertex v0 , which will be the “root” of the flower. Create one circle rooted at v0 for each word u in U , and each circle is divided into |u| edges, one for each symbol of u. Each edge of the circle is then labeled with the corresponding symbol in u. Wherever the graph contains a label s−1 , the inverse of a symbol s in S, that edge is reversed (that is, (v, w) is replaced with (w, v)) and we replace the label s−1 with the label s on the reversed edge. In this way we have constructed a graph with only positive edges; this simplifies our proof a bit. This function is computable in logarithmic space because a loop over the set U requires O(log |U |) space, a loop over a word u ∈ U requires O(log |u|) space, and writing the adjacency matrix of the graph and the corresponding labels can be done in constant space. Thus, item 1 is satisfied. Since it is the union of circles rooted at v0 , the graph G is a flower graph with respect to v0 . Since each circle corresponds to a word in U , and each word in U is freely reduced, G is also a core graph with respect to v0 . Thus, item 2 is satisfied Now in order to construct Y , we examine the properties of the graph G under F , Stalling’s folding process. Let G0 = F (G) and v00 be the image of v0 under the sequence of foldings produced by F on input G. We know G0 has a spanning tree T which is geodesic with respect to v00 by [5, Lemma 6.6]. For any vertex z in V (G0 ), let [v00 , z]T denote the path from v00 to z within the spanning tree T . For each edge e in E(G0 ) \ E(T ) (in other words, e is an edge in G0 not in the spanning tree T ), let pe denote the path that results from the concatenation of the three paths [v00 , o(e)]T , e, [t(e), v00 ]T . (Since T is a spanning tree, [v00 , o(e)]T and [t(e), v00 ]T must exist.) Define the set of words Y as Y = {µ(pe ) | e ∈ E(G0 ) \ E(T )} . In other words, Y is the set of sequences of edge labels corresponding to the fundamental cycles of G0 with respect to T . For an example of how to construct Y from a tree T , see Figure 2. Now hU i = ρ(L(G, v0 )) (by [5, Proposition 3.8]) = ρ(L(G0 , v00 )) (by [5, Lemma 3.4]) 0 (by [5, Lemma 2.9]) = L(G , v00 ) = hY i (by [5, Lemma 6.1]). 7 Figure 2: Continuing the example from Figure 1, the set Y in Lemma 3.1 is constructed from the minimum spanning tree, shown in bold edges, for the graph produced by Stallings’ folding process. In this case, Y = {b, aba−1 , aa}. The subgroup generated by Y equals the subgroup generated by U ; each word in one set can be expressed as a concatenation of words (or their inverses) from the other set. b a a b Since hU i and hY i are equal, their ranks are equal. Finally, the rank of hY i is |Y |, since Y is Nielsen reduced by [5, Proposition 6.7]. Therefore, the rank of hU i equals |Y |. Computing |Y | can be done by counting the number of (positive) edges in G0 not in T . Computing T from G0 can be done recursively in logarithmic space (by recursively computing Tn , the geodesic spanning tree for all vertices at distance n from v0 ; this requires O(n) levels of recursion, each of which requires looping over O(n2 ) edges and checking if each edge is adjacent to one already in the spanning tree from the next level of recursion, thereby requiring at most O(log n) space). 4 Inherently sequential properties of Stallings’ folding process According to Lemma 3.1, each finitely generated subgroup of a free group corresponds to a directed labeled graph whose language is exactly the generated subgroup. Since this transformation is efficiently computable we would like to use it to show a reduction to some new computational problems concerning Stallings’ folding process. This section proves that determining certain properties of the graph that results from Stallings’ folding process is an inherently sequential problem. We show that both the problem of determining the Euler characteristic of the graph produced by Stallings’ folding process and the problem of determining the number of folds performed on parallel edges during the execution of the algorithm are P-complete. This is an indication that the algorithm itself is inherently sequential. In section 5, we use these P-complete problems to show just that. In order to show the necessary reductions, we express the optimization problems of interest as decision problems. Any minimization problem, like the problem of computing the minimum rank of a finitely generated free group, has a corresponding budget problem that can be used to decide whether there is a 8 solution to the problem that meets a given upper bound. Definition 4.1 (Free Group Rank). Instance: finite alphabet S, finite set U of freely reduced words over S ±1 , positive integer k. Question: Does hU i in the free group on S have rank k or less? Free Group Rank is P-complete [1, Theorem 4.9] (see also [3, Problem A.8.11]). (In fact, the algorithm that shows that this problem is decidable in polynomial time is constructive; not only does it compute the rank of hU i, it does so by also computing a set V such that V is Nielsen reduced and hU i = hV i.) We will use this fact to show the P-completeness of some related problems, and ultimately Stallings’ folding process itself. Definition 4.2 (Folded Characteristic). Instance: finite alphabet S, directed graph G, label function µ : E(G) → S, integer k. Question: Does F (G) have Euler characteristic at least k? Definition 4.3 (Parallel Folds). Instance: finite alphabet S, directed graph G, label function µ : E(G) → S, integer k. k k Question: Is NF (G) greater than or equal to k? Here, NF (G) is the number of folds produced by running F on input G that are folds of a pair of parallel edges. The former problem asks a question about the output of F , whereas the latter asks a question about the execution of F . Theorem 4.4. Folded Characteristic is P-complete, even when the graph is both a flower graph and a core graph (with respect to the same vertex). Proof. By Theorem 2.1, F (G) is computable in polynomial time. Computing the Euler characteristic of a graph can be done in linear time, as can comparison with an integer, so Folded Characteristic is in P. To show that Folded Characteristic is P-hard, we show a logarithmic space many-one reduction from the P-complete decision problem Free Group Rank to Folded Characteristic. The reduction is hS, U, ki 7→ hS, G, µ, 1−ki, where G and µ are the graph and label function guaranteed by Lemma 3.1. This reduction is computable in logarithmic space by that lemma as well. Let Y be the set constructed in Lemma 3.1 such that the rank of hU i equals |Y |. In order to show that the reduction is correct, it suffices to show that the Euler characteristic of F (G) equals 1 − |Y |. The set Y is defined as Y = {µ(pe ) | e ∈ E(G0 ) \ E(T )} , where G0 = F (G) and T is a spanning tree for G0 . Recalling that the number of 9 edges in a spanning tree is |V (G)| − 1, we have |Y | = |E(G0 ) \ E(T )| = |E(G0 )| − |E(T )| (since E(T ) ⊆ E(G0 )) = |E(G0 )| − (|V (G0 )| − 1) 0 (since T is a spanning tree) 0 = (|E(G )| − |V (G )|) + 1 = −χ(G0 ) + 1 (by definition of χ). With this equality (which also appears as [5, Lemma 8.2]), we conclude the proof by stating that hU i has rank at most k if and only if 1 − k ≤ χ(G0 ). We can also prove that determining a property of how the algorithm F operates is inherently sequential, as well. Theorem 4.5. Parallel Folds is P-complete, even when the graph is both a flower graph and a core graph (with respect to the same vertex). Proof. Like for Folded Characteristic, computing Stallings’ folding process and counting the number of folds that occur on a pair of parallel edges places this problem in P. We show a logarithmic space many-one reduction from the Folded Characteristic problem on graphs that are both flower graphs and core graphs to Parallel Folds. The reduction is hS, G, µ, ki 7→ hS, G, µ, k − χ(G)i. Counting the number of vertices and number of edges in G, then performing two subtractions can be performed in logarithmic space. It remains to show the correctness of the reduction. Each fold in Stallings’ folding process decreases the number of edges in the final graph by one. Each fold decreases the number of vertices in the final graph by one, unless the fold operates on two parallel edges with the same label (that is, two edges with the same origin, terminus, and label), in which case, the number of vertices remains unchanged. (This includes folds of double self-loops.) Let NF (G) be the number of folds when k Stallings’ folding process is run on input G, and let NF (G) be the number of those folds which are folds of a pair of a parallel edges. If G0 = F (G), it follows k that |E(G0 )| = |E(G)| − NF (G) and |V (G0 )| = |V (G)| − (NF (G) − NF (G)). Hence χ(G0 ) = |V (G0 )| − |E(G0 )| k = (|V (G)| − (NF (G) − NF (G))) − (|E(G)| − NF (G)) k = (|V (G)| − |E(G)|) − NF (G) + NF (G) + NF (G) k = χ(G) + NF (G). k k Therefore, χ(G0 ) ≥ k ⇐⇒ χ(G) + NF (G) ≥ k ⇐⇒ NF (G) ≥ k − χ(G). 10 5 Stallings’ folding process is inherently sequential The previous section shows that computing the number of parallel folds performed by Stallings’ folding process is an inherently sequential problem; adding more processors does not provide any substantial speedup. Since it is easy to decide whether a particular fold is a fold of parallel edges, the hardness of this problem seems to stem from the sequential nature of the folding process: each fold depends on the result of the previous fold. In an effort to formalize this intuition, we would like to prove that Stallings’ folding process itself is an inherently sequential algorithm; this section proves that intuition. Specifically, we show that computing any bit of the flow function of Stallings’ folding process is P-complete, thereby proving that the algorithm itself is inherently sequential. This means the function F is at least as difficult to compute as each other polynomial time computable function. However, a randomized algorithm or approximation algorithm remains a possibility. Suppose M is an arbitary RAM. For any input x, each statement executed by M when run on input x has an associated value. For example, the value of an “add” instruction is the integer that results from the addition and the value of a “write” instruction is the integer written to memory. The flow function of M , denoted fM , is defined by fM (x, t) = ((1, v1 ), . . . , (t, vt )), where vi is the value associated with statement i in the execution of M on input x. Define fM (x) by fM (x) = fM (x, T (|x|)), where T (n) is the function bounding the maximum running time of M on inputs of length n. Definition 5.1 (Flow(M )). Instance: binary string x, positive binary integer i, bit j. Question: Does the ith bit of fM (x) equal j? We say the function computed by M is inherently sequential if Flow(M ) is P-complete [3, Definition 8.2.2]. Theorem 5.2. Stallings’ folding process is inherently sequential. Specifically, Flow(F ) is P-complete, even when the graph is both a flower graph and a core graph (with respect to the same vertex). Proof. Assume without loss of generality that F accepts an additional input, k, and appends to its normal output a bit indicating whether the Euler characteristic of F (G) is at least k. We can make this assumption because the length of k is at most the size of the graph G, and performing the additional computation on F (G) can be done in polynomial time. Thus the modified algorithm has an input not much larger than the original input, has a polynomial running time, and computes just a bit of additional information. Now Folded Characteristic reduces to Flow(F ), where F is the modified folding process. The reduction is (G, S, µ, k) 7→ ((G, S, µ, k), i, 1), where i is the index of the very last bit of the output of the flow function. The reduction is computable in logarithmic space because it copies its input to its output, writes 11 the index of the last bit of the flow function (which is the binary representation of a number bounded by a polynomial in n), and writes the single bit 1. The reduction is correct because the last bit of the output of the modified algorithm is 1 exactly when the Euler characteristic of F (G) is at least k. The following graph is an example of the worst-case input for Stallings’ folding process. For each natural number n, this graph on 4n + 2 nodes and edges corresponds to the subgroup of the free group on two elements generated by the singleton set {(ab)n (ab−1 )(b−1 a−1 )n }. (It is also a flower graph and a core graph.) a b ... b ... a a a b a b b At each step of Stallings’ folding process, there is exactly one foldable pair of edges, the leftmost pair of “branching” edges, so no parallelization can be applied; the total number of steps in the process must be Θ(m), where m is the number of edges, even if we allow folding multiple foldable edges at each step. TODO Is there a dense worst-case graph? TODO Is there an approximation for graphs like this? References [1] Jürgen Avenhaus and Klaus Madlener. “The Nielsen Reduction and PComplete Problems in Free Groups”. In: Theoretical Computer Science 32 (1984), pp. 61–76. doi: 10.1016/0304-3975(84)90024-0. [2] A. Clifford and R. Z. Goldstein. “Sets of primitive elements in a free group”. In: Journal of Algebra 357 (2012), pp. 271–278. issn: 0021-8693. doi: 10.1016/j.jalgebra.2012.01.033. [3] Raymond Greenlaw, H. James Hoover, and Walter L. Ruzzo. Limits to Parallel Computation: P-completeness Theory. New York: Oxford University Press, 1995. isbn: 0195358902. [4] III Hunt Harry B., Madhav V. Marathe, and Richard E. Stearns. “On the Efficient Approximability of "HARD" Problems: A Survey”. In: Approximation and Complexity in Numerical Optimization. Ed. by Panos M. Pardalos. Vol. 42. Nonconvex Optimization and Its Applications. Springer US, 2000, pp. 308–322. isbn: 978-1-4419-4829-8. doi: 10.1007/978-1-4757-31453_18. [5] Ilya Kapovich and Alexei Myasnikov. “Stallings Foldings and Subgroups of Free Groups”. In: Journal of Algebra 248.2 (2002), pp. 608–668. issn: 0021-8693. doi: 10.1006/jabr.2001.9033. 12 [6] Roger Lyndon and Paul Schupp. Combinatorial Group Theory. SpringerVerlag, 1977. isbn: 3540076425. [7] Nicholas W. M. Touikan. “A Fast Algorithm for Stallings’ Folding Process”. In: International Journal of Algebra and Computation 16 (6 2006). doi: 10.1142/S0218196706003396. [8] Abdó Roig, Enric Ventura, and Pascal Weil. “On the complexity of the Whitehead minimization problem”. In: International Journal of Algebra and Computation 17.08 (2007), pp. 1611–1634. doi: 10 . 1142 / S0218196707004244. [9] John E. Savage. Models of Computation: Exploring the Power of Computing. Addison-Wesley, 1998. [10] John R. Stallings. “Topology of finite graphs”. In: Inventiones Mathematicae 71 (3 1983), pp. 551–565. issn: 0020-9910. doi: 10.1007/BF02095993. 13