Skip to content
ForCADDocumentation

disjoint_set_union Subroutine

public pure subroutine disjoint_set_union(parent, a, b)

Merge two disjoint-set components using path halving.

Roots are linked deterministically by their integer identifier. This is the union-find structure analyzed by Tarjan (1975), without a separate rank array.

Arguments

Type IntentOptional Attributes Name
integer, intent(inout), contiguous :: parent(:)

Parent forest initialized with parent(i)=i.

integer, intent(in) :: a

One-based member of the first component.

integer, intent(in) :: b

One-based member of the second component.