Math 2.0

Combinatorics Definition

Prim's algorithm

Builds on GraphConnected graphTreeSpanning treeMinimum spanning treeAlgorithm

Definition

Let G=(V,E)G = (V, E) be a finite connected graph, let w ⁣:E→ℝw \colon E \to \R be a weight function, and let r∈Vr \in V. Prim's algorithm with start vertex rr is the following algorithm.

  1. Set S={r}S = \set{r} and F=∅F = \emptyset.
  2. While S≠VS \ne V, choose an edge uv∈Euv \in E with u∈Su \in S and v∉Sv \notin S of least weight among such edges.
  3. Add vv to SS and uvuv to FF, then return to step 2.

At every stage (S,F)(S, F) is a tree. At the end, FF is the edge set of a minimum spanning tree of GG.

Remarks

Example: let GG be the triangle on {a,b,c}\set{a, b, c} with w(ab)=1w(ab) = 1, w(bc)=2w(bc) = 2, w(ac)=3w(ac) = 3, and let r=ar = a. The first step picks abab (weight 11 beats 33), and the second picks bcbc (weight 22 beats 33). The result {ab,bc}\set{ab, bc} is a spanning tree of least weight 33.

Non-example: if GG is not connected, step 2 eventually finds no edge leaving SS while S≠VS \ne V. The algorithm then only spans the component of rr.

Correctness follows from the cut property applied to the partition (S,V∖S)(S, V \setminus S). With a binary heap the running time is O(mlog⁡n)O(m \log n), and with a Fibonacci heap it is O(m+nlog⁡n)O(m + n \log n), where n=∣V∣n = \abs{V} and m=∣E∣m = \abs{E}.

Reading path

To understand this page from the ground up, read these 7 pages in order. The foundations come first.

Show the path as a graph
Each page uses the pages above it. The colour of the bar on a box shows how strong the evidence is, and the box also gives it as text. The list has the same pages.
  • no evidence level
  1. Algorithm concept
  2. Connected graph concept
  3. Graph concept
  4. Minimum spanning tree concept
  5. Spanning tree concept
  6. Tree concept
  7. Prim's algorithm definition

Further reading

  1. Web https://en.wikipedia.org/wiki/Prim%27s_algorithm
About this page
TagT6V9712YMB
URIm2://T6V9712YMB
Kinddefinition
WritingW0 stub
MSC05C85, 05C05, 90C27
DefinesPrim's algorithm
UsesGraph, Connected graph, Tree, Spanning tree, Minimum spanning tree, Algorithm
Changed3 November 2026

Markdown · JSON · Edit on GitHub

What this page needs for W1

  • an inventory row: the row of the inventory that the node accounts for (0 of 1)
  • a source with a locator (0 of 1)

The writing levels say how complete the text of a page is. They do not measure its truth.

What links here

No page links to this page yet.