isBipartite<V> function
bool
isBipartite<V>({
- required Iterable<
V> vertices, - Iterable<
V> neighboursOf(- V vertex
- Iterable<
V> successorsOf(- V vertex
- StorageStrategy<
V> ? vertexStrategy,
Checks if a graph is bipartite.
A graph is bipartite if the vertices can be divided into two disjoint and independent sets, U and V, such that every edge connects a vertex in U to one in V. This is equivalent to checking if the graph is 2-colorable or has no odd-length cycles.
The algorithm traverses the graph using a breadth-first search approach. It handles disconnected graphs by iterating through all vertices.
Implementation
bool isBipartite<V>({
required Iterable<V> vertices,
Iterable<V> Function(V vertex)? neighboursOf,
Iterable<V> Function(V vertex)? successorsOf,
StorageStrategy<V>? vertexStrategy,
}) =>
bipartiteColoring<V>(
vertices: vertices,
neighboursOf: neighboursOf,
successorsOf: successorsOf,
vertexStrategy: vertexStrategy,
) !=
null;