Advanced maths

Graph bandwidth calculator with optimal vertex ordering

Find a vertex ordering that minimizes the largest endpoint-position gap over all edges.

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

Find a vertex ordering that minimizes the largest endpoint-position gap over all edges. This graph bandwidth calculation evaluates every supported ordering and returns an optimal witness. It keeps the labeling objective separate from graph diameter, matrix condition number and other quantities that also use the word bandwidth in different contexts.

THE FORMULAbw(G)=min_order max_(uv in E)|position(u)−position(v)|.

A worked example

Ordering a three-vertex path as 0,1,2 gives both edge gaps one. A nonempty graph needs at least gap one, proving bandwidth one.

Good to know

Undirected simple n≤8, full permutation search. Ignores weights; returns an optimal ordering only after complete bounded search.

Define a position map rather than changing the graph

An ordering assigns each vertex a distinct position from zero through n minus one. For an edge uv, its gap is the absolute difference between the positions of u and v. The bandwidth of an ordering is the largest such gap, and graph bandwidth is the minimum over all orderings.

Relabeling vertices changes their displayed names but does not alter the underlying optimum if the graph is relabeled consistently. The solver chooses positions, not new edges. Its ordering table shows position in the first column and the original vertex label in the second, avoiding confusion between a position and an input label.

Bandwidth measures the longest edge in a linear vertex ordering012Ordering 0,1,2Both gaps = 1At least one edgeOptimal width = 1
Ordering a three-vertex path as 0,1,2 gives both edge gaps one. A nonempty graph needs at least gap one, proving bandwidth one. Diagram is schematic; labels specify the numerical values.

The Exact pathwidth calculator with a path decomposition minimizes active prefix boundaries and returns path bags. Bandwidth instead penalizes the largest distance between edge endpoints in one linear ordering.

Connect the definition to adjacency-matrix bandwidth

When rows and columns of an adjacency matrix are permuted by the same vertex ordering, a nonzero edge entry lies that many positions from the main diagonal. Minimizing graph bandwidth brings every such entry as close to the diagonal as possible in the maximum-distance sense.

This is not minimizing the sum of all edge gaps, known as a different layout objective. Nor is it choosing a topological order of a directed graph. This page treats the input as undirected, so its optimal ordering has no precedence or temporal interpretation unless that comes from a separately justified model.

Verify a simple path

For the path zero–one–two, ordering the vertices in that same sequence makes both edge gaps one. Any nonempty graph has an edge joining distinct positions, so its bandwidth cannot be below one. The witness therefore attains the lower bound exactly.

Putting the middle vertex first, with the two endpoints afterward, creates one edge gap two and is worse. A reverse path ordering is just as optimal as the forward ordering. Different returned optimal labels can therefore represent equally valid layouts without changing the minimum numeric bandwidth.

Compare graphs with the same vertex count

A complete graph on n vertices contains an edge between the first and last positions in every ordering, so its bandwidth is n minus one. An edgeless graph has no positive edge gap and returns zero. Those two extremes share a vertex count but have very different layout requirements.

A star forces its center to be close to all leaves, and placing the center near the middle can improve the maximum gap. Degree can give intuition, but it does not uniquely determine bandwidth. The exact search compares full layouts rather than applying a degree-based rule as though it were always optimal.

Understand the permutation-search certificate

The implementation visits every vertex permutation for at most eight vertices and evaluates its maximum edge gap. It retains a best ordering only after the complete supported search succeeds. This directly proves optimality for that bounded instance rather than providing a heuristic ordering with an unverified minimum label.

Permutation counts grow factorially. The small cap is intentional and is not a limitation of the mathematical definition. Larger graph-layout problems can use heuristics or specialized methods, but their approximation status must remain visible. A low objective encountered early is only an upper bound until the search has completed.

Ignore weights only when the task is unweighted

An optional edge weight does not change this bandwidth definition. It is the endpoint position gap that matters, regardless of whether an edge was assigned a large travel time or benefit. A weighted bandwidth or communication-cost model would need a stated objective that uses those weights.

All declared vertices occupy positions, including isolated vertices. Their placement can vary freely while preserving an optimum, which increases ties. Loops and repeated edges are rejected by the simple-graph input checks; the solver does not interpret a duplicate row as additional layout importance.

Read the ordering before using it elsewhere

To permute an adjacency matrix, apply the returned vertex sequence to both rows and columns. Applying it only to rows does not represent the same relabeled graph and will not reproduce the bandwidth certificate. If an external tool expects an inverse permutation, convert positions and labels explicitly.

The output does not promise improved runtime for every sparse-matrix algorithm. Numerical factorization fill, cache behavior and parallel scheduling can depend on objectives other than maximum edge gap. Use graph bandwidth as the stated combinatorial layout measure and evaluate any downstream computational benefit separately.

A few questions, answered

Is graph bandwidth the graph diameter?

No. Diameter measures shortest-path distances. Bandwidth measures endpoint position gaps under an optimized ordering.

Do edge weights affect the answer?

No. This page uses the standard unweighted graph layout definition.

How do I use the ordering on a matrix?

Permute both rows and columns by the same returned vertex sequence.

Why can reversing an ordering give the same result?

Absolute position differences are unchanged by reversal, so every ordering has an equally good reverse.

Find your calculator

Start typing to explore the library.