public static < T > Set < Set < Node < T > > > compute ( final Graph < T > graph ) { final Set < Set < Node < T > > > connectedComponents = new LinkedHashSet <> ( ) ; final Set < Node < T > > unmarkedNodes = new LinkedHashSet <> ( graph . nodes ( ) ) ; while ( ! unmarkedNodes . isEmpty ( ) ) { Set < Node < T >> connectedComp = new LinkedHashSet <> ( ) ; deepFirstSearch ( unmarkedNodes . iterator ( ) . next ( ) , connectedComp , unmarkedNodes ) ; connectedComponents . add ( connectedComp ) ; } return connectedComponents ; }
Computes the set of connected components of a graph where each component is represented by a set of nodes .