TheAlgorithms/C++ 1.0.0
All the algorithms implemented in C++
|
Disjoint sets union data structure, class based representation. More...
Public Member Functions | |
dsu (uint64_t n) | |
contructor for initialising all data members. | |
uint64_t | findSet (uint64_t i) |
Method to find the representative of the set to which i belongs to, T(n) = O(1) | |
void | UnionSet (uint64_t i, uint64_t j) |
Method that combines two disjoint sets to which i and j belongs to and make a single set having a common representative. | |
bool | isSame (uint64_t i, uint64_t j) |
A utility function which check whether i and j belongs to same set or not. | |
vector< uint64_t > | get (uint64_t i) |
prints the minimum, maximum and size of the set to which i belongs to | |
uint64_t | size (uint64_t i) |
A utility function that returns the size of the set to which i belongs to. | |
uint64_t | get_max (uint64_t i) |
A utility function that returns the max element of the set to which i belongs to. | |
uint64_t | get_min (uint64_t i) |
A utility function that returns the min element of the set to which i belongs to. | |
dsu (uint64_t n) | |
constructor for initialising all data members | |
uint64_t | findSet (uint64_t i) |
Method to find the representative of the set to which i belongs to, T(n) = O(logN) | |
void | unionSet (uint64_t i, uint64_t j) |
Method that combines two disjoint sets to which i and j belongs to and make a single set having a common representative. | |
bool | isSame (uint64_t i, uint64_t j) |
A utility function which check whether i and j belongs to same set or not. | |
vector< uint64_t > | getParents (uint64_t i) |
Method to print all the parents of i, or the path from i to representative. | |
Private Attributes | |
vector< uint64_t > | p |
keeps track of the parent of ith element | |
vector< uint64_t > | depth |
tracks the depth(rank) of i in the tree | |
vector< uint64_t > | setSize |
size of each chunk(set) | |
vector< uint64_t > | maxElement |
maximum of each set to which i belongs to | |
vector< uint64_t > | minElement |
minimum of each set to which i belongs to | |
Disjoint sets union data structure, class based representation.
n | number of elements |
Definition at line 34 of file dsu_path_compression.cpp.
|
inlineexplicit |
contructor for initialising all data members.
n | number of elements |
initially, all of them are their own parents
initially all have depth are equals to zero
initially set size will be equals to one
Definition at line 46 of file dsu_path_compression.cpp.
|
inlineexplicit |
constructor for initialising all data members
n | number of elements |
initially all of them are their own parents
Definition at line 45 of file dsu_union_rank.cpp.
|
inline |
Method to find the representative of the set to which i belongs to, T(n) = O(1)
i | element of some set |
using path compression
Definition at line 74 of file dsu_path_compression.cpp.
|
inline |
Method to find the representative of the set to which i belongs to, T(n) = O(logN)
i | element of some set |
using union-rank
Definition at line 62 of file dsu_union_rank.cpp.
|
inline |
prints the minimum, maximum and size of the set to which i belongs to
i | element of some set |
Definition at line 136 of file dsu_path_compression.cpp.
|
inline |
A utility function that returns the max element of the set to which i belongs to.
i | element of some set |
Definition at line 156 of file dsu_path_compression.cpp.
|
inline |
A utility function that returns the min element of the set to which i belongs to.
i | element of some set |
Definition at line 163 of file dsu_path_compression.cpp.
|
inline |
Method to print all the parents of i, or the path from i to representative.
i | element of some set |
Definition at line 120 of file dsu_union_rank.cpp.
|
inline |
A utility function which check whether i and j belongs to same set or not.
i | element of some set |
j | element of some set |
true
if element i
and j
ARE in the same set false
if element i
and j
are NOT in same set Definition at line 124 of file dsu_path_compression.cpp.
|
inline |
A utility function which check whether i and j belongs to same set or not.
i | element of some set |
j | element of some set |
true
if element i and j are in same set false
if element i and j are not in same set Definition at line 108 of file dsu_union_rank.cpp.
|
inline |
A utility function that returns the size of the set to which i belongs to.
i | element of some set |
Definition at line 149 of file dsu_path_compression.cpp.
|
inline |
Method that combines two disjoint sets to which i and j belongs to and make a single set having a common representative.
i | element of some set |
j | element of some set |
check if both belongs to the same set or not
always keeping the min as x shallow tree
making the shallower root's parent the deeper root
if same depth, then increase one's depth
total size of the resultant set
changing the maximum elements
Definition at line 88 of file dsu_path_compression.cpp.
|
inline |
Method that combines two disjoint sets to which i and j belongs to and make a single set having a common representative.
i | element of some set |
j | element of some set |
checks if both belongs to same set or not
we find representative of the i and j
always keeping the min as x in order to create a shallow tree
making the shallower tree, root parent of the deeper root
if same depth, then increase one's depth
total size of the resultant set
Definition at line 76 of file dsu_union_rank.cpp.
|
private |
tracks the depth(rank) of i in the tree
Definition at line 37 of file dsu_path_compression.cpp.
|
private |
maximum of each set to which i belongs to
Definition at line 39 of file dsu_path_compression.cpp.
|
private |
minimum of each set to which i belongs to
Definition at line 40 of file dsu_path_compression.cpp.
|
private |
keeps track of the parent of ith element
Definition at line 36 of file dsu_path_compression.cpp.
|
private |
size of each chunk(set)
Definition at line 38 of file dsu_path_compression.cpp.