Skip to main content

is_bipartite

Function is_bipartite 

Source
pub fn is_bipartite(graph: &Graph) -> bool
Expand description

Returns whether graph is bipartite: its nodes split into two sets such that every edge runs from one set to the other.

Reads the graph as undirected, so the direction of the edges does not matter. A self-loop makes the graph not bipartite, unlike the other checks of the undirected reading, which ignore self-loops. The empty graph is bipartite.

Time: O(node_count + edge_count x alpha(node_count)), stopping at the first cycle of odd length. Memory: 10 x node_count bytes while it runs.

ยงPanics

With an invalid argument message if graph has more than 2^30 - 5 nodes.