Package dsa

Interface UF

    • Method Summary

      All Methods Instance Methods Abstract Methods 
      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 count()
      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 if they are not already connected.
    • Method Detail

      • 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 if they are not already connected.
        Parameters:
        p - one site.
        q - the other site.