Prim  Family of functions  pgRouting Manual (3.4)
Prim  Family of functions
Description
The prim algorithm was developed in 1930 by Czech mathematician Vojtěch Jarník. It is a greedy algorithm that finds a minimum spanning tree for a weighted undirected graph. This means it finds a subset of the edges that forms a tree that includes every vertex, where the total weight of all the edges in the tree is minimized. The algorithm operates by building this tree one vertex at a time, from an arbitrary starting vertex, at each step adding the cheapest possible connection from the tree to another vertex.
This algorithms find the minimum spanning forest in a possibly disconnected graph; in contrast, the most basic form of Prim’s algorithm only finds minimum spanning trees in connected graphs. However, running Prim’s algorithm separately for each connected component of the graph, then it is called minimum spanning forest.
The main characteristics are:

It’s implementation is only on undirected graph.

Process is done only on edges with positive costs.

When the graph is connected

The resulting edges make up a tree


When the graph is not connected,

Finds a minimum spanning tree for each connected component.

The resulting edges make up a forest.


Prim’s running time: \(O(E * log V)\)
Note
From boost Graph: "The algorithm as implemented in Boost.Graph does not produce correct results on graphs with parallel edges."
Inner Queries
Column 
Type 
Default 
Description 


ANYINTEGER 
Identifier of the edge. 


ANYINTEGER 
Identifier of the first end point vertex of the edge. 


ANYINTEGER 
Identifier of the second end point vertex of the edge. 


ANYNUMERICAL 
Weight of the edge (



ANYNUMERICAL 
1 
Weight of the edge (

Where:
 ANYINTEGER :

SMALLINT
,INTEGER
,BIGINT
 ANYNUMERICAL :

SMALLINT
,INTEGER
,BIGINT
,REAL
,FLOAT
See Also

Boost: Prim’s algorithm

Wikipedia: Prim’s algorithm
Indices and tables