Skip to content

Chapter 34. Tree Decomposition

A tree decomposition represents a graph by arranging overlapping sets of vertices along a tree.

The purpose is to describe a graph that may contain cycles by using a tree-like structure. The graph itself may be complicated, but its vertices are grouped into bags, and the bags are organized as nodes of a tree. If the bags are small, many hard graph problems become easier.

Tree decompositions are important in structural graph theory, dynamic programming, constraint satisfaction, probabilistic inference, database query optimization, and algorithms on graphs of bounded treewidth. A standard definition uses three conditions: every graph vertex appears in some bag, every graph edge appears inside some bag, and the bags containing a fixed vertex form a connected subtree.

34.1 Motivation

Trees are simpler than general graphs.

A tree has no cycles. Between any two vertices there is exactly one simple path. Many problems that are hard on general graphs are easy on trees because information can be passed from leaves toward a root.

A general graph may contain many cycles. These cycles create dependencies that prevent simple recursive methods. A tree decomposition handles this by grouping vertices into bags. Each bag stores a local part of the graph. The tree structure describes how these local parts are connected.

The guiding idea is this:

A graph is close to a tree if it can be decomposed into small overlapping pieces arranged as a tree.

The size of the largest bag measures how far the graph is from being tree-like.

34.2 Definition

Let

G=(V,E) G=(V,E)

be an undirected graph.

A tree decomposition of GG is a pair

(T,B), (T,\mathcal{B}),

where TT is a tree and

B={Bt:tV(T)} \mathcal{B}=\{B_t : t \in V(T)\}

is a family of subsets of VV, one subset for each node tt of TT.

Each set BtB_t is called a bag.

The following three conditions must hold.

First, every vertex of GG appears in at least one bag:

tV(T)Bt=V. \bigcup_{t \in V(T)} B_t = V.

Second, every edge of GG is contained in some bag. That is, for every edge

{u,v}E, \{u,v\}\in E,

there exists a node tV(T)t\in V(T) such that

u,vBt. u,v \in B_t.

Third, for every vertex vVv\in V, the set of nodes

{tV(T):vBt} \{t\in V(T): v\in B_t\}

forms a connected subtree of TT.

The third condition is called the connectedness condition or running intersection property. It prevents a vertex from disappearing and then reappearing in unrelated parts of the decomposition.

34.3 Bags and the Decomposition Tree

There are two graphs involved in a tree decomposition.

The original graph is

G. G.

Its vertices are the objects we want to study.

The decomposition tree is

T. T.

Its nodes are not vertices of GG. Instead, each node of TT carries a bag, and each bag is a subset of vertices of GG.

This distinction is important. To avoid confusion, one often says vertex for an element of V(G)V(G), and node for an element of V(T)V(T).

A bag may contain one vertex, two vertices, or many vertices. Adjacent bags in TT usually overlap. The overlaps are where information is passed between parts of the decomposition.

34.4 A Simple Example

Let GG be the path graph

1234. 1-2-3-4.

One tree decomposition has three bags:

B1={1,2}, B_1=\{1,2\}, B2={2,3}, B_2=\{2,3\}, B3={3,4}. B_3=\{3,4\}.

Let the decomposition tree be the path

B1B2B3. B_1-B_2-B_3.

Every graph vertex appears in some bag. Every graph edge appears inside a bag:

{1,2}B1, \{1,2\}\subseteq B_1, {2,3}B2, \{2,3\}\subseteq B_2, {3,4}B3. \{3,4\}\subseteq B_3.

The bags containing vertex 22 form the connected set

B1B2. B_1-B_2.

The bags containing vertex 33 form the connected set

B2B3. B_2-B_3.

Vertices 11 and 44 each appear in one bag. Thus all three conditions hold.

This example shows that a tree is already tree-like. Its decomposition can use bags of size 22.

34.5 A Cycle Example

Consider the cycle graph

12341. 1-2-3-4-1.

This graph is not a tree, but it has a small tree decomposition.

Take the bags

B1={1,2,4}, B_1=\{1,2,4\}, B2={2,3,4}. B_2=\{2,3,4\}.

Let the decomposition tree consist of one edge:

B1B2. B_1-B_2.

Every vertex appears in some bag. The edges are covered:

{1,2}B1, \{1,2\}\subseteq B_1, {2,3}B2, \{2,3\}\subseteq B_2, {3,4}B2, \{3,4\}\subseteq B_2, {4,1}B1. \{4,1\}\subseteq B_1.

