Question

A 2-coloring of an undirected graph with n vertices and m edges is the assignment of one of two colors (say, red or green) to each vertex of the graph


A 2-coloring of an undirected graph with n vertices and m edges is the assignment of one of two colors (say, red or green) to each vertex of the graph, so that no two adjacent nodes have the same color. So, if there is an edge (u,v) in the graph, either node u is red and v is green or vice versa. Give an O(n + m) time algorithm (pseudocode!) to 2-colour a graph or determine that no such coloring exists. (Hint: Use BFS)

 The following shows examples of graphs that are and are not 2-colourable: 

image.png

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Algorithm to find out whether a given graph is Birpartite or not (2-colorable or not )using Breadth First Search (BFS).
step 1. Assign RED color to the source vertex (putting into set U).
step 2. Color all the neighbors with GREEN color (putting into set V).
step 3. Color all neighbor's neighbor with RED color (putting into set U).
step 4. This way, assign color to all vertices such that it satisfies all the constraints of m way coloring problem where m = 2.
step 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)

As,we are using BFS, Time complexity is O(m+n) where m is number of vertices and n is number of edges.

Add a comment
Know the answer?
Add Answer to:
A 2-coloring of an undirected graph with n vertices and m edges is the assignment of one of two colors (say, red or green) to each vertex of the graph
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT