6.3. Quiz
This section provides exercises for better understanding in disjoint sets.
Implementation
Create the
DisjointSetQuizclass under thesetpackage.Assume that the
find()method in theDisjointSetclass uses the baseline approach:public int find(int id) { return (subsets[id] < 0) ? id : find(subsets[id]); }A disjoint set can be represented by a tree. Update the
main()method in theDisjointSetQuizclass that would result the following tree:

Report
Write a report quiz6.pdf that includes the followings:
Describe how the values in the
subsets[]array changes after each call in themain()method.Describe how the values in the
subsets[]array would change after callingfind(0)once all keys are added as above, assuming that thefind()method inDisjointSetclass uses the efficient approach:public int find(int id) { return (subsets[id] < 0) ? id : (subsets[id] = find(subsets[id])); }
Last updated
Was this helpful?