Enum Class DisjointSet.UnionAlgorithm

java.lang.Object
java.lang.Enum<DisjointSet.UnionAlgorithm>
io.openml.gearbox.disjointset.DisjointSet.UnionAlgorithm
All Implemented Interfaces:
Serializable, Comparable<DisjointSet.UnionAlgorithm>, Constable
Enclosing class:
DisjointSet<E>

public static enum DisjointSet.UnionAlgorithm extends Enum<DisjointSet.UnionAlgorithm>
The algorithm used to merge two sets.
  • Enum Constant Details

    • UNION_BY_SIZE

      public static final DisjointSet.UnionAlgorithm UNION_BY_SIZE
      Union by size.

      Two sets are merged based on the number of descendants (including the node itself). The set root with more descendants becomes the parent. If the two nodes have the same number of descendants, then the root of the first argument of DisjointSet.union(Object, Object) becomes the new parent. In both cases, the size of the new parent node is set to its new total number of descendants.

      Union by size helps to keep the trees relatively balanced and prevents the formation of very tall, unbalanced trees.

    • UNION_BY_RANK

      public static final DisjointSet.UnionAlgorithm UNION_BY_RANK
      Union by rank.

      Two sets are merged based on the rank, which is a zero-based upper bound for its height, of their respective roots. The set root with larger rank becomes the parent while the ranks for both do not change. If the ranks are the same, then the root of the first argument of DisjointSet.union(Object, Object) becomes the new parent and the rank of the first root is increased by 1.

      Note that the "rank" is not the same as (node) height. Ranks does not accurately reflect the height. For this reason, rank is never updated after path-compression.

      Union by rank helps maintain flat trees, which improves the efficiency of Find operations.

  • Method Details

    • values

      public static DisjointSet.UnionAlgorithm[] values()
      Returns an array containing the constants of this enum class, in the order they are declared.
      Returns:
      an array containing the constants of this enum class, in the order they are declared
    • valueOf

      public static DisjointSet.UnionAlgorithm valueOf(String name)
      Returns the enum constant of this class with the specified name. The string must match exactly an identifier used to declare an enum constant in this class. (Extraneous whitespace characters are not permitted.)
      Parameters:
      name - the name of the enum constant to be returned.
      Returns:
      the enum constant with the specified name
      Throws:
      IllegalArgumentException - if this enum class has no constant with the specified name
      NullPointerException - if the argument is null