A bipartite graph is one in which the nodes of the graph can be divided into two sets, A and B, such that there are no edges going within nodes in the same sets. In other words, every edge in the graph goes between A and B (note that this does not mean that every node in A is connected to every node in B). Create an efficient algorithm to determine whether a connected graph is a bipartite graph.
Here is an efficient algorithm to check whether a graph is bipartite or not :-(Using Breadth First Search)
1. Assign WHITE color to the source vertex (putting into set
X).
2. Color all the neighbors with BLACK color (putting into set
Y).
3. Color all neighbor’s neighbor with WHITE color (putting into set
X).
4. This way, assign color to all vertices such that it satisfies
all the constraints of m way coloring problem where m = 2.
5. While assigning colors, if we find a neighbor which is colored
with same color as current vertex, then the graph cannot be colored
with 2 vertices (or graph is not Bipartite)
A bipartite graph is one in which the nodes of the graph can be divided into...