data-structures

DisjointSet

Class

Members

forest

Set<Tree>

map

Map<string, Tree>

Initializes x as a lone node.

@complexityΘ(1) in the worst case
@paramxstring
@returnsvoid
@paramxstring | Tree
@returnsTree

union

Tree
  • Climbs to the roots of the trees containing x and y
  • and merges parents sets rep[y] , rep[x].
@complexityΘ(height)
@paramxstring | Tree
@paramystring | Tree
@returnsTree

merge

Tree

Merging the tree with the smaller height into the tree with the bigger height

  • the height of a tree remains O(lg n).
@paramxTree
@paramyTree
@returnsTree