The bags containing vertex 22 are B1B_1 and B2B_2, which are adjacent. The bags containing vertex 44 are also B1B_1 and B2B_2. The other vertices appear once.

Thus the cycle has a tree decomposition with bags of size 33.

The cycle cannot be decomposed with only bags of size 22, because a cycle has more dependency than a tree. This difference is measured by treewidth.

34.6 Width

The width of a tree decomposition is one less than the size of its largest bag:

width(T,B)=maxtV(T)Bt1. \operatorname{width}(T,\mathcal{B}) = \max_{t\in V(T)} |B_t| - 1.

The subtraction by 11 is conventional. With this convention, a tree has treewidth 11, not 22, because it can be decomposed into bags of size 22.

A decomposition with small width is better for many algorithms, because the amount of local state often grows exponentially in the bag size.

For example:

Largest bag sizeWidth
1100
2211
3322
k+1k+1kk

34.7 Treewidth

The treewidth of a graph GG, written

tw(G), \operatorname{tw}(G),

is the minimum width over all tree decompositions of GG:

tw(G)=min(T,B)(maxtV(T)Bt1). \operatorname{tw}(G) = \min_{(T,\mathcal{B})} \left( \max_{t\in V(T)} |B_t| - 1 \right).

Treewidth measures how close a graph is to a tree.

A graph has treewidth 00 exactly when it has no edges. A forest has treewidth at most 11. Any nonempty forest has treewidth exactly 11. A cycle has treewidth 22. Complete graphs have large treewidth.

For the complete graph KnK_n, every pair of vertices is adjacent. In any tree decomposition, all nn vertices must appear together in some bag. Therefore

tw(Kn)=n1. \operatorname{tw}(K_n)=n-1.

34.8 Why the Connectedness Condition Matters

The first two conditions alone are not enough.

Suppose a vertex vv appears in two distant bags but not in the bags between them. Then the decomposition treats vv as if it belongs to two separate regions. This breaks dynamic programming, because information about vv could become inconsistent.

The connectedness condition ensures that all appearances of vv form one contiguous region of the decomposition tree.

If vv appears in bag BaB_a and bag BbB_b, then vv must appear in every bag on the unique path between BaB_a and BbB_b in TT.

This condition is what makes the decomposition behave like a coherent tree-structured representation.

34.9 Separators from Tree Decompositions

Tree decompositions encode separators.

Let xyxy be an edge of the decomposition tree TT. Removing this edge splits TT into two components. These two components correspond to two collections of bags.

Let

S=BxBy. S = B_x \cap B_y.

Then SS acts as a separator between the parts of GG represented on the two sides.

Any path in GG from a vertex that appears only on one side to a vertex that appears only on the other side must pass through a vertex in SS.

This separator view explains why tree decompositions support divide-and-conquer algorithms. The graph can be separated into parts that interact through small boundary sets.

34.10 Trivial Decomposition

Every graph has a tree decomposition.

The simplest one uses a single bag:

B=V. B = V.

The decomposition tree has one node carrying this bag.

All conditions are immediate. Every vertex appears in the bag. Every edge has both endpoints in the bag. The connectedness condition holds because each vertex appears in a one-node subtree.

The width of this decomposition is

V1. |V|-1.

This decomposition is usually not useful, but it proves that treewidth is always defined for finite graphs.

34.11 Tree Decomposition of a Tree

Let GG itself be a tree.

For every edge

{u,v}E(G), \{u,v\}\in E(G),

create a bag

Buv={u,v}. B_{uv}=\{u,v\}.

Arrange these bags in a tree structure corresponding to the original tree.

One way is to root GG, then connect bags for adjacent edges when the corresponding edges share a vertex and lie next to each other in the rooted structure.

Every edge of GG is contained in its own bag. Every vertex vv appears in the bags corresponding to edges incident with vv. These bags form a connected subtree.

Thus every tree with at least one edge has a decomposition of width 11.

Since a graph of treewidth 00 has no edges, every nontrivial tree has treewidth 11.

34.12 Complete Graphs

Complete graphs have large treewidth.

Let

G=Kn. G=K_n.

In a complete graph, every pair of vertices is adjacent.

For any tree decomposition of KnK_n, there must be a bag containing every vertex of KnK_n. This follows from the Helly property for subtrees of a tree: if every pair of connected subtrees intersects, then all of them have a common intersection.

For each vertex vV(Kn)v\in V(K_n), the bags containing vv form a connected subtree of the decomposition tree. Since every pair of vertices is adjacent, each pair of these subtrees intersects in some bag. Hence all nn subtrees share a common node. The bag at that node contains all vertices.

