Package dsa
Interface UF
- All Known Implementing Classes:
QuickFindUF
,QuickUnionUF
,WeightedQuickUnionUF
public interface UF
This interface specifies the API for the Union Find (UF) data structure.
-
Method Summary
Modifier and TypeMethodDescriptionboolean
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
.void
union
(int p, int q) Connects sitesp
andq
.
-
Method Details
-
find
int find(int p) Returns the canonical site of the component containing sitep
.- Parameters:
p
- a site.- Returns:
- the canonical site of the component containing site
p
.
-
count
int count()Returns the number of components.- Returns:
- the number of components.
-
connected
boolean connected(int p, int q) Returnstrue
if sitesp
andq
belong to the same component, andfalse
otherwise.- Parameters:
p
- one site.q
- the other site.- Returns:
true
if sitesp
andq
belong to the same component, andfalse
otherwise.
-
union
void union(int p, int q) Connects sitesp
andq
.- Parameters:
p
- one site.q
- the other site.
-