Advanced maths

Minimum edge graph spanner calculator with a stretch bound

Minimize retained edge count while bounding every shortest-path detour relative to the original connected weighted graph.

Your numbers

Zero-based labels 0 through n−1, including isolated vertices.
One row: u v length.
At least 1. Every retained pair distance is compared with the original shortest distance.

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

Minimize retained edge count while bounding every shortest-path detour relative to the original connected weighted graph.

THE FORMULAmin |E(H)| subject to d_H(u,v)≤t·d_G(u,v) for every u,v; H⊆G spans V.

A worked example

A unit four-cycle with stretch limit 2 needs all four edges. Removing any edge creates an endpoint detour of 3 instead of 1, exceeding the permitted factor 2.

Good to know

Connected simple undirected graph on 1–8 vertices and at most 16 edges; positive lengths 0.000001–1,000,000, stretch 1–100. Exact edge-subset search capped at 100,000 evaluated subgraphs; all-pair comparisons allow 1e−9·max(1,bound) length tolerance. One minimum-count subgraph, no minimum-length secondary objective, additive/fault-tolerant/directed claim.

Keep few edges while bounding detours

A multiplicative t-spanner is a spanning subgraph whose shortest-path distance between every vertex pair is at most t times the original graph distance. The word spanning means that every declared vertex remains present. The optimization on this page minimizes the number of retained edges.

A spanner is not necessarily a tree. Cycles can be essential when the allowed detour is small. This distinguishes the problem from finding a minimum-stretch spanning tree, where exactly n minus one edges are retained and the objective instead optimizes the resulting stretch.

A unit four-cycle with stretch limit 2 needs all four edges0123Unit four-cycleStretch limit = 2Delete one edge:detour 3 > 2 × 1All 4 edges needed
Scroll across to see the full diagram.
A unit four-cycle with stretch limit 2 needs all four edges. Removing any edge creates an endpoint detour of 3 instead of 1, exceeding the permitted factor 2.

Compare this with the Minimum stretch spanning tree calculator from graph edges. Minimize retained edge count subject to a supplied stretch bound; a spanner may retain cycles and need not be a tree.

Use positive lengths and a connected graph

Each edge row specifies two zero-based vertices and a strictly positive length. The supported lengths are at least one millionth, avoiding zero-distance pairs and unstable ratios. The input graph must be connected so that every reference pair has a finite original shortest-path distance.

The stretch limit is at least one. It multiplies original shortest-path distances, not individual direct-edge lengths unless that edge is itself a shortest route. Long redundant edges may be removable even when t equals one. Edge count is minimized without a secondary preference for the sum of retained lengths.

Search subgraphs and test all pair distances

The calculator enumerates retained-edge subsets below the best known edge count, skipping sets with fewer than n minus one edges. Floyd–Warshall distances are computed for each candidate. Disconnected candidates fail the all-pairs bounds, so connectivity is enforced through the same distance certificate.

A valid candidate becomes the current best and tightens later pruning. Exhausting all smaller subsets proves the minimum retained count for the accepted numerical comparison convention. Distances use a stated relative-scale tolerance, so pairs lying essentially on the stretch threshold should be assessed with that tolerance in mind.

A four-cycle can require all four edges

The default input is a unit-length four-cycle and a stretch bound of two. Keeping all four edges obviously gives stretch one. Removing any one edge produces a path through all four vertices, so the endpoints of the removed edge become three units apart.

Their original distance was one, making that pair's stretch three. Since three exceeds the allowed two, every three-edge spanning candidate fails. Fewer edges disconnect the graph. The minimum count is therefore four: this is a concrete case where requiring the answer to be a tree would make the valid optimum impossible to return.

Read the paths as a detour certificate

For every unordered pair, the result shows the original distance, retained distance, ratio and an explicit retained-edge path. The largest listed ratio is the reported maximum stretch. This table connects the global objective to individual detours that can be checked from the selected edge list.

A retained edge can support many pairwise paths, and an original edge can disappear without violating its endpoints' bound if an alternative route is short enough. Do not judge feasibility only by inspecting the removed edges visually; all vertex pairs matter, including pairs without a direct connection in the original graph.

Know the finite exact-search scope

The supported graph contains at most eight vertices and sixteen edges, with finite positive lengths and no parallel pairs. A search-state cap guards the enumeration. Hitting that cap produces an unresolved error rather than promoting the best subgraph encountered so far to a certified minimum.

The numerical comparison allows one billionth times the larger of one and the requested distance bound. This is an explicit floating-point convention, not an exact algebraic certificate for arbitrarily precise decimal lengths. Very large stretch limits are bounded, and directed graphs, edge-failure resilience and additive spanners are not included.

Compare sparsity and performance carefully

The output answers a precise count question: how many of the original edges must remain under one detour bound? It does not minimize construction cost, total cable length, maximum degree or the number of crossings in a geometric drawing. Different objectives can select different sparse subgraphs.

Trying several stretch limits illustrates the sparsity tradeoff, but the optimal edge count may stay constant over a range before dropping at a critical ratio. Preserve the same lengths and vertex set during that comparison. An observed plateau is a property of this finite instance, not evidence that all networks behave smoothly or share the same threshold.

A few questions, answered

Does a spanner have to be a tree?

No. A cycle may be necessary to meet the stretch constraint; the default four-cycle demonstrates this.

Does stretch compare with direct edge length?

It compares retained shortest-path distance with the original shortest-path distance for each vertex pair.

Is total retained length minimized?

No. The objective minimizes the number of retained edges, with no secondary optimization of their summed lengths.

Can a disconnected graph be entered?

No. This page requires finite reference distances for every pair, so the original graph must be connected.

Find your calculator

Start typing to explore the library.