Question
Please provide a description of the algorithm and the explanation of correctness and complexity of final_sets(),thanks! --------------------------------- class uandf { public: uandf(int n); void make_set(int
Please provide a description of the algorithm and the explanation of correctness and complexity of final_sets(),thanks!
---------------------------------
class uandf { public: uandf(int n); void make_set(int i); void union_set(int i, int j); int find_set(int i); int final_sets(); int get_sets(); int get_size(int i); private: int *parent, *rank, numSets, count, *size; bool final; void link(int x, int y); };
uandf::uandf(int n){ final = false; count = n; parent = new int[n]; rank = new int[n]; size = new int[n]; numSets = 0; for (int i = 0; i
void uandf::make_set(int i){ if (final) return; parent[i] = i; rank[i] = 0; size[i]=1; numSets++; } void uandf::link(int x, int y){
if (rank[x] > rank[y]) parent[y] = x; else if (rank[x]
return parent[i]; } int uandf::final_sets(){ parent = new int[count]; rank = new int[count]; final = true; for (int i = 0; i 10. (programming question) Finding connected components in a binary image. a) An Union-Find data structure should be implemented, with the most efficient algorithm, as an abstract data type (a class in C++ or java) with the following operations. uand (n): constructs an union-find data type with n elements, 1, 2, ...,n. make_set(i): creates a new set whose only member and thus representative) is i. union_sets(i, j): unites the dynamic sets that contains i and j, respectively, into a new set that is the union of these two sets. find_set(i); returns the representative of the set containing i. final sels(): returns the total number of current sets and finalizes the current sets: (i) make_set() and union sets will have no effect after this operation and (ii) resets the representatives of the sets so that integers from 1 to final sets) will be used as representatives. 10. (programming question) Finding connected components in a binary image. a) An Union-Find data structure should be implemented, with the most efficient algorithm, as an abstract data type (a class in C++ or java) with the following operations. uand (n): constructs an union-find data type with n elements, 1, 2, ...,n. make_set(i): creates a new set whose only member and thus representative) is i. union_sets(i, j): unites the dynamic sets that contains i and j, respectively, into a new set that is the union of these two sets. find_set(i); returns the representative of the set containing i. final sels(): returns the total number of current sets and finalizes the current sets: (i) make_set() and union sets will have no effect after this operation and (ii) resets the representatives of the sets so that integers from 1 to final sets) will be used as representatives
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started