TheAlgorithms/C++ 1.0.0
All the algorithms implemented in C++
|
#include <cstdint>
#include <iostream>
#include <set>
#include <vector>
Go to the source code of this file.
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 | |
int64_t | graph::disjoint_union::find_set (int64_t val) |
Find the component where following node belongs to. | |
void | graph::disjoint_union::union_sets (int64_t node1, int64_t node2) |
Merge 2 components to become one. | |
uint32_t | graph::disjoint_union::no_of_connected_components () |
Find total no. of connected components. | |
static void | test () |
Test Implementations. | |
int | main () |
Main function. | |
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
Definition in file connected_components_with_dsu.cpp.
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 |
Definition at line 54 of file connected_components_with_dsu.cpp.
int main | ( | void | ) |
Main function.
Definition at line 117 of file connected_components_with_dsu.cpp.
void graph::disjoint_union::make_set | ( | ) |
function the initialize every node as it's own parent
Definition at line 43 of file connected_components_with_dsu.cpp.
uint32_t graph::disjoint_union::no_of_connected_components | ( | ) |
Find total no. of connected components.
Definition at line 85 of file connected_components_with_dsu.cpp.
|
static |
Test Implementations.
Definition at line 97 of file connected_components_with_dsu.cpp.
void graph::disjoint_union::union_sets | ( | int64_t | node1, |
int64_t | node2 ) |
Merge 2 components to become one.
node1 | 1st component |
node2 | 2nd component |
Definition at line 67 of file connected_components_with_dsu.cpp.
std::vector<uint32_t> graph::disjoint_union::connected_set_size {} |
Definition at line 38 of file connected_components_with_dsu.cpp.
uint32_t graph::disjoint_union::number_of_nodes = 0 |
Definition at line 36 of file connected_components_with_dsu.cpp.
std::vector<int64_t> graph::disjoint_union::parent {} |
Definition at line 37 of file connected_components_with_dsu.cpp.