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

Sign in. Loading… Whoops! There was a problem loading more pages. Retrying... Whoops! There was a problem previewing this document. Retrying.

344KB Sizes 4 Downloads 100 Views

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
... loading more pages. Retrying... graph-contraction.pdf. graph-contraction.pdf. Open. Extract. Open with. Sign In. Main menu. Displaying 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
DOWNLOAD in @PDF Algorithms in C++ Part 5: Graph Algorithms: Graph Algorithms Pt.5 By #A#. Download EBOOK EPUB KINDLE. Book detail.

Graph Theory.PDF
(c) Find the chromatic number of the Graph 4. given below. If the chromatic number is k, ... MMTE-001 3. Page 3 of 5. Main menu. Displaying Graph Theory.PDF.

graph-search.pdf
There was a problem previewing this document. Retrying... Download. Connect more apps... Try one of the apps below to open or edit this item. graph-search.

Polar Graph Paper.pdf
Retrying... Download. Connect more apps... Try one of the apps below to open or edit this item. Polar Graph Paper.pdf. Polar Graph Paper.pdf. Open. Extract.

Unbalanced Graph Cuts
tention recently, in the context of analyzing social networks and the World ..... [10]. We consider the converse of the densest k-subgraph problem, in which the.