Advanced maths

Exact pathwidth calculator with a path decomposition

Compute exact pathwidth for a small undirected graph and return a path decomposition.

Your numbers

Each row: from,to; optional third weight. Empty allowed for an edgeless graph.

Calculated on your device. Your inputs aren’t sent to us.

Your result

Ready when you are

Enter your inputs and select Calculate.

Report an issue

Behind the numbers

How this calculation works

Compute exact pathwidth for a small undirected graph and return a path decomposition. The method uses vertex-separation dynamic programming, then constructs bags that can be checked for coverage and running intersection. Requiring the decomposition structure to be a path makes this a different invariant from the site’s branching-tree decomposition calculator.

THE FORMULApw(G)=min_path_decomposition max_i |B_i|−1.

A worked example

A four-cycle has path bags {0,1,3} and {1,2,3}; each has size three, giving width two. It cannot have width one because the cycle is not a forest.

Good to know

Exact vertex-separation subset DP n≤16, path-bag certificate. Not arbitrary branching treewidth or a greedy upper bound.

Require bags to follow one path

A path decomposition is an ordered list of vertex bags. Every original vertex occurs somewhere, every original edge has both endpoints in a bag, and the bags containing any one vertex form a consecutive interval. Width is the largest bag size minus one, not the number of bags.

A tree decomposition allows bags on a branching tree and can achieve a smaller width. Therefore a minimum treewidth certificate cannot automatically be relabeled as a minimum pathwidth certificate. The path restriction is a mathematical change to the allowed decomposition structure, not a display preference.

Two three-vertex bags give a path decomposition of the four-cycleBag {0,1,3}Bag {1,2,3}Every edge covered; shared vertices persistMaximum bag size 3 → pathwidth 2
A four-cycle has path bags {0,1,3} and {1,2,3}; each has size three, giving width two. It cannot have width one because the cycle is not a forest. Diagram is schematic; labels specify the numerical values.

The Graph bandwidth calculator with optimal vertex ordering measures maximum edge span in a vertex order. A low pathwidth decomposition can still contain edges whose endpoints are far apart in that ordering.

Interpret the vertex-separation viewpoint

Choose a vertex ordering and consider each prefix. Its boundary consists of prefix vertices with at least one neighbor still in the unprocessed suffix. These are the vertices that must remain active to preserve dependencies across that cut. The largest boundary size is the ordering’s vertex-separation value.

Pathwidth equals the minimum such value over orderings. The dynamic program indexes processed subsets and compares possible last vertices, keeping the best maximum boundary encountered so far. It explores the small graph’s subset space rather than greedily discarding a vertex whenever its current degree looks small.

Check the four-cycle example

For cycle zero–one–two–three–zero, bags {zero,one,three} and {one,two,three} cover all edges. Vertices one and three appear in adjacent bags, while zero and two appear once, so running intersection holds. Largest bag size three gives width two.

A cycle cannot have width one because graphs of width at most one under this decomposition are forests. Thus the width-two witness is optimal. A four-vertex path instead admits consecutive two-vertex bags and has width one, showing that equal vertex counts need not imply equal decomposition complexity.

Read the constructed bag order

For each next vertex in the selected ordering, the solver forms a bag containing that vertex and the earlier active boundary. A processed vertex remains in bags until all its neighbors have been introduced. This construction enforces the interval property without arbitrarily adding distant bags later.

The returned ordering and bags are certificates of an achievable width. The completed dynamic program supplies the lower-bound claim that no smaller width exists. When comparing another implementation, check bag validity and maximum size rather than requiring its bag list or optimal ordering to be identical.

Handle isolated and disconnected vertices

An isolated vertex needs a one-vertex bag but contributes no edge dependency across a prefix. An edgeless nonempty graph consequently has pathwidth zero. This minus-one convention is important: reporting its largest bag size one as the width would be off by one.

Disconnected components can be processed consecutively along the decomposition path without increasing the maximum component width. The input need not be connected. Do not connect components with invented edges just to satisfy an assumption borrowed from another graph algorithm; that would change pathwidth itself.

Keep exact search within its supported size

The form accepts at most sixteen vertices. Its subset dynamic program is exponential in vertex count, even though it avoids enumerating every permutation explicitly. Search-state counts describe the implemented work, not a statistical confidence score or a practical memory budget for another solver.

The result is exact for the accepted simple unweighted graph under the completed search. Edge weights have no role, and loops or duplicates are rejected. Weighted pathwidth, directed variants and a decomposition with additional application-specific bag constraints are different problems and are not silently approximated here.

Use width as a structural guide

A small pathwidth can help dynamic programs process a graph in a linear sequence while retaining a limited active state. The actual runtime still depends on the problem and the state stored for each bag; width alone is not a universal timing prediction for every computation.

A large number of bags can coexist with low width, so do not judge a decomposition by visual length alone. If the application requires a streaming or linear layout, the path certificate may be more relevant than a branching-tree certificate. Verify that this restriction matches the intended algorithm before drawing conclusions from a comparison of the two invariants.

A few questions, answered

Is pathwidth always the same as treewidth?

No. Path decompositions are more restrictive, so pathwidth is at least treewidth and can be larger.

Is width the largest bag size?

It is the largest bag size minus one.

Can disconnected graphs be entered?

Yes. Their components can be arranged consecutively in the path decomposition.

Does a different optimal bag list mean an error?

Not necessarily. Many decompositions can certify the same minimum width.

Find your calculator

Start typing to explore the library.