Click or drag to resize
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 .

Inheritance Hierarchy
SystemObject
  Algs4NetWeightedQuickUnionUF

Namespace: Algs4Net
Assembly: Algs4Net (in Algs4Net.dll) Version: 1.0.0.0 (1.0.0.0)
Syntax
C#
public class WeightedQuickUnionUF

The WeightedQuickUnionUF type exposes the following members.

Constructors
  NameDescription
Public methodWeightedQuickUnionUF
Initializes an empty union-Find data structure with N sites 0 through N-1. Each site is initially in its own component.
Top
Properties
  NameDescription
Public propertyCount
Returns the number of components.
Top
Methods
  NameDescription
Public methodConnected
Returns true if the the two sites are in the same component.
Public methodFind
Returns the component identifier for the component containing site p.
Public methodStatic memberMainTest
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.
Public methodUnion
Merges the component containing site p with the the component containing site q.
Top
Remarks
For additional documentation, see Section 1.5 of Algorithms, 4th Edition by Robert Sedgewick and Kevin Wayne.

This class is a C# port from the original Java class WeightedQuickUnionUF implementation by Robert Sedgewick and Kevin Wayne.

See Also