1

Graph Coloring (Backtracking Approach) Algorithm:

2

Program: #include #include int color[50],G[50][50],edges,m; int getdata(); void colorvalue(int,int); void graphcoloring(int,int); void main() { int i,j,n; clrscr(); for(i=0;i<50;i++) for(j=0;j<50;j++) { G[i][j]=0; color[i]=0; } n=getdata(); graphcoloring(1,n); printf("\nThe vertices to be colored as:"); for(i=1;i<=n;i++) { printf("\n\tv%d-->",i); switch(color[i]) { case 1: printf("RED"); break; case 2: printf("BLUE");

3 break; case 3: printf("GREEN"); break; case 4: printf("YELLOW"); break; case 5: printf("ORANGE"); break; case 6: printf("PURPLE"); break; case 7: printf("PINK"); break; case 8: printf("BROWN"); break; case 9: printf("VIOLET"); break; case 10: printf("CYAN"); break; } } getch(); } void colorvalue(int k,int n)

4 { int a,b,j; while(1) { a=color[k]+1; b=m+1; color[k]=a%b; if(color[k]==0) return; for(j=1;j<=n;j++) if(G[k][j]&&color[k]==color[j]) break; if(j==n+1) return; } } void graphcoloring(int k,int n) { colorvalue(k,n); if(color[k]==0) return; if(k==n) return; else graphcoloring(k+1,n); } int getdata() { int v1,v2,i,n; printf("\nEnter the no. of nodes:");

5 scanf("%d",&n); printf("\nEnter the no. of edges:"); scanf("%d",&edges); m=n-1; printf("\nEnter the edges of the graph:"); for(i=1;i<=edges;i++) { scanf("%d%d",&v1,&v2); G[v1][v2]=G[v2][v1]=1; } return n; }

## Graph Coloring.pdf

#### Recommend Documents

Robust Graph Mode Seeking by Graph Shift
ample, in World Wide Web, dense subgraphs might be communities or link spam; in telephone call graph, dense subgraphs might be groups of friends or families. In these situations, the graphs are usually very sparse in global, but have many dense subgr

graph-contraction.pdf

Graph Theory Notes - CiteSeerX
To prove the minimality of the set MFIS(X), we will show that for any set N ..... Prove that for a non-empty regular bipartite graph the number of vertices in both.

Knowledge Graph Identification
The web is a vast repository of knowledge, but automatically extracting that ... Early work on the problem of jointly identifying a best latent KB from a collec- ... limitations, and we build on and improve the model of Jiang et al. by including ....

Graph Algorithms