Class DisjointSets


  • public class DisjointSets
    extends java.lang.Object
    A data structure that represents a partition of a set into disjoint subsets, and allows merging subsets. Set items are represented by integer indices. Initially each item is in its own subset. Client code can merge subsets of items as required for the algorithm being performed (e.g. set partitioning or clustering). The current partitioning can be computed at any time, and subset items accessed by their indices. See the Wikipedia article on disjointiset data structures.
    Author:
    mdavis
    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
      class  DisjointSets.Subsets
      Provides accessors for items in disjoint subsets.
    • Constructor Summary

      Constructors 
      Constructor Description
      DisjointSets​(int size)
      Creates a new structure containing a given number of items.
    • Constructor Detail

      • DisjointSets

        public DisjointSets​(int size)
        Creates a new structure containing a given number of items.
        Parameters:
        size - the number of items contained in the set
    • Method Detail

      • isSameSubset

        public boolean isSameSubset​(int i,
                                    int j)
      • merge

        public void merge​(int i,
                          int j)