getMinimumSpanningTree
computes a minimum cost
spanning tree. This function provides methods to find a
minimum cost spanning tree with the three most commonly
used algorithms: "Prim", "Kruskal" and "Boruvka".
getMinimumSpanningTree(nodes, arcs, algorithm, start.node = 1, show.data = TRUE, show.graph = TRUE, check.graph = FALSE)
FALSE
by default.TRUE
) or not
(FALSE
). The default is TRUE
.TRUE
) or not
(FALSE
). The default is TRUE
.getMinimumSpanningTree
returns a list with:Prim's algorithm was developed in 1930 by the mathematician Vojtech Jarnik, independently proposed by the computer scientist Robert C. Prim in 1957 and rediscovered by Edsger Dijkstra in 1959. This is a greedy algorithm that can find a minimum spanning tree in a connected weighted undirected graph by adding minimum cost arcs leaving visited nodes recursively.
Kruskal's algorithm was published for first time in 1956 by mathematician Joseph Kruskal. This is a greedy algorithm that finds a minimum cost spanning tree in a connected weighted undirected graph by adding, without form cycles, the minimum weight arc of the graph in each iteration.
Boruvka's algorithm was published for first time in 1926 by mathematician Otakar Boruvka. This algorithm go through a connected weighted undirected graph, reviewing each component and adding the minimum weight arcs without repeat it until one minimum spanning tree is complete.
Kruskal, Joshep B. (1956), "On the Shortest Spanning Subtree of a Graph and the Traveling Salesman Problem", Proceedings of the American Mathematical Society, Vol. 7, No. 1 (Feb., 1956), pp. 48-50.
Boruvka, Otakar (1926). "O jistem problemu minimalnim (About a certain minimal problem)". Prace mor. prirodoved. spol. v Brne III (in Czech, German summary) 3: 37-58.
# Graph
nodes <- 1:4
arcs <- matrix(c(1,2,2, 1,3,15, 1,4,3, 2,3,1, 2,4,9, 3,4,1),
ncol = 3, byrow = TRUE)
# Minimum cost spanning tree with several algorithms
getMinimumSpanningTree(nodes, arcs, algorithm = "Prim")
getMinimumSpanningTree(nodes, arcs, algorithm = "Kruskal")
getMinimumSpanningTree(nodes, arcs, algorithm = "Boruvka")
Run the code above in your browser using DataCamp Workspace