An improved isomorphism test for bounded-tree-width graphs

We give a new fpt algorithm testing isomorphism of $n$-vertex graphs of tree width $k$ in time $2^{k\operatorname{polylog} (k)}\operatorname{poly} (n)$, improving the fpt algorithm due to Lokshtanov, Pilipczuk, Pilipczuk, and Saurabh (FOCS 2014), which runs in time $2^{\mathcal{O}(k^5\log k)}\operatorname{poly} (n)$. Based on an improved version of the isomorphism-invariant graph decomposition technique introduced by Lokshtanov et al., we prove restrictions on the structure of the automorphism groups of graphs of tree width $k$. Our algorithm then makes heavy use of the group theoretic techniques introduced by Luks (JCSS 1982) in his isomorphism test for bounded degree graphs and Babai (STOC 2016) in his quasipolynomial isomorphism test. In fact, we even use Babai's algorithm as a black box in one place. We also give a second algorithm which, at the price of a slightly worse running time $2^{\mathcal{O}(k^2 \log k)}\operatorname{poly} (n)$, avoids the use of Babai's algorithm and, more importantly, has the additional benefit that it can also used as a canonization algorithm.


Introduction
Already early on in the beginning of research on the graph isomorphism problem (which asks for structural equivalence of two given input graphs) a close connection to the structure and study of the automorphism group of a graph was observed. For example, Mathon [Mat79] argued that the isomorphism problem is polynomially equivalent to the task of computing a generating set for the automorphism group and also to computing the size of the automorphism group.
With Luks's polynomial time isomorphism test for graphs of bounded degree [Luk82], the striking usefulness of group theoretic techniques for isomorphism problems became apparent and they have been exploited ever since (e.g. [BL83,Mil83,Pon91,Neu16]). In his algorithm, Luks shows and uses that the automorphism group of a graph of bounded degree, after a vertex has been fixed, has a very restricted structure. More precisely, the group is in the class Γ k of all groups whose non-Abelian composition factors are isomorphic to a subgroup of the symmetric group Sym(k).
Most recently, Babai's quasi-polynomial time algorithm for general graph isomorphism [Bab16] adds several novel techniques to tame and manage the groups that may appear as the automorphism group of the input graphs.
A second approach towards isomorphism testing is via decomposition techniques (e.g. [Bod90,GM15,GS15]). These decompose the graph into smaller pieces while maintaining control of the complexity of the interplay between the pieces. When taking this route it is imperative to decompose the graph in an isomorphism-invariant fashion so as not to compare two graphs that have been decomposed in structurally different ways.
A prime example of this strategy is Bodlaender's isomorphism test [Bod90] for graphs of bounded treewidth. Bodlaender's algorithm is a dynamic programming algorithm that takes into account all k-tuples of vertices that separate the graph, leading to a running time of O(n k+c ) to test isomorphism of graphs of tree width at most k.
Only recently, Lokshtanov, Pilipczuk, Pilipczuk, and Saurabh [LPPS17] designed a fixed-parameter tractable isomorphism test for graphs of bounded tree width which has a running time of 2 O(k 5 log k) poly(n). This algorithm first "improves" a given input graph G to a graph G k by adding an edge between every pair of vertices between which more than kinternally vertex disjoint paths exist. The improved graph G k isomorphism-invariantly decomposes along clique separators into clique-separator free parts, which we will call basic throughout the paper. The decomposition can in fact be extended to an isomorphisminvariant tree decomposition into basic parts, as was shown in [ES16] to design a logspace isomorphism test for graphs of bounded tree width. For the basic parts, Lokshtanov et al. [LPPS17] show that, after fixing a vertex of sufficiently low degree, is it possible to compute an isomorphism-invariant tree decomposition whose bags have a size at most exponential in k and whose adhesion is at most O(k 3 ). They use this invariant decomposition to compute a canonical form essentially by a brute-force dynamic programming algorithm.
The problem of computing a canonical form is the task to compute, to a given input graph G, a graph G ′ isomorphic to G such that the output G ′ depends only on the isomorphism class of G and not on G itself.
The isomorphism problem reduces to the task of computing a canonical form: for two given input graphs we compute their canonical forms and check whether the canonical forms are equal (rather than isomorphic).
As far as we know, computing a canonical form could be algorithmically more difficult than testing isomorphism. It is usually not very difficult to turn combinatorial isomorphism tests into canonization algorithms, sometimes the algorithms are canonization algorithms in the first place. However, canonization based on group theoretic isomorphism tests is more challenging. For example, it is still open whether there is a graph canonization algorithm running in quasipolynomial time.

Our Results
Our main result is a new fpt algorithm testing isomorphism of graphs of bounded tree width.
Theorem 1. There is a graph isomorphism test running in time where n is the size and k the minimum tree width of the input graphs.
In the first part of the paper, we analyze the structure of the automorphism groups of a graph G of tree width k. Following [LPPS17] and [ES16], we pursue a two-stage decomposition strategy for graphs of bounded tree width, where in the first step we decompose the improved graph along clique separators into basic parts. We observe that these basic parts are essential for understanding the automorphism groups. We show (Theorem 9) that with respect to a fixed vertex v of degree at most k, we can construct for each basic graph H an isomorphism-invariant tree decomposition of width at most 2 O(k log k) and adhesion at most O(k 2 ) where, in addition, each bag is equipped with a graph of small degree which is defined in an isomorphism-invariant way and gives us insight about the structure of the bag. In particular, using Luks results [Luk82], this also restricts the structure of the automorphism group.
Our construction is based on a similar construction of an isomorphism-invariant tree decomposition in [LPPS17]. Compared to that construction, we improve the adhesion (that is, the maximum size of intersections between adjacent bags of the decomposition) from O(k 3 ) to O(k 2 ). More importantly, we expand the decomposition by assigning a group and a graph to each bag.
Using these groups, we can prove that Aut(H) v (the group of all automorphisms of H that keep the vertex v fixed) is a Γ k+1 group. This significantly restricts possible automorphism groups. Moreover, using the graph structure assigned to each bag, we can also compute the automorphism group of a graph of tree width k within the desired time bounds. The first, already nontrivial step towards computing the automorphism group, is a reduction from arbitrary graphs of tree width k to basic graphs. The second step reduces the problem of computing the automorphism group of a basic graph to the problem of computing the automorphism group of a structure that we call an expanded d-ary tree. In the reduction, the parameter d will be polynomially bounded in k. Then as the third step, we can apply a recent result [GNS18] due to the first three authors that allows us to compute the automorphism groups of such expanded d-ary trees. This result is heavily based on techniques introduced by Babai [Bab16] in his quasipolynomial isomorphism test. In fact, it even uses Babai's algorithm as a black box in one place.
We prove a second result that avoids the results of [GNS18,Bab16] and even allows us to compute canonical forms, albeit at the price of an increased running time.
Theorem 2. There is a graph canonization algorithm running in time where n is the size and k the tree width of the input graph.
Even though it does not employ Babai's new techniques, this algorithm still heavily depends on the group theoretic machinery. As argued above, the design of group theoretic canonization algorithms often requires extra work, and can be slightly technical, compared to the design of an isomorphism algorithm. Here, we need to combine the group theoretic canonization techniques going back to Babai and Luks [BL83] with graph decomposition techniques, which poses additional technical challenges and requires new canonization subroutines.

Organization of the paper
In the next section we introduce the necessary preliminaries. The next two Sections 3-4 of the paper deal with the decomposition of bounded tree width graphs. They describe the isomorphism-invariant decomposition into basic parts and the isomorphism-invariant decomposition of the basic parts with respect to a fixed vertex of low degree.
The two following Sections 5-6 are concerned with isomorphism. We define a particular subproblem, coset-hypergraph-isomorphism, identified to be of importance. Then, we assemble the recursive isomorphism algorithm.
In the last Section 7 we devise several subroutines for canonization in general and assemble the recursive canonization algorithm.

