Package dsa
Class QuickUnionUF
- java.lang.Object
-
- dsa.QuickUnionUF
-
-
Constructor Summary
Constructors Constructor Description QuickUnionUF(int n)
Constructs an empty union-find data structure with n sites.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
connected(int p, int q)
Returnstrue
if sitesp
andq
belong to the same component, andfalse
otherwise.int
count()
Returns the number of components.int
find(int p)
Returns the canonical site of the component containing sitep
.static void
main(String[] args)
Unit tests the data type.void
union(int p, int q)
Connects sitesp
andq
if they are not already connected.
-
-
-
Method Detail
-
find
public int find(int p)
Description copied from interface:UF
Returns the canonical site of the component containing sitep
.
-
count
public int count()
Description copied from interface:UF
Returns the number of components.
-
connected
public boolean connected(int p, int q)
Description copied from interface:UF
Returnstrue
if sitesp
andq
belong to the same component, andfalse
otherwise.
-
union
public void union(int p, int q)
Description copied from interface:UF
Connects sitesp
andq
if they are not already connected.
-
main
public static void main(String[] args)
Unit tests the data type.- Parameters:
args
- the command-line arguments.
-
-