Advanced maths

Minimum stretch spanning tree calculator from graph edges

Choose a spanning tree that minimizes the largest tree distance across any original edge.

Your numbers

Vertices are labeled 0 through n−1, including isolated vertices.
One edge per line: u,v. No loops or duplicate pairs. Blank means no edges.

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

Choose a spanning tree that minimizes the largest tree distance across any original edge. Return the exact minimum maximum stretch, a selected tree and the edge attaining its bottleneck.

THE FORMULAstretch(T)=max_{uv∈E(G)} d_T(u,v); optimum=min_{spanning trees T⊆G} stretch(T), for unweighted G.

A worked example

In the four-cycle 0–1–2–3–0, every spanning tree deletes one cycle edge. The deleted edge’s endpoints are distance 3 in the remaining path, while selected edges have distance 1. Minimum maximum stretch is therefore 3.

Good to know

Connected simple unweighted graphs with 1–8 vertices and at most 28 edges. Enumerates spanning trees with cycle pruning; 5000000 recursive-state cap throws an unfinished-search error. Singleton stretch is defined as 0. No average-stretch or weighted objective.

Minimize the worst detour

A spanning tree connects every graph vertex using original edges and contains no cycles. For each original edge, measure how many tree edges are needed to travel between its endpoints. The maximum of these distances is the tree’s stretch under this unweighted maximum-detour convention.

The calculator chooses the spanning tree with the smallest such maximum. This differs from minimizing total tree edge cost or average pairwise distance. Every spanning tree has the same number of unweighted edges, yet their worst detours can be very different when the original graph contains extra shortcuts.

The omitted cycle edge makes a three-edge detourOriginal four-cycle0123A spanning path0123Omitted edge 3–0 has distance 3
Scroll across to see the full diagram.
In the four-cycle 0–1–2–3–0, every spanning tree deletes one cycle edge. The deleted edge’s endpoints are distance 3 in the remaining path, while selected edges have distance 1. Minimum maximum stretch is therefore 3.

Compare this with the Minimum spanning tree calculator from weighted edges. Choose a spanning tree minimizing the worst original-edge distance in the tree,not total edge weight.

Enter a connected simple graph

Declare one to eight vertices and list each undirected edge once using two zero-based endpoints. Edges have unit length; do not add a weight column. Loops, repeated unordered pairs, out-of-range labels and fractional labels are rejected rather than silently changing the graph model.

The graph must be connected so that a spanning tree exists. Isolated declared vertices therefore matter even when omitted from all edge rows. A single vertex is accepted with no edges. Its stretch is defined here as zero because there are no original edges across which to measure a detour.

Work through the four cycle

The default square has edges 0–1, 1–2, 2–3 and 3–0. A spanning tree must contain three of them. Removing 3–0 leaves the path 0–1–2–3, so the original edge 3–0 has endpoints separated by three tree edges instead of its original single edge.

All selected tree edges have distance one. Whichever cycle edge is omitted, its endpoints have distance three in the remaining path. Thus every possible spanning tree has maximum stretch three, making the displayed value both achievable and optimal without needing to trust a particular tie-breaking choice.

Why original edges suffice

The conventional maximum pairwise stretch compares tree distance with shortest-path distance in the original graph. If every original edge stretches by at most t, replace each edge of an original shortest path by its tree route. The resulting walk has length at most t times the original path length.

Tree distance cannot exceed that walk’s length, so the same bound holds for every vertex pair. Conversely, original edges are themselves vertex pairs at graph distance one. Therefore maximizing over entered edges gives the same worst ratio in this unweighted setting while producing a compact bottleneck witness.

Inspect the tree and distances

The tree array is the construction certificate. It must contain exactly n−1 original edges, be connected and contain no cycle. The edgeDistances entries then show the tree route length for every original edge, including edges omitted from the tree. Their maximum must equal the reported stretch.

The worstEdge identifies one edge attaining that maximum. More than one may tie, and different optimal spanning trees may have different bottleneck edges. The calculator reports one optimum, not a claim that its specific selected edges are necessary in every minimum-stretch tree.

Complete enumeration and its cap

The exact search considers inclusion and exclusion of graph edges, pruning branches that would create cycles or cannot reach n−1 chosen edges. Every surviving complete choice is a spanning tree. Breadth-first tree distances evaluate its objective, and the best tree is retained after the search finishes.

Recursive search is capped at five million states. If that limit is reached, the computation throws an explicit unfinished-search error. A good tree encountered earlier is only an upper bound until every potentially better branch is settled, so this page does not relabel such a partial incumbent as an exact optimum.

Choose the right tree objective

An input graph that is already a nontrivial tree has stretch one because every original edge is retained. A triangle has optimum two, while longer chordless cycles force a larger detour. These simple cases are useful checks when changing edge lists or testing relabeled versions of a graph.

The implementation does not handle edge lengths, weighted pairwise ratios, average stretch or degree constraints. A minimum-cost spanning tree can have poor maximum stretch, and a low-stretch tree can violate operational degree limits. Select the calculator whose objective and feasibility conditions match the intended network design.

A few questions, answered

Is this the minimum spanning tree objective?

No. It minimizes the worst original-edge detour, not total edge cost.

Why examine original edges only?

For unweighted graphs, bounding each edge’s tree detour bounds the distance ratio of every shortest path.

What is the answer for a graph already forming a tree?

It is 1 for a tree with at least one edge, and 0 for a singleton by this page’s convention.

Can a capped search return an exact optimum?

No. A resource-cap error explicitly marks the search unfinished.

Find your calculator

Start typing to explore the library.