Graph coloring using backtracking

14,117 views 11 slides May 22, 2021
Slide 1
Slide 1 of 11
Slide 1
1
Slide 2
2
Slide 3
3
Slide 4
4
Slide 5
5
Slide 6
6
Slide 7
7
Slide 8
8
Slide 9
9
Slide 10
10
Slide 11
11

About This Presentation

presentation of Graph coloring Technique using backtracking


Slide Content

GRAPH COLORING USING BACKTRACKING BY: P. Shashidhar 18E11A05B7

What is graph coloring?

T he objective is to minimize the number of colors while coloring a graph.  The smallest number of colors required to color a graph G is called its chromatic number of that graph. Graph coloring problem is a NP Complete problem . No efficient algorithm is available to implement graph coloring mainly we use Greedy and Backtracking algorithm.

Method to Color a Graph Arrange the vertices of graph in the same order. Choose the first vertex and color it with the first color. Then choose next vertex and color it with the lowest numbered color that has not been colored on any vertices which is adjacent to it. If all the adjacent vertices are colored with the color, assign the new color to it. Repeat the same process until all the vertices are colored. If any complication occurs backtrack before step and repeat the process.

Algorithm:  Create a recursive function that takes current index, number of vertices and output color array. If the current index is equal to number of vertices. Check if the output color configuration is safe, i.e check if the adjacent vertices do not have same color. If the conditions are met, print the configuration and break. Assign a color to a vertex (1 to m). For every assigned color recursively call the function with next index and number of vertices If any recursive function returns true break the loop and returns true.

GraphColor (int k){ for(int c=1;c<= m;c ++); if( isSafe ( k,c )){ X[k]=c; if((k+1)<n) GraphColor (k+1); else print x[];return; } } isSafe (int k,int c){ for(int i =0;i< n;i ++){ if(G[k][ i ]=2 && c==x[ i ]){ return false; } } return true; }

Applications: Making schedule or Time table. Sudoku. Register allocation. Map coloring. Job allocation in CPU.

THANK YOU