A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://TheAlgorithms.github.io/C-Plus-Plus/df/d28/dsu__union__rank_8cpp_source.html below:

TheAlgorithms/C++: data_structures/dsu_union_rank.cpp Source File

Go to the documentation of this file. 38

vector<uint64_t>

depth

;

45 explicit dsu

(uint64_t n) {

50 for

(uint64_t i = 0; i < n; i++) {

121

vector<uint64_t> ans;

122 while

(

p

[i] != i) {

147

vector<uint64_t> ans = {7, 5};

148 for

(uint64_t i = 0; i < ans.size(); i++) {

152

cout <<

"1st test passed!"

<<

endl

;

172

vector<uint64_t> ans = {2, 1, 10};

173 for

(uint64_t i = 0; i < ans.size(); i++) {

177

cout <<

"2nd test passed!"

<<

endl

;

Disjoint sets union data structure, class based representation.

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)

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

bool isSame(uint64_t i, uint64_t j)

A utility function which check whether i and j belongs to same set or not.

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 > getParents(uint64_t i)

Method to print all the parents of i, or the path from i to representative.

vector< uint64_t > setSize

size of each chunk(set)

static void test2()

Self-implementations, 2nd test.

int main()

Main function.

static void test1()

Self-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