AI Glossary / Graphs and symbolic AI / Advanced
Tree width
Definition
Tree width, commonly written treewidth, measures how small the largest bag can be in a valid tree decomposition of a graph, minus one. It captures a structural form of closeness to a tree that is useful for designing algorithms.
What it means
A tree decomposition groups graph vertices into overlapping bags connected in a tree. Every vertex and edge must be represented, and all bags containing any one vertex must stay connected. Different valid decompositions of the same graph can have different largest bags.
The width of one decomposition is easy to calculate: count the vertices in its largest bag and subtract one. The graph's treewidth is the minimum of that quantity across all valid decompositions. Reporting the width of a decomposition found by a heuristic does not automatically establish the graph's exact treewidth.
Low width is valuable because many algorithms need to consider combinations of values within each bag. The number of combinations can grow sharply with bag size even when the overall graph has relatively few vertices.
How it works
Suppose a constraint problem has variables with at most d possible values each. A bag with k variables can contain as many as d raised to k possible assignments before constraints eliminate alternatives. If a decomposition has width w, its bags have at most w+1 variables.
Dynamic programming can process the decomposition while retaining the information needed to match shared variables. For suitable finite-domain problems, this replaces one enormous global combination space with coordinated smaller tables. The benefit depends on both width and domain sizes; small width does not make very large domains free.
A decomposition of width w proves that the graph's treewidth is at most w. To establish equality, one also needs a matching lower bound. Finding minimum-width decompositions is computationally difficult in general, so practical tools often use heuristics. A heuristic result should be described with its actual guarantee rather than silently promoted to an exact measurement.
Three practical examples
- A constraint solver uses a low-width decomposition to organize compatibility tables for a product configuration.
- A probabilistic modeling team examines width-related intermediate table sizes before choosing an exact inference method.
- A graph-software team compares decomposition heuristics by the largest bags they produce and the resources required by the downstream algorithm.
Think of it this way
Think of distributing a complicated discussion among small meetings, with overlapping participants carrying the necessary decisions between meetings. The largest unavoidable meeting matters because coordinating many participants at once is harder.
This is only an intuition. Treewidth is defined by exact graph conditions, not by subjective meeting difficulty. A poor meeting plan can have a large group even when a better plan uses small groups; likewise, one wide decomposition does not prove that the graph itself has large treewidth.
Worked example
Separating a decomposition's width from the graph's width
Consider the path A - B - C - D. A single bag {A,B,C,D} is a valid decomposition with width 4−1=3. It covers every vertex and edge, and connected occurrences are automatic with one bag.
A better decomposition is the three-bag path {A,B} - {B,C} - {C,D}. Each original edge is covered, and the appearances of B and C are connected. Its largest bags have two vertices, so its width is one.
The original graph cannot have width zero: every bag would then have at most one vertex, making it impossible to cover edge AB. Therefore its treewidth is exactly one, even though the first valid decomposition had width three.
If all four variables have three possible values, a four-variable bag has 3^4=81 possible assignments. A two-variable bag has 3^2=9. These are potential local table sizes, not a measured ninefold runtime improvement: multiple bags, constraints and coordination still contribute work.
Illustrative case study
Fictional Alder Inference receives a report saying that its graph has treewidth twelve. The number came from the largest bag in one heuristic decomposition, but no minimum-width proof was supplied.
The team relabels the result as an upper bound obtained by that heuristic and tries a different variable ordering. It records the new decomposition, its validity checks and the resulting intermediate table sizes.
Even when a narrower decomposition is found, the team measures the complete inference workflow because preparing the decomposition and managing tables also take resources. The fictional lesson is about interpreting structural evidence, not a claim that a particular heuristic always improves performance.
Common misconceptions and mistakes
- Treewidth counts branches in a drawing. It concerns bags in valid decompositions, not the visual spread of a picture.
- A decomposition of width six proves treewidth six. It proves an upper bound; a better decomposition may exist.
- Low treewidth guarantees every task on the graph is easy. Benefits depend on the specific algorithm, problem and additional parameters.
Business use
Treewidth can support a practical discussion about whether exact structured reasoning is likely to fit available memory and time. It is particularly useful when a proposed system repeatedly solves problems on related graphs.
Ask how width was estimated, whether the decomposition is available, and what variable domains or table representations are involved. Benchmark the complete workflow on representative cases. A claim that a model is “tree-like” is less useful than a valid decomposition, its maximum bag size and evidence about the computation that uses it.
People also ask
Can a graph with many vertices have small treewidth?
Yes. A long path still has width one when it contains an edge.
Is the minus one important?
Yes. It is part of the standard definition and makes ordinary nontrivial trees have treewidth one.
Does a heuristic necessarily find the minimum?
No. Its output may be useful without being optimal, and the result should retain that distinction.
Check your understanding
A valid decomposition has largest bag size five. What does this establish about the graph's treewidth?
Answer: Its treewidth is at most four. Equality requires evidence that no valid decomposition has smaller width.
Related terms
- Tree decomposition
- Graph
- Dynamic programming
- Variable elimination
- Constraint satisfaction problem
- junction tree
- upper bound
Learn next
Read tree decomposition and variable elimination. Construct two valid decompositions of a small path, calculate each width, and explain why only a matching lower bound establishes the exact graph value.
More in Graphs and symbolic AI
- Transition kernel - A transition kernel specifies a probability distribution over possible next states for each current state.
- Transposition table - A transposition table stores information about game positions that a search has already examined, so the information can be reused when a different sequence...
- Traveling salesperson problem - The traveling salesperson problem, or TSP, asks for a minimum-cost tour that visits each required location once and returns to the starting location.
- Tree-like search - Tree-like search explores a tree of possible action sequences without maintaining a global record of every state already reached.
- Trigram search - Trigram search retrieves or compares text using overlapping sequences of three characters.
- Triplestore - A triplestore is a database designed to store and query statements represented as subject - predicate - object triples, most commonly using RDF.
Sources
Russell and Norvig, Constraint Satisfaction Problems, Section 5.4, defining decomposition width, graph treewidth and its role in solving structured constraint problems: https://aima.cs.berkeley.edu/4th-ed/pdfs/newchap05.pdf
NetworkX, treewidth approximation module and heuristic implementation documentation: https://networkx.org/documentation/stable/_modules/networkx/algorithms/approximation/treewidth.html
The primary textbook section and returned NetworkX documentation were reviewed. The path proof and table-size comparison are original calculations, not runtime measurements.
Previous: Tree selection policy Next: Treebank