Preliminaries
Graphs We use standard graph notation. All graphs G = (V, E) considered are undirected finite simple graphs. We denote an edge {u, v} ∈ E by uv. Let U, W ⊆ V be subsets of vertices. We write E(U, W ) for the edges with one vertex in U and the other vertex from W , whereas E(U ) are the edges with both vertices in U . By N (U ), we denote the neighborhood of U , i.e, all vertices outside U that are adjacent to U . For the induced subgraph on U , we write G[U ], whereas G − U is the induced subgraph on V \ U . A rooted graph is triple G = (V, E, r) where r ∈ V is the root of the graph. For two vertices v, w ∈ V we denote by dist G (v, w) the distance between v and w, i.e. the length of the shortest path from v to w. The depth of a rooted graph is the maximum distance from a vertex to the root, that is, depth In this case we call A ∩ B a separator. A separation (A, B) is a (L, R)-separation if L ⊆ A and R ⊆ B and in this case A ∩ B is called a (L, R)-separator. A separation (A, B) is a called a clique separation if A ∩ B is a clique and A \ B = ∅ and B \ A = ∅. In this case we call A ∩ B a clique separator.

Tree Decompositions
Definition 3. A tree decomposition of a graph G is a pair (T, β), where T is a rooted tree and β : V (T ) → Pow(V (G)) is a mapping into the power set of V (G) such that: induces a nonempty and connected subtree of T, and 2. for each edge e ∈ E(G), there exists t ∈ V (T ) such that e ⊆ β(t).
Sets β(t) for t ∈ V (T ) are called the bags of the decomposition, while sets β(s) ∩ β(t) for st ∈ E(T ) are called the adhesions sets. The width of a tree decomposition T is equal to its maximum bag size decremented by one, i.e. max t∈V (T ) |β(t)| − 1. The adhesion width of T is equal to its maximum adhesion size, i.e., max st∈E(T ) |β(s) ∩ β(t)|. The tree width of a graph, denoted by tw(G), is equal to the minimum width of its tree decompositions.
A graph G is k-degenerate if every subgraph of G has a vertex with degree at most k. It is well known that every graph of tree width k is k-degenerate.
Groups For a function ϕ : V → V ′ and v ∈ V we write v ϕ for the image of v under ϕ, that is, v ϕ = ϕ(v). We write composition of functions from left to right, e.g, v (σρ) = (v σ ) ρ = ρ(σ(v)). By [t] we denote the set of natural number from 1 to t. By Sym(V ) we denote the symmetric group on a set V and we also write Sym(t) for Sym([t]). We use upper Greek letters ∆, Φ, Γ, Θ and Ψ for permutation groups.
Labeling cosets A labeling coset of a set V is a set of bijective mappings τ ∆ where τ is a bijection from V to [|V |] and and ∆ is a subgroup of Sym(|V |). By Label(V ), we denoted the labeling coset τ Sym(|V |). We say that τ ∆ is a labeling subcoset of a labeling coset ρΘ, written τ ∆ ≤ ρΘ, if τ ∆ is a subset of ρΘ and τ ∆ forms a labeling coset again. Sometimes we will choose a single symbol to denote a labeling coset τ ∆. For this will usually use the upper greek letter Λ. Recall that Γ k denotes the class of all finite groups whose non-Abelian composition factors are isomorphic to subgroups of Sym(k). Let Γ k be the class of all labeling cosets Λ = τ ∆ such that ∆ ∈ Γ k .
Orderings on sets of natural numbers We extend the natural ordering of the natural numbers to finite sets of natural numbers. For two such sets M 1 , M 2 we define M 1 ≺ M 2 if |M 1 | < |M 2 | or if |M 1 | = |M 2 | and the smallest element of M 1 \ M 2 is smaller than the smallest element of M 2 \ M 1 .
Isomorphisms In this paper we will always define what the isomorphism between our considered objects are. But this can also be done in a more general context. Let ϕ : V → V ′ . For a vector (v 1 , . . . , v k ) we define (v 1 , . . . , v k ) ϕ as (v ϕ 1 , . . . , v ϕ k ) inductively. Analogously, for a set we define {v 1 , . . . , v n } ϕ as {v ϕ 1 , . . . , v ϕ n }. For a labeling coset Λ ≤ Label(V ) we write Λ ϕ for ϕ −1 Λ. In the paper we will introduce isomorphisms Iso(X, X ′ ) for various objects X and X ′ . Unless otherwise stated these are all ϕ : V → V ′ such that X ϕ = X ′ where we apply ϕ as previously defined. For example, the isomorphism between two graphs G and G ′ are all ϕ : V → V ′ such that G ϕ = G ′ which means that G has an edge uv, if and only if G ′ has the edge u ϕ v ϕ .

Clique separators and improved graphs
To perform isomorphism tests of graphs of bounded tree width, a crucial step in [LPPS17] is to deal with clique separators. For this step the concept of a k-improved graph is the key.
Definition 4 ( [LPPS17]). The k-improvement of a graph G is the graph G k obtained from G by connecting every pair of non-adjacent vertices v, w for which there are more than k pairwise internally vertex disjoint paths connecting v and w. We say that a graph G is k-improved when G k = G.
A graph is k-basic if it is k-improved and does not have any separating cliques. In particular, a k-basic graph is connected.
We summarize several structural properties of G k .
2. Every tree decomposition (T, β) of G of width at most k is also a tree decomposition of G k .
3. There exists an algorithm that, given G and k, runs in O(k 2 n 3 ) time and either correctly concludes that tw(G) > k, or computes G k .
Since the construction of G k from G is isomorphism-invariant, the concept of the improved graph can be exploited for isomorphism testing and canonization. A k-basic graph has severe limitations concerning its structure as we explore in the following sections. In the canonization algorithm from [LPPS17] a result of Leimer [Lei93] is exploited that says that every graph has a tree decomposition into clique-separator free parts, and the family of bags is isomorphism-invariant. While it is usually sufficient to work with an isomorphism-invariant set of bags (see [OS14]) we actually require an isomorphism invariant decomposition, which can indeed be obtained.
Theorem 6 ([Lei93], [ES16]). There is an algorithm that, given a connected graph G, computes a tree decomposition (T, β) of G, called clique separator decomposition, with the following properties.
1. For every t ∈ V (T ) the graph G[β(t)] is clique-separator free (and in particular connected).
2. Each adhesion set of (T, β) is a clique.

