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.
-
Field Summary
-
Constructor Summary
ConstructorDescriptionWeightedUF
(int N) Create an empty union find data structure with N isolated sets. -
Method Summary
Modifier and TypeMethodDescriptionboolean
connected
(int p, int q) Are objects p and q in the same set?int
count()
Return the number of disjoint sets.int
find
(int p) Return the id of component corresponding to object p.static void
void
toString()
void
union
(int p, int q) Replace sets containing p and q with their union.
-
Field Details
-
id
-
sz
-
count
-
-
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:
toGraphviz
in interfaceUF
-
main
-