TheAlgorithms/C++ 1.0.0
All the algorithms implemented in C++
|
[Borůvkas Algorithm](https://en.wikipedia.org/wiki/Borůvka's_algorithm) to find the Minimum Spanning Tree More...
#include <cassert>
#include <climits>
#include <iostream>
#include <vector>
Go to the source code of this file.
Namespaces | |
namespace | greedy_algorithms |
for string class | |
namespace | boruvkas_minimum_spanning_tree |
Functions for the [Borůvkas Algorithm](https://en.wikipedia.org/wiki/Borůvka's_algorithm) implementation. | |
Functions | |
int | greedy_algorithms::boruvkas_minimum_spanning_tree::findParent (std::vector< std::pair< int, int > > parent, const int v) |
Recursively returns the vertex's parent at the root of the tree. | |
std::vector< std::vector< int > > | greedy_algorithms::boruvkas_minimum_spanning_tree::boruvkas (std::vector< std::vector< int > > adj) |
the implementation of boruvka's algorithm | |
int | greedy_algorithms::boruvkas_minimum_spanning_tree::test_findGraphSum (std::vector< std::vector< int > > adj) |
counts the sum of edges in the given tree | |
static void | tests () |
Self-test implementations. | |
int | main () |
Main function. | |
[Borůvkas Algorithm](https://en.wikipedia.org/wiki/Borůvka's_algorithm) to find the Minimum Spanning Tree
Boruvka's algorithm is a greepy algorithm to find the MST by starting with small trees, and combining them to build bigger ones.
Combine each group with the group it shares its smallest edge, adding the smallest edge to the MST.
It assumes that the graph is connected. Non-connected edges can be represented using 0 or INT_MAX
Definition in file boruvkas_minimum_spanning_tree.cpp.
std::vector< std::vector< int > > greedy_algorithms::boruvkas_minimum_spanning_tree::boruvkas | ( | std::vector< std::vector< int > > | adj | ) |
the implementation of boruvka's algorithm
adj | a graph adjancency matrix stored as 2d vectors. |
Definition at line 60 of file boruvkas_minimum_spanning_tree.cpp.
int greedy_algorithms::boruvkas_minimum_spanning_tree::findParent | ( | std::vector< std::pair< int, int > > | parent, |
const int | v ) |
Recursively returns the vertex's parent at the root of the tree.
parent | the array that will be checked |
v | vertex to find parent of |
Definition at line 47 of file boruvkas_minimum_spanning_tree.cpp.
int main | ( | void | ) |
Main function.
Definition at line 224 of file boruvkas_minimum_spanning_tree.cpp.
int greedy_algorithms::boruvkas_minimum_spanning_tree::test_findGraphSum | ( | std::vector< std::vector< int > > | adj | ) |
counts the sum of edges in the given tree
adj | 2D vector adjacency matrix |
Definition at line 175 of file boruvkas_minimum_spanning_tree.cpp.
|
static |
Self-test implementations.
Definition at line 196 of file boruvkas_minimum_spanning_tree.cpp.