% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/minimum.spanning.tree.R
\name{mst}
\alias{mst}
\title{Minimum spanning tree}
\usage{
mst(graph, weights = NULL, algorithm = NULL, ...)
}
\arguments{
\item{graph}{The graph object to analyze.}

\item{weights}{Numeric vector giving the weights of the edges in the
graph. The order is determined by the edge ids. This is ignored if the
\code{unweighted} algorithm is chosen. Edge weights are interpreted as
distances.}

\item{algorithm}{The algorithm to use for calculation. \code{unweighted} can
be used for unweighted graphs, and \code{prim} runs Prim's algorithm for
weighted graphs.  If this is \code{NULL} then igraph will select the
algorithm automatically: if the graph has an edge attribute called
\code{weight} or the \code{weights} argument is not \code{NULL} then Prim's
algorithm is chosen, otherwise the unweighted algorithm is used.}

\item{\dots}{Additional arguments, unused.}
}
\value{
A graph object with the minimum spanning forest. To check whether it
is a tree, check that the number of its edges is \code{vcount(graph)-1}.
The edge and vertex attributes of the original graph are preserved in the
result.
}
\description{
A \emph{spanning tree} of a connected graph is a connected subgraph with
the smallest number of edges that includes all vertices of the graph.
A graph will have many spanning trees. Among these, the \emph{minimum spanning
tree} will have the smallest sum of edge weights.
}
\details{
The \emph{minimum spanning forest} of a disconnected graph is the collection
of minimum spanning trees of all of its components.

If the graph is not connected a minimum spanning forest is returned.
}
\section{Related documentation in the C library}{
\href{https://igraph.org/c/html/0.10.17/igraph-Structural.html#igraph_minimum_spanning_tree_unweighted}{\code{minimum_spanning_tree_unweighted()}}, \href{https://igraph.org/c/html/0.10.17/igraph-Structural.html#igraph_minimum_spanning_tree_prim}{\code{minimum_spanning_tree_prim()}}, \href{https://igraph.org/c/html/0.10.17/igraph-Basic.html#igraph_edges}{\code{edges()}}, \href{https://igraph.org/c/html/0.10.17/igraph-Basic.html#igraph_get_eids}{\code{get_eids()}}, \href{https://igraph.org/c/html/0.10.17/igraph-Basic.html#igraph_vcount}{\code{vcount()}}, \href{https://igraph.org/c/html/0.10.17/igraph-Basic.html#igraph_ecount}{\code{ecount()}}
}

\examples{

g <- sample_gnp(100, 3 / 100)
g_mst <- mst(g)

}
\references{
Prim, R.C. 1957. Shortest connection networks and some
generalizations \emph{Bell System Technical Journal}, 37 1389--1401.
}
\seealso{
\code{\link[=components]{components()}}
}
\author{
Gabor Csardi \email{csardi.gabor@gmail.com}
}
\concept{minimum.spanning.tree}
\keyword{graphs}
