Enum Class DisjointSet.UnionAlgorithm
- All Implemented Interfaces:
Serializable
,Comparable<DisjointSet.UnionAlgorithm>
,Constable
- Enclosing class:
- DisjointSet<E>
-
Nested Class Summary
Nested classes/interfaces inherited from class java.lang.Enum
Enum.EnumDesc<E extends Enum<E>>
-
Enum Constant Summary
Enum Constants -
Method Summary
Modifier and TypeMethodDescriptionstatic DisjointSet.UnionAlgorithm
Returns the enum constant of this class with the specified name.static DisjointSet.UnionAlgorithm[]
values()
Returns an array containing the constants of this enum class, in the order they are declared.
-
Enum Constant Details
-
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 ofDisjointSet.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
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 ofDisjointSet.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
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
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 nameNullPointerException
- if the argument is null
-