 from Department of Computer Science and Engineering from Volchon Institute of Technology, Solapur. And today we shall see how to solve the graph coloring problem by backtracking approach. Now, we shall see what exactly is the graph coloring problem. How does backtracking approach provide a solution to this problem and how to solve this problem by backtracking approach. So at the end of the session, you will be able to apply backtracking approach to solve the graph coloring problem. Now what exactly is the problem in this problem we are given a connected graph having mn number of nodes and m number of colors. The objective of the problem is to find out whether all the nodes of graph G are colored in such a way that no two adjacent nodes are colored with the same color. That means if I am coloring a particular node vi with a color say for example red then I cannot color any other node which is adjacent to node vi by the same red color. And the second constraint is that all the nodes of the graph are colored with at most m colors. That means I cannot use more than m colors because I only have m colors in my hand. So this is termed as the m colorability decision problem. We find out whether the graph can be colored with m colors or not. So the backtracking approach provides a solution to this particular problem. We generate a state space tree for all the possibilities of the solution and then we limit the growth of the tree by bounding the solution path if the adjacent nodes have similar color. Now consider the graph given below it has five nodes which have been noted as 1, 2, 3, 4 and 5. We have been given three colors that is RGB standing for red, green and blue. And we have to find whether the given graph can be colored in at most three colors or not. We shall apply backtracking approach generate the state space tree for the solution and find out whether this graph can be colored with three colors or not. We shall see how it is done. Now this is the exact graph that we had seen it has five nodes which has been named the nodes have been named from one through five and we shall see how to solve this problem using backtracking. Now initially we start with the initial node and now we want to see whether the first we start coloring the nodes by the given colors. So firstly I color node one with red so I state x1 that is node one colored with red. So now I have three options to color node two. So if I color node two with R that is red this is incorrect because no adjacent nodes can be colored with the same color. So this is not possible. So I have to take the second color that is green. So I can color the second node with green. So first node or the first vertex has been colored with red the second vertex has been colored with green. Now I continue further with coloring the further nodes. Now I have to check whether node three can be colored with red or green or blue. So I start with red. So coloring node three with red is not possible because we have already colored node one with red which is again adjacent to node three. So since node one has been colored with red I cannot color node three with red. Similarly I cannot color it with green because node two is already colored with green which is again adjacent to node three. So node three cannot be colored with green. I have one color left which is blue. So I write as third node is colored with blue. So first node is colored with red second node is colored with green third node is colored with blue. Now I have to check for the fourth node. So I start with the first color that is red. So is it possible? Yes because node three is colored with blue and node five is not yet colored. So it is possible for me to color fourth node with red. Now I have the last node remaining which is node five. So I will start coloring or the solution I will start with red. Is it possible? No because node four is already colored with red. Can I color it with green? Yes it is possible to color node five with green because the two adjacent nodes of node five that is node four and node one are having different colors. And since we know that node one has red color node four has also red color and node five should have some different color than red and since I am coloring it with green. So this is my solution. So the first solution that I have come across is color the first node with red color the second node with green color the third node with blue color the fourth node with red again and color the fifth node with green which gives me the solution. Now I can trace back I can backtrack and find other solutions for this same problem. Now I have colored the fifth node with green. Is there any other solution we shall check. Now if I color the fifth node with red is over it cannot be colored green is what we have done in the previous solution if if I color it with blue I come to know that this is my second solution because both one and four have been colored with red and I can color node five with blue. So this is the other solution that I am I am getting for this particular problem that node one can be colored with red node two can be colored with green node three can be colored with blue node four again can be colored with red and node five can be colored with blue. So these are the two solutions that we are getting at this point in time of course if you generate the entire tree and search for the entire search space you will get all the solutions that is you can you will get all the possible solutions for this particular graph where we can color it with these three colors we shall stop here. So we have seen two solutions where we color the five nodes of this graph by three colors. So at this point in time I want you to pause the video and find whether we can color this graph which is having four nodes with three colors pause the video and find out whether the graph can be colored with these three colors or not. So if you have applied the backtracking approach and you have found out the solution you will find out that yes you can color this graph with three nodes what you have to consider is that you are not coloring any two adjacent vertices with the same color say for example you color the first node with red then you have the option to color the second node with green or blue I will consider it as green then you can color the third node with red again and then you can color the fourth node with blue. So you have the option and you have the options to color it with three nodes and you can come to many possibilities I have already discussed one possibility with you and you can color it with given three colors so this is the reference that I have used for this video lecture. Thank you.