Class UnionFindRemSP

    • Constructor Detail

      • UnionFindRemSP

        public UnionFindRemSP​(int n)
        Initializes the disjoint-set data structure.
        Parameters:
        n - the overall size of the domain
    • Method Detail

      • size

        public int size()
        Description copied from interface: IntDisjointSets
        Returns the size of the universe. The elements of the universe are the integers between 0 (inclusive) and size() (exclusive).
        Specified by:
        size in interface IntDisjointSets
        Returns:
        the size of the universe
      • equivalent

        public boolean equivalent​(int x,
                                  int y)
        Description copied from interface: IntDisjointSets
        Checks if two elements are in the same set.
        Specified by:
        equivalent in interface IntDisjointSets
        Parameters:
        x - the first element
        y - the second element
        Returns:
        true if x and y are in the same set, false otherwise
      • find

        public int find​(int x)
        Finds the set of a given element, and compresses the path to the root node.
        Specified by:
        find in interface IntDisjointSets
        Parameters:
        x - the element
        Returns:
        the identifier of the set which contains the given element
      • union

        public boolean union​(int x,
                             int y)
        Unites the sets containing the two given elements.
        Specified by:
        union in interface IntDisjointSets
        Parameters:
        x - the first element
        y - the second element
        Returns:
        true if two disjoint sets have been united as a result, false otherwise
      • link

        public int link​(int x,
                        int y)
        Unites two given sets. Note that the behavior of this method is not specified if the given parameters are normal elements and no set identifiers.
        Specified by:
        link in interface IntDisjointSets
        Parameters:
        x - the first set
        y - the second set
        Returns:
        the identifier of the resulting set (either x or y)