(uint64_t n) {
49 for(uint64_t i = 0; i < n; i++) {
56 for(uint64_t i = 0; i < n; i++) {
63 for(uint64_t i = 0; i < n; i++) {
136vector<uint64_t>
get(uint64_t i) {
137vector<uint64_t> ans;
140ans.push_back(
size(i));
177vector<uint64_t> ans = {1, 4, 3};
178 for(uint64_t i = 0; i < ans.size(); i++) {
179assert(d.
get(4).at(i) == ans[i]);
181cout <<
"1st test passed!"<<
endl;
195vector<uint64_t> ans = {3, 7, 4};
196 for(uint64_t i = 0; i < ans.size(); i++) {
197assert(d.
get(3).at(i) == ans[i]);
199cout <<
"2nd test passed!"<<
endl;
Disjoint sets union data structure, class based representation.
vector< uint64_t > get(uint64_t i)
prints the minimum, maximum and size of the set to which i belongs to
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)
uint64_t size(uint64_t i)
A utility function that returns the size of the set to which i belongs to.
vector< uint64_t > minElement
minimum of each set to which i belongs to
vector< uint64_t > p
keeps track of the parent of ith element
vector< uint64_t > maxElement
maximum of each set to which i belongs to
vector< uint64_t > depth
tracks the depth(rank) of i in the tree
bool isSame(uint64_t i, uint64_t j)
A utility function which check whether i and j belongs to same set or not.
uint64_t get_max(uint64_t i)
A utility function that returns the max element of the set to which i belongs to.
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 com...
vector< uint64_t > setSize
size of each chunk(set)
uint64_t get_min(uint64_t i)
A utility function that returns the min element of the set to which i belongs to.
static void test2()
Self-implementations, 2nd test.
int main()
Main function.
static void test1()
Self-test implementations, 1st test.
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4