emory-courses / dsa-java

Data Structures and Algorithms in Java
https://emory.gitbook.io/dsa-java/
42 stars 55 forks source link

[QZ6] Quick Question Regarding Disjoint Set #165

Closed HallOfSam closed 4 years ago

HallOfSam commented 4 years ago

In the exercises for Disjoint Sets we are required to build the tree structure as shown in that graph. But does anyone know whether the node that contains 3 is a child node or a parent node? Thanks in advance!

liamsgordon commented 4 years ago

I believe 3 is the parent node, so at the end, if you use the ds.find(x) for any of the 5 subsets you get 3. I am not positive about this but it seems correct.

HallOfSam commented 4 years ago

I believe 3 is the parent node, so at the end, if you use the ds.find(x) for any of the 5 subsets you get 3. I am not positive about this but it seems correct.

Yeh I agree. It makes no sense if 3 is a child node, since a child node cannot point to more than 1 parent.

marvinquiet commented 4 years ago

Yes, it should be parent according to the figure because after certain behaviors, you want to generate a result exactly same as the output.