Decomposing basic graphs
In this section, we shall construct bounded-width tree decompositions of k-basic graphs of tree width at most k. Crucially, these decompositions will be isomorphism invariant after fixing one vertex of the graph. Our construction refines a similar construction of [LPPS17]. Let us define three parameters c S , c M , and c L (small, medium and large) that depend on k as follows: c S := 6(k + 1), c M := c S + c S (k + 1), Note that c S ∈ O(k), c M ∈ O(k 2 ) and c L ∈ 2 O(k log k) . The interpretation of these parameters is that c M will bound the size of the adhesion sets and c L will bound the bag size. The parameter c S is used by the algorithm which in certain situations behaves differently depending on sets being larger than c S or not.
The bound c M ∈ O(k 2 ) improves the corresponding bound c M ∈ O(k 3 ) in [LPPS17]. However, the more significant extension of the construction in [LPPS17] is that in addition to the tree decomposition we also construct both an isomorphism-invariant graph of bounded forward-degree and depth and an isomorphism-invariant Γ k+1 -group associated with each bag.
The weight of a set S ⊆ V (G) with respect to a (weight) function w : For U ⊆ V (G) we define a weight function w U,k such that w U,k (u) = k for all u ∈ U and w U,k (v) = 1 for all v ∈ V \ U . Given a weight function w, using Menger's theorem and the Ford-Fulkerson algorithm it is possible to compute S L,R (w). The following lemma generalizes Lemma 3.2 of [LPPS17]. Through this generalization we obtain the adhesion bound O(k 2 ) for our decomposition.
Lemma 7. Let G be a graph, let S ⊆ V (G) be a subset of vertices, and let Proof. We proceed by induction on t. For t = 0 we have N (Z) ⊆ D = S, so the claim is trivial. Assume t ≥ 1 and define D ′ := S ∪ i∈[t−1] T i . Let Z be the vertex set of a connected component of G − D, and let Z ′ ⊇ Z be the vertex set of the connected component of G − D ′ containing Z. Let L t , R t ⊆ S be sets such that T t is a minimum weight (L t , R t )-separator with respect to w t . Let (A, B) be an (L t , R t )-separation with separator A ∩ B = T t . Without loss of generality we may assume that Z ⊆ A \ B. The three sets A\T t , T t , and B\T t partition V (G). Similarly the three sets V \(Z∪N (Z ′ )), N (Z ′ ) and Z ′ partition V (G). We define Q i,j to be the intersection of the i-th set of the first triple with the j-th set of the second triple. This way the sets Q i,j with i, j ∈ {1, 2, 3} partition V (G) into 9 parts as shown in Figure 1.
By the minimality of T t , we have w t (T t ) ≤ w t (Q 2,1 ∪ Q 2,2 ∪ Q 3,2 ), and as T t = Q 2,1 ∪ Q 2,2 ∪ Q 2,3 , this implies w t (Q 2,3 ) ≤ w t (Q 3,2 ). By Assumptions (1) and (2) of the lemma, it follows that The lemma can be used to extend a set of vertices S that is not a clique separator to a set D in an isomorphism-invariant fashion while controlling the size of the adhesions sets of the components of G − D. It will be important for us that we can also extend a labeling coset of S to a labeling coset of D and furthermore construct a graph of bounded forward-degree and depth associated with D and S. Lemma 8. Let k ∈ N and let G be a graph that is k-improved. Let S ⊆ V (G) and let Λ ≤ Label(S) be a labeling coset such that There is an algorithm that either correctly concludes that tw(G) > k, or finds a proper superset D of S and a labeling coset Λ ≤ Label(D) and a connected rooted graph H with the following properties:

The algorithm runs in time
Here, the output of an algorithm A is isomorphism-invariant if all isomorphisms between two input data (G, S, Λ, k) and (G ′ , S ′ , Λ ′ , k ′ ) extends to an isomorphism between the output (D, Λ, H) and (D ′ , Λ ′ , H ′ ) (An isomorphism between (G, S, Λ, k) and where we apply ϕ as defined in the preliminaries).
Proof. We consider two cases depending on the size of S.
We set w := w S,k+1 and then we have the following for every vertex set Z of a connected component of G − D by Lemma 7: The properties of D follow from similar arguments as in the first case. The fact that I is nonempty follows from the existence of a balanced separation (for details see [LPPS17]). Next, we show how to find Λ in both cases. To each x ∈ D \ S we associate the set A x := {(L, R) ∈ I | x ∈ S L,R }. Two vertices x and y occur in exactly the same separators if A x = A y . In this case we call them equivalent and write x ≡ y. Let A 1 , . . . , A t ⊆ D \ S be the equivalence classes of "≡". Since each x is contained in some separator of size at most k + 1 we conclude that the size of each A i is at most k + 1.
For each labeling λ ∈ Label(S) we choose an extension λ : (Recall that ≺ is the linear order of subsets of N as defined in the preliminaries). Inside each equivalence class A i , the ordering is chosen arbitrarily. Define Λ : By construction the coset Λ does not depend on the choices of the extensions λ. Since |A i | ≤ k + 1 for all 1 ≤ i ≤ t we conclude that Λ ∈ Γ k+1 , as desired.
It remains to explain how to efficiently compute Λ. For this we simply remark that is suffices to use a set of extensions M ⊆ Λ such that Λ is the smallest coset containing all elements of M (i.e., we can use a coset analogue of a generating set). We conclude that Λ can be computed in polynomial time in the size of I.
Last but not least, we show how to construct the graph H. The Case |S| ≤ c S is easy to handle. In this case we define H as the complete graph on the set D ∪ {r} where r is some new vertex, which becomes the root of H. The forward-degree of r is bounded by |D| which in turn is bounded by k O(1) . We consider the Case Since for each pair (L, R) there are at most |S| 2 different extensions (L ′ , R ′ ) with |L| + 1 = |R| + 1 = |L ′ | = |R ′ | and since each separator S L,R contains at most k + 1 vertices, we conclude that the forwarddegree of each vertex in H is bounded by |S| 2 + k + 1 ∈ k O(1) . Moreover, the depth of H is bounded by k + 3.
A labeled tree decomposition (T, β, α, η) is a 4-tuple where (T, β) is a tree decomposition and α is a function that maps each t ∈ V (T ) to a labeling coset α(t) ≤ Label(β(t)) and η is a function that maps each t ∈ V (T ) to a graph η(t).
The lemma can be used as a recursive tool to compute our desired isomorphisminvariant labeled tree decomposition.
Theorem 9. Let k ∈ N and let G be a k-basic graph and let v be a vertex of degree at most k. There is an algorithm that either correctly concludes that tw(G) > k, or computes a labeled tree decomposition (T, β, α, η) with the following properties.
(I) the width of (T, β) is bounded by c L , (II) the adhesion width of (T, β) is bounded by c M , (III) the degree of (T, β) is bounded by kc 2 L and the number of children of t with common adhesion set is bounded by k for each t ∈ V (T ), The algorithm runs in time 2 O(k 2 log k) |V (G)| O(1) and the output (T, β, α, η) of the algorithm is isomorphism invariant (w.r.t. G, v and k). Furthermore, if we drop Property (VII) as a requirement, the triple (T, β, η) can be computed in time Here, the output of an algorithm A is isomorphism-invariant, if all isomorphisms between two input data extend to an isomorphism between the output. More precisely, an isomorphism ϕ ∈ Iso((G, v, k), (G ′ , v ′ , k ′ )) extends to an isomorphism between between (T, β, α, η) and (T ′ , β ′ , α ′ , η ′ ) if there is a bijection between the tree decompositions ϕ T : V (T ) → V (T ′ ) and for each node t ∈ V (T ) a bijection between the vertices of graphs where we naturally apply ϕ as defined in the preliminaries. Furthermore, these extensions define an isomorphism between the output data, i.e. for all nodes t ∈ V (T ) we have that Proof. We describe a recursive algorithm A that has (G, S ⊆ V (G), Λ ≤ Label(S)) as the input such that the data satisfy the assumptions of Lemma 8. That is: The output is a labeled tree decomposition (T, β, α, η) with root bag S. Since G has no separating cliques and therefore v is not a cut vertex, the triple (G, {v}, {v → 1}) fulfills the input conditions which will complete the proof. The algorithm A works as follows.
Step 1: We describe how to construct β(t) = D and α(t) = Λ for the root node t ∈ V (T ).
Let Z 1 , . . . , Z r be the connected components of the graph G − D. Let S i := N G (Z i ) and Step 2: We describe how to construct the graph η(t) = H t . First, we compute the graph H as in Lemma 8. To achieve that pairs of vertices from β(t) are contained in this graph we define a Cartesian product Step 3: We call the algorithm recursively as follows. Let (This set is essentially only an isomorphism-invariant restriction of Λ to S i . The minimum is taken with respect to ≺, the ordering of subsets of N as defined in the preliminaries.) The image S λ i might be a set of natural numbers different from {1, . . . , |S i |}. To rectify this we let π i be the bijection from S λ i to {1, . . . , |S i |} that preserves the normal ordering "<" of natural numbers and set By possibly renaming the vertices of the trees T i , we can assume w.
Step 4: We define a labeled tree decomposition (T, β, α, η) as follows. Define a new root vertex t and attach the root vertices t 1 , . . . , t r computed by the recursive calls as children. We define β(t) := D and α(t) := Λ and η(t) := H t . Combine all decompositions (T i , β i , α i , η i ) together with the new root t and return the resulting decomposition (T, β, α, η).
(Correctness.) First of all, we show that (G i , S i , Λ i ) fulfills the Conditions 1-6 and the recursive call in Step 3 is justified. Condition 1 is clear. For 2 notice that D and Λ satisfy (A)-(D) from Lemma 8 regardless which option is applied in Step 1. Condition 2 then follows from (C). For 3 notice that G does not have any separating cliques, but S i is a separator. The Conditions 4 and 5 follow from the definition of G i and S i , whereas 6 follows from (D). Next, we show (I)-(V). The bound for the width in (I) immediately follows from (B), while the bound on the adhesion width in (II) follows from (C). For (III) observe that G is k-improved and therefore each non-edge in D is contained in at most k different S i , i.e., |{i | u, v ∈ S i }| ≤ k for each u, v ∈ D, uv / ∈ E(D). Therefore, r ≤ k|E(D)| ≤ kc 2 L . Moreover, since each S j contains a non-edge uv we conclude |{i | S i = S j }| ≤ |{i | u, v ∈ S i }| ≤ k. For (IV) we associate each bag β(t) = D with the set D \ S in an injective way. The number of sets D \ S occurring in each recursive call is bounded by |V (G)| since these sets are not empty and pairwise distinct. We conclude |V (T )| ≤ |V (G)|. Property (VII) follows from (D). For any bag not satisfying Property (V) we introduce a new bag containing all equal adhesion sets. For (VI) we observe that the forward-degree of the vertices (u, v) ∈ V (H 2 ) is the sum of the forward-degrees of u and v in H. The depth of H 2 is twice the depth of H. Therefore, we have fdeg(x) ∈ k O(1) for each x ∈ V (H t ) and depth(H t ) ≤ 2k + 7. The construction is obviously isomorphism invariant. . We need to explain how to compute Λ i from Λ. With standard group theoretic techniques, including the Schreier-Sims algorithm, one can find a minimal image of S i . Using set transporters one can find all labelings in Λ mapping to this minimal image. This algorithm runs in time |D| O(k) ⊆ 2 O(k 2 log k) . Since we are only interested in an isomorphism invariant restriction of Λ to S i , we could also use techniques from Section 7 as follows. We define a hypergraph X on the vertex set D consisting of one single hyperedge S i . Let Λ i := CL(X; Λ)| S i be the restriction of a canonical labeling of that hypergraph. This algorithm also runs in time |D| O(k) . This leads to a total run time of 2 O(k 2 log k) |V (G)| O(1) . We remark that the computation of Λ i from Λ is only needed if we require Property (VII). For the computation of a labeled tree decomposition (T, β, η) the bottleneck arises in Lemma 8 which gives a run time of Remark 10. We later use the isomorphism-invariance of the labeled tree decomposition (T, β, α, η) from the previous theorem in more detail. Let t ∈ V (T ) be a non-root node and let S ⊆ V (G) be the adhesion set to the parent node of t and let I t = (T t , β t , α t , η t ) be the decomposition of the subtree rooted at t and G t the graph corresponding to I t . Then η t is isomorphism-invariant w.r.t. T t , β t , G t and S.