Therefore the largest bag has size at least nn, and

tw(Kn)=n1. \operatorname{tw}(K_n)=n-1.

34.13 Dynamic Programming on Tree Decompositions

Tree decompositions are algorithmically useful because they reduce global graph problems to local computations on bags.

A typical dynamic programming algorithm proceeds as follows:

  1. Root the decomposition tree.
  2. Process bags from leaves toward the root.
  3. For each bag, store partial solutions indexed by the vertices in that bag.
  4. Combine information from child bags through their intersections with the parent bag.
  5. Read the final answer at the root.

The running time is often exponential in the treewidth but polynomial in the number of vertices.

A common form is

O(f(k)n), O(f(k)n),

where kk is the treewidth and n=Vn=|V|. The function f(k)f(k) may be exponential, but if kk is small, the algorithm can be efficient.

This is the main reason bounded-treewidth graphs are important.

34.14 Example: Independent Set

An independent set is a set of vertices no two of which are adjacent.

On a general graph, finding a maximum independent set is computationally hard. On a graph with small treewidth, it can be solved by dynamic programming over a tree decomposition.

For each bag BtB_t, one considers all subsets

SBt. S \subseteq B_t.

Only subsets that are independent inside the bag are allowed. The algorithm records the best partial solution below tt consistent with choosing SS inside BtB_t.

The number of subsets of a bag is

2Bt. 2^{|B_t|}.

Thus small bags make the computation feasible.

This illustrates the general pattern: treewidth controls the number of boundary configurations.

34.15 Nice Tree Decompositions

For algorithmic purposes, tree decompositions are often converted into nice tree decompositions.

A nice tree decomposition is rooted and has restricted node types. Common types are:

Node typeMeaning
LeafStarts a computation
Introduce vertexAdds one vertex to the bag
Forget vertexRemoves one vertex from the bag
Introduce edgeAccounts for one graph edge
JoinCombines two child computations

Nice decompositions simplify dynamic programming because each step changes the bag in a controlled way.

They do not change the essential width. They mainly provide a convenient normal form.

34.16 Chordal Graph View

Tree decompositions are closely related to chordal graphs.

A chordal graph is a graph in which every cycle of length at least four has a chord. A chord is an edge connecting two nonconsecutive vertices of the cycle.

One may view a tree decomposition as embedding the original graph into a chordal supergraph whose maximal cliques correspond to bags.

From this viewpoint, treewidth is one less than the minimum possible clique size in such a chordal completion.

This connection links tree decompositions with elimination orderings, sparse matrix factorization, and graphical models.

34.17 Elimination Orderings

An elimination ordering is an ordering of vertices

v1,v2,,vn. v_1,v_2,\ldots,v_n.

Eliminating a vertex means making its remaining neighbors into a clique, then removing the vertex.

The width of an elimination ordering is the maximum number of later neighbors any vertex has at the moment it is eliminated.

The treewidth of a graph equals the minimum width over all elimination orderings.

This gives another way to understand treewidth. A graph has small treewidth if its vertices can be eliminated while keeping small remaining neighborhoods.

34.18 Applications

Tree decompositions appear in several areas.

AreaRole of tree decomposition
Graph algorithmsDynamic programming over bags
Constraint satisfactionVariables in bags, constraints across bags
Probabilistic inferenceJunction tree methods
Database systemsJoin trees and acyclic query plans
Sparse linear algebraFill-in and elimination
Structural graph theoryMeasuring tree-like structure
LogicEfficient model checking on bounded treewidth

The common theme is controlled interaction. A large structure is decomposed into parts whose overlap is small.

34.19 Limitations

Tree decompositions are powerful when the width is small.

They become less useful when the treewidth is large. A graph may have many vertices but small treewidth, or it may have moderate size and large treewidth. Dense graphs often have large treewidth because many vertices must appear together in bags.

Finding an optimal tree decomposition is itself computationally difficult in general. In practice, algorithms often use heuristics or approximation methods to find decompositions that are good enough.

Thus tree decomposition is most effective when the input graph has natural sparsity, locality, or separator structure.

34.20 Summary

A tree decomposition represents a graph by assigning subsets of graph vertices, called bags, to the nodes of a tree.

The bags must cover all vertices, cover all edges, and satisfy the connectedness condition for each vertex.

The width of a decomposition is the largest bag size minus one. The treewidth of a graph is the minimum possible width.

Small treewidth means that the graph is structurally close to a tree. This enables dynamic programming and separator-based reasoning. Tree decompositions therefore form a bridge between graph structure and efficient algorithms.