UndiGraph.connectedComponents

UndiGraph.connectedComponents()

Returns the connected components of the graph.

Each node is mapped to the index of its component: 0, 1, …, (number of components - 1), numbered in the order in which the components are found.

Returns:

mapping node id → index of its component

Return type:

dict[int, int]

See also

connectedComponentsList

returns a dict[int, set[int]] grouping nodes by component

connectedComponentsCount

returns the number of components

Example

import pyagrum as gum

g = gum.fastUndiGraph("A-B-C;D-E")
cc = g.connectedComponents()  # node id -> index of its component
cc[0] == cc[1] == cc[2], cc[3] == cc[4], cc[0] == cc[3]
# (True, True, False)

Used by

UndiGraph, CliqueGraph

Inheritance diagram of pyagrum.UndiGraph, pyagrum.CliqueGraph

Overridden in

MixedGraph.connectedComponents