Treewidth Calculator

how tree-like is G?

CalculatorsFreeNo Signup
4.3(156 reviews)
All Tools

Loading tool...

About Treewidth Calculator

A treewidth calculator computing tw(G): minimum width of a tree decomposition. tw(tree)=1, tw(cycle)=2, tw(K_n)=n-1, tw(grid)=min(m,n). Many NP-hard problems become polynomial for bounded treewidth (Courcelle's theorem). Client-side.

Treewidth Calculator Features

  • tw(G) value
  • Tree decomposition
  • Courcelle's thm
  • Common graphs
  • FPT algorithms
Treewidth tw(G): minimum width of a tree decomposition. Measures how 'tree-like' G is. tw=1 iff forest. tw≤2 iff series-parallel. Courcelle (1990): any MSO₂-definable problem is FPT parameterized by treewidth. Revolutionized parameterized complexity.

How to Use

Select graph:

  • tw: Treewidth
  • Decomp: Tree structure
  • FPT: Fixed-parameter tractable

Courcelle's Theorem

Any graph property expressible in MSO₂ logic can be decided in linear time for graphs of bounded treewidth. This includes: 3-coloring, Hamiltonian cycle, dominating set, and hundreds more NP-hard problems! The 'metatheorem' of parameterized complexity.

Tree Decomposition

A tree decomposition: tree T with bags B_t ⊆ V(G). (1) Every vertex in some bag. (2) Every edge has both endpoints in some bag. (3) Bags containing v form a connected subtree. Width = max bag size - 1.

Step-by-Step Instructions

  1. 1Select graph.
  2. 2Compute tw(G).
  3. 3Find decomposition.
  4. 4Apply Courcelle.
  5. 5Compare graphs.

Treewidth Calculator — Frequently Asked Questions

What problems are easy for bounded treewidth?+

Independent set, vertex cover, domination, coloring, Hamiltonian cycle, Steiner tree, and any MSO₂-expressible property. Runtime: O(f(tw)·n) linear in n. The function f(tw) can be exponential in tw but that's fine if tw is small.

How is treewidth computed?+

Exact: NP-hard in general. But: FPT in tw itself: O(2^{O(tw³)}·n) by Bodlaender. Approximation: O(√log tw) factor in polynomial time. For tw≤k (fixed k): linear time recognition. In practice: heuristics work well.

What's the treewidth of common graphs?+

Trees: tw=1. Cycles: tw=2. K_n: tw=n-1. m×n grid: tw=min(m,n). Outerplanar: tw≤2. Series-parallel: tw≤2. Planar: tw=O(√n). Bounded-genus: tw=O(√n).

Share this tool: