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 Type
    Method
    Description
    boolean
    connected(int p, int q)
    Returns true if sites p and q belong to the same component, and false otherwise.
    int
    Returns the number of components.
    int
    find(int p)
    Returns the canonical site of the component containing site p.
    void
    union(int p, int q)
    Connects sites p and q.
  • Method Details

    • find

      int find(int p)
      Returns the canonical site of the component containing site p.
      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)
      Returns true if sites p and q belong to the same component, and false otherwise.
      Parameters:
      p - one site.
      q - the other site.
      Returns:
      true if sites p and q belong to the same component, and false otherwise.
    • union

      void union(int p, int q)
      Connects sites p and q.
      Parameters:
      p - one site.
      q - the other site.