Coset-Hypergraph-Isomorphism
After having computed isomorphism-invariant tree decompositions in the previous sections we now want to compute the set of isomorphisms from one graph to another in a bottom up fashion. Let G 1 , G 2 be the two input graphs and suppose we are given isomorphisminvariant tree decompositions (T 1 , β 1 ) and (T 2 , β 2 ). For a node t ∈ V (T i ) we let (G i ) t be graph induced by the union of all bags contained in the subtree rooted at t. The basic idea is to compute for all pairs t ∈ V (T 1 ), t ′ ∈ V (T 2 ) the set of isomorphisms from (G 1 ) t to (G 1 ) t ′ (in addition the isomorphisms shall also respect the underlying tree decomposition) in a bottom up fashion.
The purpose of this section is to give an algorithm that solves this problem at a given bag (assuming we have already solved the problem for all paris of children of t and t ′ ). Let us first give some intuition for this task. Suppose we are looking for all bijections from β 1 (t) to β 2 (t ′ ) that can be extended to an isomorphism from (G 1 ) t to (G 2 ) t ′ . Let t 1 , . . . , t ℓ be the children of t and t ′ 1 , . . . , t ′ ℓ the children of t ′ . Then we essentially have to solve the following two problems. First, we have to respect the edges appearing in the bags β 1 (t) and β 2 (t ′ ). But also, every adhesion set β(t) ∩ β(t i ) has to be mapped to another adhesion set β(t ′ ) ∩ β(t ′ j ) in such a way that the corresponding bijection (between the adhesion sets) extends to an isomorphism from (G 1 ) t i to (G 2 ) t ′ j . In order to solve this problem we first consider the case in which the adhesion sets are all distinct and define the following abstraction.
In this case we call ϕ an isomorphism of the instance I. Moreover, let Iso(I) be the set of all isomorphisms of I. Observe that property (N) describes a consisteny condition: if we can use σ 1 to map S 1 to S 2 , σ 2 to map S ′ 1 to S 2 , and σ 3 to map S ′ 1 to S ′ 2 , then mapping σ 1 σ −1 2 σ 2 can be used to map S 1 to S ′ 2 . As a result the set of all isomorphisms of the instance I forms a coset, that is Iso(I) = Θϕ for some Θ ≤ Sym(V 1 ) and ϕ ∈ Iso(I).
In the application in the main recursive algorithm, the sets V i = β(t i ), the hyperedges S i are the adhesion sets of t i (and we will also encode the edges appearing in the bag in this way), and the cosets Θ S 1 τ S 1 ,S 2 tell us which mappings between the adhesion sets S 1 and S 2 extend to an isomorphism between the corresponding subgraphs. The colorings χ 1 are used to indicate which subgraphs can not be mapped to each other (and also to distinguish between the adhesion sets and egdes of the bags which will both appear in the set of hyperedges).
The next Lemma gives us one of the central subroutines for our recursive algorithm.
Lemma 11. Let I = (V 1 , V 2 , S 1 , S 2 , χ 1 , χ 2 , F, f) be an instance of coset-hypergraph-isomorphism. Moreover, suppose there are isomorphism-invariant rooted graphs H 1 = (W 1 , E 1 , r 1 ) and H 2 = (W 2 , E 2 , r 2 ) such that Here, isomorphism-invariant means that for every isomorphism ϕ ∈ Iso(I) there is an The proof of this lemma is based on the following theorem. A rooted tree T = (V, E, r) is d-ary if every node has at most d children. An expanded rooted tree is a tuple (T, C) where T = (V, E, r) is a rooted tree and C : L(T ) 2 → rg(C) is a coloring of pairs of leaves of T (L(T ) denotes the set of leaves of T ). Isomorphisms between expanded trees (T, C) and (T, C ′ ) are required to respect the colorings C and C ′ .
We construct a rooted 2d-ary tree T i as follows. Let V (T i ) be the set of all branches of For a sequence of vertices v = (v 1 , . . . , v k ) let last(v) = v k be the last entry of the tuple v. Let χ ) for all v where last(v) ∈ S i , and χ ′ i (v) = 0 for all other tuples. Let Γ i := Aut(T i , χ ′ i ). Also let γ 1→2 be an isomorphism from (T 1 , χ ′ 1 ) to (T 2 , χ ′ 2 ) (if no such isomorphism exists then Iso(I) = ∅ and we are done). Let . Now let γ ∈ Γ 1 γ 1→2 be an isomorphism from (T 1 , χ ′ 1 ) to (T 2 , χ ′ 2 ). Then, for every w ∈ B 1 the isomorphism γ induces a bijection γ w : last(w) → last(w γ ) which is induced by how γ maps A 1 (w) to A 2 (w γ ). Now let Observe that the set indeed forms a coset due to property (N). Moreover, a representation for Γ ′ 1 γ ′ 1→2 can be computed in time polynomial in |V (T 1 )| since the group Γ 1 acts independently as a symmetric group on all the sets A 1 (w).
Observe that, up to now, we have not enforced any consistency between the maps γ w . Indeed, there may be elements w, w ′ ∈ B 1 such that last(w) = last(w ′ ) but γ w = γ w ′ . To finish the proof we need to enforce such a consistency property. Then every isomorphism γ ∈ Γ ′ 1 γ ′ 1→2 that fulfills the consistency property naturally translates back to an isomorphism of I. For (3) C 2 )}. By Theorem 12 a representation for this coset can be computed in time 2 O(h·log c d) for some comstant c. We claim that every γ ∈ Γ * 1 γ * 1→2 naturally defines an isomorphism of I and conversely, every isomorphism of I can be described like this.

