|
Algorithms_in_C++ 1.0.0
Set of algorithms implemented in C++.
|
#include <iostream>#include <set>#include <vector>Namespaces | |
| namespace | graph |
| Graph Algorithms. | |
| namespace | disjoint_union |
| Functions for Disjoint union implementation. | |
Functions | |
| void | graph::disjoint_union::make_set () |
| function the initialize every node as it's own parent More... | |
| int64_t | graph::disjoint_union::find_set (int64_t val) |
| Find the component where following node belongs to. More... | |
| void | graph::disjoint_union::union_sets (int64_t node1, int64_t node2) |
| Merge 2 components to become one. More... | |
| uint32_t | graph::disjoint_union::no_of_connected_components () |
| Find total no. of connected components. More... | |
| static void | test () |
| Test Implementations. More... | |
| int | main () |
| Main function. More... | |
Variables | |
| uint32_t | graph::disjoint_union::number_of_nodes = 0 |
| std::vector< int64_t > | graph::disjoint_union::parent {} |
| std::vector< uint32_t > | graph::disjoint_union::connected_set_size {} |
The Disjoint union is the technique to find connected component in graph efficiently.
In Graph, if you have to find out the number of connected components, there are 2 options
| int64_t graph::disjoint_union::find_set | ( | int64_t | val | ) |
Find the component where following node belongs to.
| val | parent of val should be found |
| int main | ( | void | ) |
| void graph::disjoint_union::make_set | ( | ) |
function the initialize every node as it's own parent
| uint32_t graph::disjoint_union::no_of_connected_components | ( | ) |
Find total no. of connected components.
|
static |
Test Implementations.
| void graph::disjoint_union::union_sets | ( | int64_t | node1, |
| int64_t | node2 | ||
| ) |
Merge 2 components to become one.
| node1 | 1st component |
| node2 | 2nd component |