8.2. igraph_minimum_spanning_tree_prim — Calculates one minimum spanning tree of a weighted graph.

int igraph_minimum_spanning_tree_prim(const igraph_t *graph, igraph_t *mst,
				      const igraph_vector_t *weights);

This function uses Prim's method for carrying out the computation, see Prim, R.C.: Shortest connection networks and some generalizations, Bell System Technical Journal, Vol. 36, 1957, 1389--1401.

If the graph has more than one minimum spanning tree, the current implementation returns always the same one.

Directed graphs are considered as undirected for this computation.

If the graph is not connected then its minimum spanning forest is returned. This is the set of the minimum spanning trees of each component.

Arguments: 

graph:

The graph object.

mst:

The result of the computation, a graph object containing the minimum spanning tree of the graph. Do not initialize this object before passing it to this function, but be sure to call igraph_destroy() on it if you don't need it any more.

weights:

A vector containing the weights of the the edges. in the same order as the simple edge iterator visits them.

Returns: 

Error code: IGRAPH_ENOMEM, not enough memory. IGRAPH_EINVAL, length of weight vector does not match number of edges.

Time complexity: O(|V|+|E|), |V| is the number of vertices, |E| the number of edges in the graph.

See also: 

igraph_minimum_spanning_tree_unweighted() for unweighted graphs.