Dijkstra-Prim Method¶
Definition¶
The Dijkstra-Prim method constructs a minimum spanning tree in a connected undirected network with nonnegative edge lengths. Let be the set of vertices reached so far; start with containing one arbitrary vertex and no selected edges. Repeatedly select a shortest edge joining a vertex in to a vertex outside , add that edge, and add the outside endpoint to . Stop when every vertex belongs to .
Interpretation¶
The method grows one connected tree from a start vertex. Each step adds the cheapest edge that brings in a vertex not yet reached, so the selected edges never form a cycle and never fall apart into separate pieces.
The numbers in brackets give the order of selection when the method starts at : first (2), then (1). The oval marks after these two steps. The edges leaving are (5), (8) and (10), so is chosen next; is no longer a candidate because both its ends are in . Then and follow, for a total length of 13.
Only edges between and the rest are compared: an edge inside would close a cycle, and an edge with neither end in would start a second piece. The cheapest crossing edge is a safe choice: every spanning tree uses at least one edge between and the rest, and one can show that a cheapest such edge always belongs to some minimum spanning tree.
The shortest path algorithm grows a set in the same way but compares , the full distance from the origin, instead of the length of the edge alone. Mixing up the two is a common slip: the Dijkstra-Prim method minimizes the total length of the tree, not the distance from the start vertex.
Key Results¶
- Compare edges crossing from the whole set , not only from the last added vertex.
- Ties can be broken arbitrarily.
- The starting vertex can change the construction order without changing the minimum total value.
Examples¶
In the figure, each green edge label gives its weight and selection step in brackets. After reaching , is cheaper than or ; is ineligible because both endpoints are already in . The five selected edges have total length 13.
- In the Euclidean example, starting with selects edge of length .
- The next edge is , of length 5.
Prerequisites¶
Related Concepts¶
Sources¶
- OR Modelling · Week 4
Aliases: Prim-Jarník algorithm, Jarník's algorithm, Prim's method Keywords: Prim's algorithm Symbols: square root
Last updated: 20 October 2026 03:02
Dijkstra-Prim MethodMinimum Spanning TreeKruskal MethodShortest Path Algorithm