Package algs15
Class WeightedUF
java.lang.Object
algs15.WeightedUF
- All Implemented Interfaces:
UF
The
UF class represents a union-find data data structure.
It supports the union and find
operations, along with a method for determining the number of
disjoint sets.
This implementation uses weighted quick union. Creating a data structure with N objects takes linear time. Afterwards, all operations are logarithmic worst-case time.
For additional documentation, see Section 1.5 of Algorithms, 4th Edition by Robert Sedgewick and Kevin Wayne.
-
Constructor Summary
ConstructorsConstructorDescriptionWeightedUF(int N) Create an empty union find data structure with N isolated sets. -
Method Summary
Modifier and TypeMethodDescriptionbooleanconnected(int p, int q) Are objects p and q in the same set?intcount()Return the number of disjoint sets.intfind(int p) Return the id of component corresponding to object p.static voidvoidtoString()voidunion(int p, int q) Replace sets containing p and q with their union.
-
Constructor Details
-
WeightedUF
Create an empty union find data structure with N isolated sets.
-
-
Method Details
-
count
Return the number of disjoint sets. -
connected
Are objects p and q in the same set? -
find
Return the id of component corresponding to object p. -
union
Replace sets containing p and q with their union. -
toString
-
toGraphviz
- Specified by:
toGraphvizin interfaceUF
-
main
-