WeightedQuickUnionUF Class |
The WeightedQuickUnionUF class represents a Union-Find data type (also known as the Disjoint-sets data type). It supports the Union and Find operations, along with a Connected operation for determining whether two sites are in the same component and a Count operation that returns the total number of components.
This implementation uses weighted quick union by size (without path compression). Initializing a data structure with N sites takes linear time. Afterwards, the Union, Find, and Connected operations take logarithmic time (in the worst case) and the Count operation takes constant time. For alternate implementations of the same API, see .
Namespace: Algs4Net
public class WeightedQuickUnionUF
The WeightedQuickUnionUF type exposes the following members.
Name | Description | |
---|---|---|
![]() | WeightedQuickUnionUF |
Initializes an empty union-Find data structure with N sites
0 through N-1. Each site is initially in its own
component. |
Name | Description | |
---|---|---|
![]() | Connected |
Returns true if the the two sites are in the same component. |
![]() | Find |
Returns the component identifier for the component containing site p. |
![]() ![]() | MainTest |
Reads in a sequence of pairs of integers (between 0 and N-1) from standard input,
where each integer represents some object;
if the sites are in different components, merge the two components
and print the pair to standard output. |
![]() | Union |
Merges the component containing site p with the
the component containing site q. |
This class is a C# port from the original Java class WeightedQuickUnionUF implementation by Robert Sedgewick and Kevin Wayne.