arrow-left

All pages
gitbookPowered by GitBook
1 of 1

Loading...

6.3. Quiz

This section provides exercises for better understanding in disjoint sets.

hashtag
Implementation

  • Create the DisjointSetQuizarrow-up-right class under the setarrow-up-right package.

  • Assume that the method in the DisjointSet class uses the baseline approach:

  • A disjoint set can be represented by a tree. Update the method in the DisjointSetQuiz class that would result the following tree:

hashtag
Report

Write a report quiz6.pdf that includes the followings:

  • Describe how the values in the array changes after each call in the main() method.

  • Describe how the values in the array would change after calling find(0) once all keys are added as above, assuming that the find() method in DisjointSet class uses the efficient approach:

find()arrow-up-right
main()arrow-up-right
subsets[]arrow-up-right
subsets[]arrow-up-right
public int find(int id) {
    return (subsets[id] < 0) ? id : find(subsets[id]);
}
public int find(int id) {
    return (subsets[id] < 0) ? id : (subsets[id] = find(subsets[id]));
}