Question: **Complete the code of the attached file disjoint-set_incomplete.cpp. #Code will be C++ ***disjoint-set_incomplete.cpp: #include using namespace std; /// Final task: implement path compression and union

 **Complete the code of the attached file disjoint-set_incomplete.cpp. #Code will be

**Complete the code of the attached file disjoint-set_incomplete.cpp.

#Code will be C++

***disjoint-set_incomplete.cpp:

#include using namespace std;

/// Final task: implement path compression and union by rank void make_set(int p[], int x){ p[x] = x; cout

int find_set(int p[], int x){ if (x!=p[x]) return find_set(p, p[x]); return p[x]; }

void _union(int p[], int x, int y){ int a = find_set(p, x); int b = find_set(p, y); p[a] = b; cout int main(){

int N; /// take N input from user

/// create the parent array for a disjoint set of N elements int p[N]; for (int i=0;i

while(1){ /// take an integer "option" as input. int option;

/// if "option" is 1, take another integer x as input, /// check if x is an element of the disjoint set or not, and /// if it is then print the root/representative-element of x if (option==1){

}

/// if "option" is 2, take integers x and y as input, /// check if x and y are elements of the disjoint set or not, and /// if they are check if they belong to the same set or not else if (option==2){

}

/// if "option" is 3, take integers x and y as input, /// check if x and y are elements of the disjoint set or not, and /// if they are then union them else if (option==3){

}

else { return 0; } }

}

Question 1: Complete the code of the attached file disjoint-set_incomplete.cpp

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!