Note

This is the documentation for the current state of the development branch of rustworkx. The documentation or APIs here can change prior to being released.

rustworkx.is_connected#

is_connected(graph, /)#

Check if an undirected graph is fully connected

An undirected graph is considered connected if there is a path between every pair of vertices.

>>> G = rx.PyGraph()
>>> G.extend_from_edge_list([(0, 1), (1, 2), (3, 4)])
>>> rx.is_connected(G)
False

If rx.is_connected(G) is True then rx.number_connected_components(G) == 1`.

For directed graphs see [is_weakly_connected], [is_semi_connected], and [is_strongly_connected].

Parameters:

graph (PyGraph) – An undirected graph to check for connectivity

Returns:

Whether the graph is connected or not

Return type:

bool

Raises:

NullGraph – If an empty graph is passed in