1→2
it holds that last(v γ ) = last((v ′ ) γ ) by the same argument. With this, we obtain that γ V 1 is indeed an isomorphism of I. The hyperedges S 1 and S 2 are encoded in the tree structure (and they have to be mapped to each other by the coloring χ ′ i ) and the coloring of hyperedges is encoded in the coloring χ ′ i which has to be preserved. Also, when mapping an element w ∈ B 1 to another element w γ ∈ B 2 the children have to mapped to each other in such a way that the corresponding bijection lies in the corresponding coset. So overall γ V 1 is an isomorphism of I.
On the other hand, every isomorphism ϕ ∈ Iso(I) extends naturally to an isomorphism from H 1 to H 2 and thus, it also extends to an isomorphism from H ′ 1 to H ′ 2 and from T 1 to T 2 , since all relevant objects are defined in an isomorphism-invariant way. Hence, from a representation for Γ * 1 γ * 1→2 we can easily compute a representation for Iso(I).
Looking at the properties of the tree decompositions computed in Theorem 6 and 9 we have for every node t that either the adhesion sets to the children are all equal or they are all distinct. Up to this point we have only considered the problem that all adhesion sets are distinct (i.e. the coset-hypergraph-isomorphism problem). Next we consider the case that all adhesion sets are equal. Towards this end we define the following variant.
The set Iso(I) is defined analogously. for some constant c.
Proof. The first run time can be achieved by brute force in the following way. We iterate through all ϕ : V 1 → V 2 and check in polynomial time if a π ∈ Sym(t) exists that satisfies (1) and (2). (This can be done by computing, for every i ∈ [t], the set A i of those j ∈ [t] such that ϕ ∈ Θ i τ i,j . Then one needs to find a permutation π ∈ Sym(t) such that π(i) ∈ A i for all i ∈ [t]. This can be interpreted as a matching problem.) The results is the union of all these ϕ. However, for the second run time we iterate through all π ∈ Sym(t) satisfying (1) and compute all corresponding ϕ : V 1 → V 2 satisfying (2) which in turn can be done by iterated coset-intersection. The result is Iso(I) = π∈Sym(t) satisfying (1) i∈[t] Θ i τ i,π(i) . Coset-intersection can be done in quasi-polynomial time [Bab16]. Here, isomorphism invariant means that every isomorphism ϕ ∈ Iso(H 1 , H 2 ), which naturally restricts to an isomorphism from G 1 to G 2 , can be extended to an isomorphism from H ′ 1 to H ′ 2 .
Proof. Let G (0) = G and for i > 0 let Since G has tree width at most k it follows that there is some i * > 0 such that G (i * ) is the empty graph. For every clique C ⊆ D we define i(C) to be the maximal i ∈ N such that C ⊆ V (G (i) ). Moreover, let a(C) = C \ V (G (i(C)+1) ). Observe that a(C) = ∅ and for every v ∈ a(C) it holds deg For a set S we define the rooted graph L S to be the graph associated with the subset lattice of S, that is, L S = (Pow(S), E S , ∅) where AB ∈ E S if A ⊆ B and |B \ A| = 1. Now let H ′ be the following graph. For every v ∈ D we attach the graph L A(v) to the vertex v ∈ V (H), that is, the root node ∅ ∈ V (L A(v) ) is connected to the vertex v. It can be easily verified that H ′ satisfies all requirements. Observe that C ⊆ A(v) for every v ∈ a(C) where C is a clique of G.
Theorem 15. Let k ∈ N and let G 1 , G 2 be connected graphs. There is an algorithm that either correctly concludes that tw(G 1 ) > k, or computes the set of isomorphisms Proof. We describe a dynamic programming algorithm A that has an input (I 1 , I 2 ) where I j = (G j , S j , T j , β j , η j ) where G j is a graph, (T j , β j ) is a tree decomposition of the graph, S j ⊆ V (G j ) is a subset of the vertices contained in the root bag, and η j is a (partial) function that assigns nodes t j ∈ V (T j ) a graph η(t j ) which is isomorphism invariant w.r.t T j,t j , β j,t j , G j,t j and S j,t j as in remark 10. The isomorphisms Iso(I 1 , I 2 ) are all isomorphisms ϕ : V (G 1 ) → V (G 2 ) from (G 1 , S 1 ) to (G 2 , S 2 ) for which there is a bijection between the nodes of the trees π : V (T 1 ) → V (T 2 ) such that for all t ∈ V (T 1 ) we have that ϕ(β 1 (t)) = β 2 (π(t)). The algorithm computes a coset A(I 1 , I 2 ) = Iso(I 1 , I 2 ). In our recursive procedure we maintain the following properties of the tree decomposition for each unlabeled bag β j (t j ) (η j (t j ) = ⊥).
] is cliqueseparator free, and (U2) Each adhesion set of t j and also S are cliques in G k j .
And for each labeled bag β j (t j ) we require the following.
(L1) The cardinality |β j (t j )| is bounded by c L , The initial input of A consists of the graphs G 1 , G 2 together with their canonical (unlabeled) clique separator decompositions (T j , β j ) of their k-improved graphs G k j from Theorem 6. For S j we choose the empty set. Since the clique separator decomposition is canonical we have Iso(I 1 , I 2 ) = Iso(G 1 , G 2 ) and therefore the algorithm computes all isomorphisms between G 1 and G 2 .

