Computational Topology (Jeff Erickson) Treewidth
Or il y avait des graines terribles sur la planète du petit prince . . . c’étaient les graines
de baobabs. Le sol de la planète en était infesté. Or un baobab, si l’on s’y prend trop
tard, on ne peut jamais plus s’en débarrasser. Il encombre toute la planète. Il la perfore
de ses racines. Et si la planète est trop petite, et si les baobabs sont trop nombreux, ils
la font éclater.
[Now there were some terrible seeds on the planet that was the home of the little
prince; and these were the seeds of the baobab. The soil of that planet was infested with
them. A baobab is something you will never, never be able to get rid of if you attend to
it too late. It spreads over the entire planet. It bores clear through it with its roots. And
if the planet is too small, and the baobabs are too many, they split it in pieces.]
— Antoine de Saint-Exupéry (translated by Katherine Woods)
Le Petit Prince [The Little Prince] (1943)
11 Treewidth
In this lecture, I will introduce a graph parameter called treewidth, that generalizes the property of
having small separators. Intuitively, a graph has small treewidth if it can be recursively decomposed into
small subgraphs that have small overlap, or even more intuitively, if the graph resembles a ‘fat tree’.
Many problems that are NP-hard for general graphs can be solved in polynomial time for graphs with
small treewidth. Graphs embedded on surfaces of small genus do not necessarily have small treewidth,
but they can be covered by a small number of subgraphs, each with small treewidth. This covering can
be used to develop efficient algorithms (either exact or approximate) for a huge number of problems
on surface graphs that are NP-hard for general graphs. As an example of this technique, I’ll describe a
polynomial-time approximation scheme for the maximum independent set problem.
11.1 Definitions
The concept of treewidth was discovered independently by several different researchers and given
several different names. The actual term ‘treewidth’ and its definition in terms of tree decompositions
were introduced by Robertson and Seymour [15]. Almost simultaneously, Arnborg and Proskurowski
independently began the systematic study of partial k-trees [3, 2, 1]. Both groups were apparently
unaware of Bertelè and Brioschi’s earlier equivalent definition of the dimension1 of a graph [6], or
Halin’s related study of S-functions [13]. Other equivalent definitions are surveyed by Bodlaender [8, 9].
A tree decomposition (T, X ) of a graph G = (V, E) consists of a tree T = (I, F ) and a function
X : I → 2V satisfying three constraints. To avoid confusion, I will always refer to vertices of G, but nodes
of T . We say that a vertex v is associated with a node i, or vice versa, whenever v ∈ X (i).
• Every vertex in G is associated with at least one node in T . More formally, we have i∈N X (i) = V .
S
• For every edge uv in G, at least one node in T is associated with both u and v.
• The nodes in T associated with any vertex of G define a subtree (connected subgraph) of T .
Equivalently, X (i) ∩ X (k) ⊆ X ( j) for every node j on the path from node i to node k in T .
The width of a tree decomposition is maxi |X (i)| − 1. Finally, the treewidth of G is the minimum width
of any tree decomposition of G. A single graph can have several tree decompositions of minimum width.
Conversely, let S = {S1 , S2 , . . . , Sn } be a set of subtrees of a tree T . The intersection graph I(S ) is
the graph with vertices {1, 2, . . . , n}, where two vertices i and j are joined by an edge if and only if Si
and S j share a node in T . The depth of S is the maximum number of subtrees that share any node in T ,
1
Erdős, Harary, and Tutte defined the dimension of a graph to be the minimum dimension of a Euclidean space that allows
an embedding where every edge is a line segment of length 1 [12]. This is not the same as treewidth.
1
Computational Topology (Jeff Erickson) Treewidth
A B H
ACD CDG DGHK BDE
C D E F
DHKM DEIM
G H I J
KLM EIJM EFJ
M
K L M
A graph with treewidth 3 and an optimal tree decomposition.
The subtrees of T corresponding to vertices H and M are highlighted.
minus 1. The treewidth of G is the minimum depth of a subtree system S whose intersection graph I(S)
contains G as a subgraph.
A graph G is called a k-tree if and only if either G is the complete graph with k vertices, or G has a
vertex v with degree k − 1 such that G \ v is a k-tree. A partial k-tree is any subgraph of a k-tree. In
particular, a connected graph G is a 1-tree if and only if G is a tree. Unwinding the recursion gives us an
elimination order v1 , v2 , . . . , vn for the vertices of any partial k-tree, in which each node vi has at most
k − 1 neighbors with larger indices.
A B B B B
C D E F C D E F D E F D E F D E F
G H I J G H I J G H I J H I J H I J
K L M K L M K L M K L M K L M
D E F D E F D E F E F E F E F F
H I J H I J I J I J I J J J J
K M M M M
An elimination order for the example graph.
We can easily derive a tree decomposition of width k for any partial k-tree from an elimination
order. Specifically, the decomposition tree T has n nodes {1, 2, . . . , n}, and for any node i, the subset
X (i) contains vertex vi and its (at most k − 1) larger-indexed neighbors. The converse is true as well;
every tree decomposition of width k defines an elimination order proving that the decomposed graph is
a partial k-tree. (I’ll leave the proof as an exercise.)
Lemma 11.1 (Wimer [17], Scheffler [16]). A graph has treewidth k if and only if it is a partial k-tree.
Finally, a tree decomposition (T, X ) can be interpreted as a recursive separator hierarchy as follows.
Choose any node of T to to be the root. For each node i of T , let D(i) denote the union of the subsets
X ( j) for all descendants of j of i (including i itself), and let A(i) denote the union of the subsets X ( j) for
all proper ancestors of j of i. Each node i is associated with a set of boundary vertices Bi = D(i) ∩ A(i)
and a subgraph Gi , which is the induced subgraph G[D(i)] minus edges between boundary nodes. Each
subset X (i) is a separator of the corresponding subgraph Gi .
We can relate the treewidth of a graph to the existence of small balanced separators as follows. We
say that an n-vertex graph G is s -separable, for some non-decreasing function s : N → N, if either n = 1
or G has a 2/3-separator S of size s(n), such that the components of G \ S are also s-separable.
2
Computational Topology (Jeff Erickson) Treewidth
A
B
C D
D E
C D E F
D D E E
D
G J
G H I I J
H
K M M
K M
K L M
A separator hierarchy for the example graph, rooted at DHKM.
Lighter (blue) nodes are boundary nodes inherited from ancestors in the hierarchy.
Lemma 11.2. Any graph of treewidth k is O(k)-separable. Conversely, any s-separable n-vertex graph
has treewidth O(s(n) log n), or treewidth O(s(n)) if s(n) = Ω(nc ) for some constant c > 0.
Proof (sketch): Let G be a graph with treewidth k, and let (T, X ) be a tree decomposition of width k.
Without loss of generality, every node in T has degree at most 3. Thus, there is a node i that separates T
into subtrees, each with at most 2/3 of the nodes of T . The corresponding subset X (i) is a 2/3-separator
for G of size at most k + 1, and the components of T \ X (i) have treewidth at most k.
On the other hand, suppose G = (V, E) is s-separable, and |V | = n > 1. I claim that G has a path
decomposition of the appropriate width. Let S be a 2/3 separator of size s(n), such that both components
of G \ S are also s-separable. Let (T1 , X 1 ) and (T2 , X 2 ) be path decompositions of the components of G \ S.
Let T be a path obtained by concatenating paths T1 and T2 . For any node i in T1 , let X (i) = X 1 (i) ∪ S,
and for any node j in T2 , let X (i) = X 2 (i) ∪ S. Then (T, X ) is a path decomposition whose width k(n)
obeys the recurrence k(n) ≤ k(2n/3) + s(n).
p
Corollary 11.3. Every planar graph has treewidth O( n). Every graph that has a cellular embedding
p
on a surface of genus g > 0 has treewidth O( g n).
11.2 Dynamic Programming: Maximum Independent Set
An independent set in a graph G is a subset of the vertices, no two of which are connected by an edge
in G. Compute the largest independent set in a graph is one of Karp’s classical NP-hard problems.
Moreover, even approximating the largest independent set to within a factor of n1−" , for any " > 0, is
NP-hard [14, 18]. However, for any graph of constant (or even logarithmic) treewidth, we can compute
the largest independent set in polynomial time.
Theorem 11.4 (Arnborg and Proskurowski [4]). The size of the largest independent set in a graph
of treewidth k can be computed in O(4k k2 n) time.
Proof: Let G be a graph of treewidth k, and let (T, X ) be a tree decomposition of width k. Without loss
of generality, the tree T has at most n nodes. Let r denote the arbitrarily chosen root of T . For each
node i, let Gi and Bi denote the corresponding subgraph and boundary vertices (as defined above).
For any node i of T and any subset A ⊆ Bi , let M IS(i, A) denote the size of the largest independent
set I in Gi such that I ∩ Bi = A. This function obeys the recurrence
J is an independent set in G j
X
M IS(i, A) = |A| + max M IS( j, B j ∩ A0 ) − B j ∩ A ,
j child of i and A ⊆ J ⊆ X (i)
3
Computational Topology (Jeff Erickson) Treewidth
with the base case M IS(i, A) = |A| whenever Gi \ Bi = ∅ (in particular, when i is a leaf of T ). The
largest independent set in G has size M IS(G, ∅). We can easily evaluate the recurrence using dynamic
programming.
For each node i, there are at most 2k+1 subsets A to consider. For each subproblem (i, A), and each
child j of i, there are at most 2k+1 subsets J to consider; for each subset J, we can easily determine
in O(k2 ) time whether J is an independent set in G j . Thus, the total time to evaluate M IS(i, A), not
counting recursion, is O(2k k2 · deg(i)), where deg(i) is the
Pnumber of children of node i. Thus, the total
running time of the dynamic programming algorithm is i O(4k k2 · deg(i)) = O(4k k2 n).
Similar strategies apply to a truly enormous number of other NP-hard optimization problems [1];
some of these are surveyed by Arnborg and Proskurowski [4] and by Bodlaender [7].
11.3 PTAS for Planar Graphs
Lemma 11.5. A planar graph with diameter D has treewidth at most 3D − 2.
Proof (Eppstein [10]): Without loss of generality, assume that G is a triangulation; adding edges does
not increase the diameter of the graph. Let (T, ∅, C) be a tree-cotree decomposition where T is a BFS
tree rooted at an arbitrary node r. For each face f of T , let X ( f ) be the setof vertices on the shortest
paths from the vertices of f to r. Then (C ∗ , X ) is a tree decomposition; each subset X ( f ) has size at
most 3D − 1, so the width of the decomposition is at most 3D − 2.
Let G be an arbitrary graph. Choose an arbitrary root vertex r, and for any vertex r, let d(v ) denote
the depth of v in a breadth-first search tree rooted at r. For any nonnegative integers i ≤ j, let G[i, j] be
the subgraph of G induced by vertices v such that i ≤ d(v) ≤ j, and let G〈i, j ] := G[0, j] / G[0, i − 1].
Observe that G[i, j] is a subgraph of G〈i, j], and that G[i, j] \ G〈i, j] consists of a single vertex: the
contraction of G[0, i − 1].
Lemma 11.6. For any graph G and any nonnegative integers i ≤ j, the graph G〈i, j] has diameter at
most 2 j − 2i + 1.
Finally, for any integers i ≥ 0 and k ≥ 2 such that i < k, let Gi,k denote the subgraph of G induced
by vertices whose depth mod k is not equal to i.
Corollary 11.7 (Baker [5]). For any planar graph G and any integers i ≥ 0 and k ≥ 2 such that i < k,
the subgraph Gi,k has treewidth O(k).
Proof: Gi,k is the disjoint union of all graphs of the form G[ak + i + 1, (a + 1)k + i − 1]. For every
integer a, the graph G〈ak + i + 1, (a + 1)k + i − 1] has diameter at most 2k − 3, and therefore has
treewidth at most 3(2k − 3) − 2 = 6k − 11. Thus, each subgraph G[ak + i + 1, (a + 1)k + i − 1] also has
treewidth at most 6k − 11.
Theorem 11.8 (Baker [5]). For any integer k > 1, we can compute a (1 − 1/k)-approximation of the
largest independent set in any n-node planar graph in 2O(k) n time.
Proof: Let G be a planar graph, and let S be the largest independent set in G. For each integer
0 ≤ i < k, let Si = {v ∈ S | d(v) mod k = i}. For any i, our dynamic programming algorithm can
compute the largest independent set Si0 in Gi,k in 2O(k) n, because Gi,k has treewidth O(k). The set
S \ Si is an independent set in Gi,k , so |S 0 | ≥ |S \ Si |. Finally, the pigeonhole principle implies that
|S \ Si | ≥ (1 − 1/k) |S| for some i.
Equivalently, we can compute a (1−")-approximation in time 2O(1/") n. In particular, we can compute
a (1 − 1/ log n)-approximation in polynomial time.
4
Computational Topology (Jeff Erickson) References
11.4 PTAS for Surface Graphs
Lemma 11.9 (Eppstein [11]). A graph with diameter D and genus g has treewidth O(g D).
Proof: Let G be a cellular graph on a surface of genus g. Let (T, L, C) denote a tree-cotree decomposition
of G where T is a breadth-first-search tree. Let R be the reduced cut graph obtained by repeatedly
removing vertices of degree 1 from the cur graph T ∪ L. We proved earlier in the semester that R is the
union of O(g) shortest paths. It follows that R contains O(g D) nodes.
We can embed the graph G / R in the plane by first embedding G \ R so that all neighbors of R are
on the outer face, and then connecting the neighbors of R to a new super-vertex. Thus, G / R is planar.
Contracting an edge can only reduce the diameter of a graph, so G / R has diameter at most D. Thus,
Baker’s Lemma (Corollary 10.7) implies that G / R has a tree decomposition (T 0 , X ) of width at most
3D − 1.
We can extend (T 0 , X ) to a tree decomposition (T 0 , X 0 ) of G by setting X 0 (i) = X (i) ∪ V (R). The
resulting decomposition has width O(g D).
Corollary 11.10. For any genus-g graph G and any integers i ≥ 0 and k ≥ 2 with i < k, the subgraph
Gi,k has treewidth O(g k).
Theorem 11.11 (Eppstein [11]). For any integer k > 1, we can compute a (1 − 1/k)-approximation
of the largest independent set in any n-node graph of genus g in 2O(gk) n time.
Equivalently, we can compute a (1−")-approximation in time 2O(g/") n. In particular, we can compute
a (1 − g/ lg n)-approximation in polynomial time.
References
[1] S. Arnborg. Efficient algorithms for combinatorial problems on graphs with bounded decompos-
ability: A survey. BIT 25:2–23, 1985.
[2] S. Arnborg and A. Proskurowski. Characterization and recognition of partial k-trees. Congr. Numer.
47:69–75, 1985. Proc. 16th S.E. Int. Conf. Combinatorics, Graph Theory, and Computing.
[3] S. Arnborg and A. Proskurowski. Characterization and recognition of partial 3-trees. SIAM J. Alg.
Disc. Meth. 7(2):305–314, 1986.
[4] S. Arnborg and A. Proskurowski. Linear time algorithms for NP-hard problems restricted to partial
k-trees. Discrete Appl. Math. 23:11–24, 1989.
[5] B. S. Baker. Approximation algorithms for NP-complete problems on planar graphs. J. Assoc.
Comput. Mach. 41(1):153–180, 1994.
[6] U. Bertelè and F. Brioschi. Nonserial Dynamic Programming. Academic Press, New York, 1972.
[7] H. L. Bodlaender. Dynamic programming on graphs of bounded treewidth. Proc. 15th Int. Colloq.
Automata Lang. Prog., 105–119, 1988. Lecture Notes Comput. Sci. 317, Springer-Verlag.
[8] H. L. Bodlaender. Some classes of graphs with bounded treewidth. Bull. EATCS 36:116–126, 1988.
Technical Report RUU-CS-76-22, Dept. Comput. Sci., Univ. Utrecht, 1998.
[9] H. L. Bodlaender. A partial k-arboretum of graphs with bounded treewidth. Theoret. Comput. Sci.
209:1–45, 1998.
5
Computational Topology (Jeff Erickson) References
[10] D. Eppstein. Subgraph isomorphism in planar graphs and related problems. J. Graph Algorithms
Appl. 3(3):1–27, 1999.
[11] D. Eppstein. Diameter and treewidth in minor-closed families. Algorithmica 27:275–291, 2000.
[12] P. Erdős, F. Harary, and W. T. Tutte. On the dimension of a graph. Mathematika 12:118–122, 1965.
[13] R. Halin. S-functions for graphs. J. Geom. 8(1–2):171–186, 1976.
[14] J. Håstad. Clique is hard to approximate within n1−" . Acta Mathematica 182(1):105–142, 1999.
[15] N. Robertson and P. D. Seymour. Graph minors. II. Algorithmic aspects of tree-width. J. Algorithms
7(3):309–322, 1986.
[16] P. Scheffler. Linear-time algorithms for NP-complete problems restricted to partial k-trees. Tech. Rep.
R-Math-87/03, Akademie der Wissenschaften der DDR, Karl-Weierstrass-Institut für Mathematik,
1987.
[17] T. V. Wimer. Linear algorithms on k-terminal graphs. Ph.D. thesis, Clemson University, 1987.
[18] D. Zuckerman. Linear degree extractors and the inapproximability of MAX CLIQUE and CHROMATIC
NUMBER. Theory Comput. 3:103–128, 2007.
c Copyright 2009 Jeff Erickson. Released under a Creative Commons Attribution-NonCommercial-ShareAlike 3.0 License (http://creativecommons.org/licenses/by-nc-sa/3.0/).
Free distribution is strongly encouraged; commercial distribution is expressly forbidden. See http://www.cs.illinois.edu/~jeffe/teaching/comptop/ for the most recent revision.