Percentages and Math

Minimum Spanning Tree Calculator

List the connections and their costs to find the cheapest way to link every place.

Your numbers

Two names without spaces, then the cost, length or weight of linking them. Example data.

Result

Total cost of the cheapest connected network

11

4 of 7 connections used to join 5 places.

Total cost
11
Connections used
4
Places
5
Separate groups
1
Connections left out
3
Second method (Prim) total
11

Connections to build

OrderLinkCostRunning total
1B - C11
2B - D23
3A - C36
4D - E511

Connections left out

LinkCostWhy
A - B4would close a loop
C - D4would close a loop
C - E6would close a loop
How this was calculated
  1. Kruskal's method sorts all connections from cheapest to dearest and adds each one unless its two ends are already joined, which would make a loop.
  2. Prim's method grows the network from one place by always adding the cheapest link to a new place. It reaches the same total, 11, which is a check on the result.
  3. Every place is reachable, so the result is one tree with one link fewer than the number of places.
  • When several links cost the same, more than one cheapest network can exist; the total is the same, and this page lists the first one found in the order you typed the links.

Calculated using SumPanda.com · https://sumpanda.com/minimum-spanning-tree-calculator/

Results are estimates for general information. Verify important figures before relying on them.

Next step

How to use the minimum spanning tree calculator

  1. List the connections, one per line: two place names without spaces, then the cost, distance or weight of linking them, for example A B 4.
  2. Read the headline for the total cost of the cheapest network that joins every place.
  3. The first table lists the links to build, in the order they are chosen, with a running total. The second lists links left out because they would close a loop.
  4. If the places fall into separate groups, the result is a cheapest forest: one tree for each group.

Formula

Kruskal: sort all links by cost, add each link unless its ends are already joined

Prim: grow from one place, always adding the cheapest link to a new place

a spanning tree of n places uses exactly n - 1 links

Both methods give a tree of the same total cost, so the page runs both and shows the second total as a check. When several links cost the same, more than one cheapest tree can exist; the total stays the same.

Five places and seven possible links

The default links are A-B 4, A-C 3, B-C 1, B-D 2, C-D 4, C-E 6 and D-E 5. Kruskal adds B-C (1), B-D (2), A-C (3) and D-E (5), skipping C-D (4) and A-B (4) because they would close loops and C-E (6) because E is already joined.

The total is 1 + 2 + 3 + 5 = 11 with 4 links for 5 places. Prim's method from A reaches the same total of 11. A search over every set of 4 links finds no cheaper tree, so 11 is the minimum.

What a spanning tree is

A spanning tree connects every place without any loops. A minimum spanning tree is the one whose links cost least in total. It answers questions like how to lay cable, pipe or road between sites at the lowest cost when every site must be reachable, but it does not tell you the shortest route between two particular places.

The costs can be distances, prices or any other weight, and they can be negative. Parallel links between the same two places are allowed; the cheaper one is used. A link from a place to itself is rejected.

Related problems

A minimum spanning tree is different from a tour. To visit every place once and return, use the Shortest Route Calculator. To pair people with jobs at least cost, the Assignment Optimizer solves that problem, and for choosing items under a limit, the Knapsack Optimizer. The Linear Programming Solver handles general resource problems.

More math tools

For other numerical methods, try the Polynomial Root Finder, Root Finder and Numerical Integration Calculator.

Assumptions and limits

  • Each connection can be used in both directions at the same cost.
  • Place names contain no spaces, and up to 200 places and 2,000 links are supported.
  • Costs are plain numbers without units, and may be negative or zero.
  • Only the total cost is guaranteed to be minimal; the choice among equal-cost links depends on the order you typed them.

Formulas reviewed October 10, 2026. See the calculation methodology for how SumPanda rounds, tests and sources its formulas.

Frequently asked questions

Is the cheapest network always unique?

No. When several links share a cost, different trees can have the same total. The total is always the same, even when the chosen links differ.

What if some places cannot be reached from the others?

The result is a spanning forest with one tree for each group of places that are connected, and the page reports how many groups there are.

Does the tree give the shortest route between two places?

Not necessarily. It minimizes the total cost of the whole network. The path between two places inside the tree can be longer than the best direct route.

Why are some links left out?

A link is skipped when its two places are already connected through links chosen earlier, because adding it would create a loop that no network needs.