Description of A:
For j = 1, 2 let t j1 , . . . , t jℓ be the children of t j and let (T ji , β ji , η ji ) be the decomposition of the subtree rooted at t ji . Let G ji be the graph corresponding to (T ji , β ji , η ji ). Let V ji := V (G ji ) and let S ji := β j (t j ) ∩ V ji be the adhesion sets of the children, let Z ji be V ji \ S ji , and let I ji := (G ji , S ji , T ji , β ji , η ji ). We assume that the isomorphisms A(I 1i , I 2i ′ ) have already been computed via dynamic programming.
We have to consider two cases depending on the root t j ∈ T j .
Case β j (t j ) are both unlabeled: Let v 1 be a vertex in β 1 (t 1 ) of degree at most k in G k 1 [β 1 (t 1 )] and compute the canonical labeled tree decomposition ( , v 2 ) from Theorem 9. Notice that the bags of (T ′ j , β ′ j , η ′ j ) satisfy (L1)-(L4), because in the case tw(G j ) ≤ k, the k-improvement does not increase the tree width as seen in Lemma 5(2). Notice that the adhesion sets S ji and S j are cliques in G k j and these cliques must be completely contained in one bag. We attach the children (T ji , β ji , η ji ) to (T ′ j , β ′ j , η ′ j ) by adding them to the highest possible bag and we choose a new root as the highest possible node r j ∈ V (T ′ j ) such that S j ⊆ β ′ j (r j ). By doing this, we obtain (T ′′ j , β ′′ j , η ′′ j ). We need to recompute η ′′ j (s j ) for all nodes s j ∈ V (T j ) where new children are attached to preserve Property (L2). We call the algorithm in Lemma 14 with the input G j [β j (s j )], η ′′ j (s j ) and obtain η ′′′ j (s j ). Finally, we obtain (T ′′ j , β ′′ j , η ′′′ j ) and define I ′ j := (G, S, T ′′ j , β ′′ j , η ′′′ j ). We show that (L1)-(L4) remains satisfied. By possibly introducing new bags we can preserve Property (L3): The adhesion sets are either pairwise different or all equal. We can preserve Property (L4). Consider a bag s j in which all adhesion sets are equal and where β ′′ j (s j ) is not a clique in G k j . Then the children are not any of the attached children t j1 , . . . , t jℓ and therefore the number of children of s j remains bounded by c M .
For each of the vertices v 2 ∈ β 2 (t 2 ) we compute the isomorphisms A(I ′ 1 , I ′ 2 (v 2 )) recursively. We return the smallest coset that contains the union v 2 ∈β 2 (t 2 ) Iso(I ′ 1 , I ′ 2 (v 2 )). Case β j (t j ) are both labeled: We consider two cases depending whether the adhesion sets of t j are all different or not.
If all adhesion sets are different, we use the algorithm from Lemma 11 as follows. We encode the isomorphism problem Iso(I 1 , I 2 ) as an instance of coset-hypergraphisomorphism. First, we encode the tree decomposition as where F, f are the isomorphisms between the children of t 1 and the children of t 2 restricted to their adhesion sets. We can easily construct F, f with the isomorphisms A(I 1i , I 2i ′ )| S 1i that have already been computed. The colorings χ i are defined as follows. Two S 1i and S 2i ′ get assigned the same color (i.e. χ 1 (S 1i ) = χ 2 (S 2i ′ )) if and only if the set of isomorphisms A(I 1i , I 2i ′ ) is not empty. Since F, f consist of isomorphisms the consistency property N is satisfied. Next, we encode the edge relation of edges contained in the root bag as I ′ = (β 1 (t 1 ), β 2 (t 2 ), E(β(t 1 )) ∪ To construct F ′ , f ′ we define for all edges e 1 ∈ E(β 1 (t 1 )), e 2 ∈ E(β 2 (t 2 )) the allowed isomorphisms Θ e 1 τ e 1 ,e 2 as the set of bijections between β 1 (t 1 ) and β 2 (t 1 ) that map e 1 to e 2 . Moreover, the allowed isomorphisms Θ S 1 τ S 1 ,S 2 is the set of bijections between β 1 (t 1 ) and β 2 (t 1 ) that map S 1 to S 2 . We define χ 1 , χ 2 as a coloring mapping all edges to the integer 0 and mapping S 1 and S 2 to the integer 1. Finally, we combine both instances I and I ′ to obtain I ′′ and compute the isomorphisms Iso(I ′′ ) by the algorithm in Lemma 11. We extend the isomorphisms to the whole graph and define and return Iso( If all adhesions sets are equal, the procedure is analogous, but we compute Iso(I ′′ ) by calling the algorithm from Lemma 13.
Next, consider the second case in which all adhesion sets are equal. Assume that β j (t j ) is not a clique in G k j . Then by Property (L4) the cardinality |β j (t j )| is bounded by c M and the number of children of t j is bounded by k. In this case we have that |F| ≤ k for our subroutine which leads to a run time |F|! O(1) 2 O(log c (|β 1 (t 1 )|)) ⊆ 2 O(k log k) . In the case where β j (t j ) is a clique in G k j we have that |β j (t j )| ≤ k + 1 and |F| ≤ |V (G j )|. This leads to a run time of (|V 1 |!|F|) O(1) ⊆ 2 O(k log k) |V (G 1 )| O(1) . It remains to explain how the coset Iso(I ′′ ) can be constructed in polynomial time. The cosets are colored according to the isomorphism types of the graphs G ji which ensures property N2. Let P = P 1 · ∪ . . . · ∪ P p be a partition of [ℓ] into isomorphism classes, i.e. i, j ∈ P s if and only if Θ i τ i,k = Θ j τ j,k for some (and due to property N2 for all) k ∈ [ℓ]. Now, for each isomorphism ϕ ′′ ∈ Iso(I ′′ ) there is a unique coset Π of Sym(P 1 ) × . . . × Sym(P p ) such that ϕ ′′ ∈ Iso(I 1i , I 2π(i) )| β 1 (t 1 ) for all π ∈ Π and therefore it suffices to extend ϕ using generators for Iso(I 1i , I 2π(i) ) and Π.

Canonization
In this section we adapt our techniques to obtain an algorithm which computes a canonization for a given graph of tree width at most k. Since Babai's quasi-polynomial time algorithm [Bab16] only tests isomorphism of two given input graphs and can not be used for canonization purposes, our canonization algorithm has a slightly worse running time. However, our canonization algorithm still significantly improves on the previous best due to Lokshtanov, Pilipczuk, Pilipczuk, and Saurabh [LPPS17].
One of the main tasks for building the canonization algorithm out of our isomorphism test is to adapt Lemma 11. To achieve this we shall use several group theoretic algorithms concerned with canonization. We start by giving the necessary background.

Background on canonization with labeling cosets
Two graphs graphs G and H are called isomorphic with respect to a group ∆ ≤ Sym(V (G)), if there is a bijection δ ∈ ∆ such that G δ = H. In this case we write G ∼ = ∆ H. By Aut ∆ (G) we denote the automorphism group of a graph G restricted to ∆, i.e., all δ ∈ ∆ such that G δ = G.
In the following let X denote a class of graphs, closed under isomorphisms. For the purpose of recursion, it is usually more convenient to compute the entire coset of canonical labelings rather than just a canonical form. These conditions imply that the assignment of G π for an arbitrary π ∈ CL(G; ∆) is independent of the choice of π and that G π is a canonical form of G with respect to ∆, justifying the name.
Above we made the assumption that V is a fixed linearly ordered set. We can drop this assumption and can define canonical labelings for arbitrary vertex sets as seen next. For a labeling coset τ ∆ ≤ Label(V (G)) we define CL(G; τ ∆) to be the set τ CL(G τ ; ∆) which is well defined due to Property (CL2). In general, a canonical form CF for a graph G over an arbitrary (not necessary ordered) vertex set V is a function such that CF(G) ∼ = G for all G ∈ X , and G ∼ = H implies CF(G) = CF(H) for all G, H ∈ X . Notice that G π defines such a canonical form for some π ∈ CL(G; Label(V (G))). An algorithm to compute CL(G; Label(V (G))) for a graph of tree width at most k will be present in the last section.
The composition-width of a coset τ ∆, denoted cw(τ ∆) is the smallest integer k ∈ N such that τ ∆ ∈ Γ k , that is, every non-Abelian composition factor of ∆ is isomorphic to a subgroup of Sym(k). The composition width of a collection of cosets cw(S) is the maximum composition width among all elements of S. Let ω(n) be the smallest function such that, if ∆ ≤ Sym(X) is primitive, then |∆| ≤ |X| ω(cw(∆)) .
It is actually known that ω(n) ∈ O(n) as stated in [BKL83], see [LS99]. Analogously, for a hypergraph X we first define the canonical labelings with respect to a group and a start segment of N as the vertex set. Meaning CL(X; ∆) satisfies (CL1)-(CL3) with X in place of G. Then for graphs on arbitrary vertex set and a given labeling coset we define CL(X; ρ∆) to be the set ρ CL(X ρ ; ∆).
We describe several polynomial time operations that can used in general when dealing with labeling cosets of a set of natural numbers.
Let τ 1 , τ 2 , . . . , τ t be a set of bijections with the same domain and range. We denote by τ 1 , τ 2 , . . . , τ t the smallest coset containing all τ i . This coset can be computed in polynomial time (see for example Lemma 16 of the arXiv version of [GS15]).
As before, we extend the canonical labelings to arbitrary (not necessary ordered) vertex sets. For a labeling coset τ ∆ ≤ Label(V ) we write CL(X; τ ∆) for τ CL(X τ ; ∆). This is well defined due to Property (CL2).
We are now ready to formulate the analogue of Lemma 11 for the canonization algorithm.
So we can assume in the following that ∆ preserves S and χ, i.e, S δ = S and χ δ = χ for all δ ∈ ∆. Let U be the set of pairs {(S, s) | S ∈ S, s ∈ S}. We can think of U as the disjoint union of all sets S ∈ S. For notational convenience we define U S := {S} × S.
Next we define a labeling ∆ on the disjoint union V ∪ U . Roughly speaking, we define a labeling on V ∪ U that orders V according to a δ ∈ ∆ and orders the sets U S according to the ordering of the sets S δ . Inside the set U S the vertices are ordered according to some ρ S ∈ τ S Θ S . More formally, we define ∆ to be the labeling of V ∪ U consisting of the labelings δ for which there are ρ S ∈ τ S Θ S .
Consider the bipartite graph Y defined on V ∪U by connecting v and (S, v) for each S ∈ S for which v ∈ S. Return the canonical labeling coset of the graph Y restricted to V , i.e., CL(Y ; ∆)| V . (Canonical labeling.) We argue that CL(Y ; ∆) restricted to V is a canonical labeling coset of (X; ∆).
(CL1) By definition, all elements of ∆ restricted to V are in ∆.
(CL2) We consider the result of applying the algorithm to (X δ ; ∆) for any δ ∈ ∆. In the case that ∆ does not preserve S and χ, the algorithm returns δ −1 τ ∆ ′ . So assume that ∆ preserves S and χ already, In this case the definition of V ∪ U remains unchanged since ∆ preserve S. In place of ∆, the algorithm computes ∆ δ . In Place of Y the algorithm computes Y δ . But then the result of the computation is CL( (CL3) Suppose δ, δ ′ ∈ CL(Y ; ∆) and δ| V = δ and δ ′ | V = δ ′ . We need to show that δδ ′−1 is an automorphism of X. Since δ, δ ∈ ∆, it is clear that δδ ′−1 preserves S and χ. It remains to show that δδ ′−1 is compatible with F. In other words, we need to show that F δ = {δ −1 τ S Θ S | S ∈ S} and F δ ′ = {δ ′ −1 τ S Θ S | S ∈ S} are actually the same set.
Choose S ∈ S. Let S ′ be the element of S for which S δ = S ′δ ′ . Such an element exists and is unique. Since χ is preserved we have Θ S = Θ S ′ and therefore it suffices to show Consider the graph Y δ = Y δ ′ . Let γ S be the map from S δ to (U S ) δ that maps each v δ ∈ S δ to (S, v) δ . Similarly let γ ′ S ′ be the map from S ′ to (U S ′ ) δ ′ = (U S ) δ that maps each v δ ′ ∈ S ′δ ′ to (S ′ , v) δ ′ . In the graph Y δ , for s ∈ S δ we have that s γ S is the only vertex in (U S ) δ that is a neighbor of s. Similarly, in Y δ ′ = Y δ , we have that s γ ′ S ′ is the only vertex in (U S ′ ) δ ′ that is a neighbor of s. It follows that γ S = γ ′ S ′ . By construction of ∆ we know that δγ S = ρ S + m for some ρ S ∈ τ S Θ S and some integer m. Similarly δ ′ γ ′ S ′ = ρ ′ S ′ + m ′ for some ρ ′ S ′ ∈ τ ′ S ′ Θ S ′ and some integer m. In fact, it must be the case that m = m ′ since (U S ′ ) δ ′ = (U S ) δ . We conclude that δδ ′−1 = δγ S γ ′−1 S ′ δ ′−1 = ρ S ρ ′−1 S ′ . Therefore δδ ′−1 τ ′ S ′ Θ S = τ S Θ S as desired. We also need a second combinatorial subproblem that handles the case when V is small but the family F is possibly large (this is analogue to multiple-colored-coset-isomorphism and Lemma 13).
For a map ϕ : V → V ′ we define (V, F, χ) ϕ analogously to before. Similarly the automorphism and canonical labelings of (V, F, χ) are defined analogously to above.
We are now ready to formulate a lemma that is the analogue of Lemma 11, but with a weaker run time since Babai's quasi-polynomial time result does not lead to canonization yet.
Lemma 24. There is an algorithm that computes a canonical labeling of a pair (X; τ ∆) consisting of a set with multiple colored labeling cosets X = (V, F, χ) and a labeling coset τ ∆ ≤ Label(V ) which has a running time of (|V |!|F|) O(1) .
For each labeling δ ∈ ∆ we do the following. Consider the sets of the form δ −1 τ i Θ i . We order these sets so that where ≺ is the ordering of coset labelings of {1, . . . , n} defined in Section 7. By Corollary 22 this ordering can be computed in polynomial time. For every δ we get an ordered sequence δ −1 τ i 1 Θ i 1 , . . . , δ −1 τ it Θ it .
Let {δ 1 , . . . , δ s } be the collection of those δ for which this ordered sequence is lexicographically minimal. Then we let δ 1 , . . . , δ s be the output of the algorithm.
It follows from the construction that δ 1 , . . . , δ s satisfies the properties of a canonical labeling coset.
By Corollary 22, for each δ the time requirement of the algorithm is polynomial in |F| and |V |. There are at most |V |! many elements in ∆, and thus at most equally many choices for δ, giving us the desired time bound.

The canonization algorithm
Finally, we have assembled all the tools to describe an algorithm that canonizes graphs of bounded tree width.
Theorem 25. Let k ∈ N and let G be a connected graph. There is an algorithm that either correctly concludes that tw(G) > k, or computes a canonical labeling coset CL(G; Label(V )) in time 2 O(k 2 log k) |V (G)| O(1) .
We remark that the algorithm is closely related to the one described in Theorem 15. In the isomorphism-algorithm the graph η(t) serves as a tool to exploit the structure of each bag t. As the isomorphism-techniques depend on Babai's quasi-polynomial time result which does not extend to canonization yet, we will now use the fact that additionally each bag can be guarded with a labeling coset α(t) of bounded composition-width. The labeling coset α(t) serves a tool for efficient canonization. The main change of the algorithm therefore arises in (L2).
Proof. We describe a dynamic programming algorithm A with input I = (G, S, T, β, α) where (T, β) is a tree decomposition of a graph G and S ⊆ V (G) is a subset of the vertices contained in the root bag, and α is a (partial) function that maps nodes t ∈ V (T ) to labeling cosets α(t) ≤ Label(β(t)). The algorithm computes a labeling coset A(I) such that (CL1) A(I) ≤ Label(V (G)) and A(I)| S ≤ Label(S), and (CL2) A(I) = τ A(I τ ) for all τ ∈ Label(V (G)), and (CL3) Aut(G, S, T, β, α)π ⊆ A(I) ⊆ Aut(G)π for some (and thus for all) π ∈ A(I).
In our recursive procedure we maintain the following properties of the tree decomposition for each unlabeled bag β(t) (α(t) = ⊥).
(U1) The graph G k [β(t)] is cliqueseparator free, and (U2) Each adhesion set of t and also S are cliques in G k .
For each labeled bag β(t) we require the following. The initial input of A is the canonical clique separator decomposition (T, β) of the k-improved graph G k from Theorem 6. For S we choose the empty set. Since the clique separator decomposition is canonical we have Aut(G, S, T, β, ⊥) = Aut(G) and therefore the algorithm computes a canonical labeling coset of G.

Description of A:
Let t 1 , . . . , t ℓ be the children of t and let (T i , β i , α i ) be the decomposition of the subtree rooted at t i . Let G i be the graph corresponding to (T i , β i , α i ). Let V i := V (G i ), let S i := β(t) ∩ V i be the adhesion sets of the children, and let Z i be V i \ S i . We assume that the canonical labeling subcosets τ i Θ i := A(G i , S i , T i , β i , α i ) have already been computed via dynamic programming.
We have to consider two cases depending on the root t ∈ T .
Case β(t) is unlabeled: For each vertex v ∈ β(t) of degree at most k in G k [β(t)] we compute the canonical coset-labeled tree decomposition (T ′ , β ′ , α ′ ) of (G k [β(t)], v) from Theorem 9. Notice that the bags of (T ′ , β ′ , α ′ ) satisfy (L1)-(L4), because in the case tw(G) ≤ k, the k-improvement does not increase the tree width as seen in Lemma 5(2). Notice that the adhesion sets S i are cliques in G k and these cliques must be completely contained in one bag. We attach the children (T i , β i , α i ) to (T ′ , β ′ , α ′ ) adding them to the highest possible bag and we choose a new root as the highest possible node r ∈ V (T ′ ) such that S ⊆ β ′ (r). By doing this, we obtain (T ′′ , β ′′ , α ′′ ). We ensure Property (L2) because the number of children attached to one bag can be bounded by the number of cliques in G k that contains the bag. The number of cliques again can be bounded by 2 k c L which is a consequence of Lemma 14. By possibly introducing new bags we can preserve Property (L3): The adhesion sets are either pairwise different or all equal. Since the adhesion sets S i are cliques in G k and therefore their size is bounded by k + 1, we also preserve Property (L4).
For each v we compute Θ v := A(G, S, T ′′ , β ′′ , α ′′ ) recursively. For each v we compute the canonical form obtained by applying an arbitrary element of Θ v to the graph. Let M be those v for which the obtained canonized graph is minimal with respect to lexicographic comparison of the adjacency matrix. Then we return the smallest coset containing v∈M Θ v .
Compute a partial linear order on the graphs G i by comparing the resulting adjacency matrices of G τ i i lexicographically (Notice that the order does no depend on the representative τ i ). Define χ : {S 1 , . . . , S ℓ } → {1, . . . , h} according to this order where h is the number of equivalence classes. We refine χ such that χ(S i ) = χ(S j ) implies Θ i = Θ j . If all adhesion sets are different, we compute a canonical labeling coset Λ of the set β(t) by applying Lemma 23 to the input X = ((β(t), {S i }, {τ i Θ i | S i }, χ); ψ∆). Otherwise, if all adhesion sets are equal, we compute Λ by applying the algorithm of Lemma 24 to the input X = ((β(t), {τ i Θ i | β(t) }, χ); ψ∆). Notice that Property (CL1) allows us to restrict τ i Θ i to S i .
We describe a canonical labeling coset of G.
For each λ ∈ Λ we define extensions to V (G) as follows. For each i we define τ ′ i Θ ′ i to be the subcoset of those maps ρ i ∈ τ i Θ i for which λ −1 ρ i is minimal. (In fact, we have to restrict these maps to fit together (λ −1 | S λ i )(ρ i | S i )). In the case that all adhesions are different, we define Λ λ to be the set of labelings λ of V (G) for which there are we conclude that λλ ′−1 preserves the edge relation E(β(t)). With the same argument λλ ′−1 preserves S. Exemplarily, we explain the case when all adhesion sets are different. We have I λ = I λ ′ and therefore λλ ′−1 preserves {S i }, {τ i Θ i | S i } and χ. So assume that λλ ′−1 maps S i to S j . It remains to show that λ λ ′−1 is an isomorphism from G i to G j . By construction we have λ| Z i = ρ i + m and λ ′ | Z j = ρ ′ j + m ′ for ρ i ∈ τ ′ i Θ ′ i , ρ j ∈ τ ′ j Θ ′ j . In fact it must be the case that m = m ′ , because the labeling of λ, λ ′ is ordered according to the S λ i = S λ ′ j as required in (2). Since m = m ′ we conclude λ| Z i ( λ ′ | Z j ) −1 = ρ i | Z i (ρ ′ j | Z j ) −1 . Since λλ ′−1 preserves {τ i Θ i | S i } we conclude λ −1 τ i Θ i | S i = λ ′−1 τ j Θ j | S j and we get λ −1 ρ i | S i = λ ′−1 ρ j | S j by the minimality of the elements in τ ′ i Θ ′ i and τ ′ j Θ ′ j . This gives us Since χ is preserved, we know that that G ρ i i = G ρ j j and therefore G λ λ ′−1 i = G j which means that λ λ ′−1 is an isomorphism.
(Running time.) Due to dynamic programming the number of calls is polynomial in |V (G)|. More precisely, for each bag of the clique separator decomposition, we construct a coset-labeled tree decomposition and both have polynomial many bags. In the first case the construction of the coset-labeled tree decomposition from Theorem 9 takes time 2 O(k 2 log k) |V (G)| O(1) . Consider the Case "β(t) is labeled" in which all adhesion sets are different. By Property (L1) of the bag size of β(t) is bounded by c L and by Property (L2) the number of children is bounded by kc 2 L + 2 k c L . By Property (L2) we know that cw(α(t)) ≤ k+1 and also cw(τ i Θ i | S i ) ≤ k+1 since τ i Θ i | S i is a subcoset of α(t i )κ. Therefore the canonization algorithm for the hypergraph with coset-labeled hyperedges in Lemma 23 runs in time (c L (kc 2 L + 2 k c L )) O(max{cw(α(t)),cw(α(t i ))}) ⊆ 2 O(k 2 log k) . Next, consider the second case in which all adhesion sets are equal. In this case, we have that the bag size of β(t) is bounded by c M due to Property (L3) of our coset-labeled tree decomposition from Theorem 9. Therefore the canonization algorithm for the multiple colored cosets in Lemma 24 runs in time c M !|V (G)| O(1) ⊆ 2 O(k 2 log k) |V (G)| O(1) .