undirected graph and a number m, determine if the graph can be colored with at most m colors such that no two adjacent vertices of the graph are colored with the same color.
1. M-COLORING PROBLEM ON A GRAPH
Mrs.G.Chandraprabha., M.Sc.,M.Phil.,
Assistant Professor,
Department of Information Technology,
V.V.V.anniaperumal College for Women,
Virudhunagar.
2. OBJECTIVES
M-COLORING GRAPH:
Given an undirected graph and a number m, determine if the
graph can be colored with at most m colors such that no two adjacent
vertices of the graph are colored with the same color.
Starting from vertex 0, we will try to assign colors one by one
to different nodes. But before assigning, we have to check whether the
color is safe or not. A color is not safe whether adjacent vertices are
containing the same color.
Note: Here coloring of a graph means the assignment of
colors to all vertices
Following is an example of a graph that can be colored
with 3 different colors:
3.
4. PROBLEM:-
PROBLEM: Determine all ways in which the vertices in all
undirected graph can be colored, using only m colors, so that adjacent
vertices are not the same color.
Input: The adjacency matrix of a graph
G(V, E) and an integer m, which indicates the maximum number of colors
that can be used.
5. Let the maximum color m = 3.
OUTPUT: This algorithm will return which node will
be assigned with which color. If the solution is not possible,
it will return false.
For this input the assigned colors are:
Node 0 -> color 1
Node 1 -> color 2
Node 2 -> color 3
Node 3 -> color 2
6. EXAMPLE:-
INPUT: graph = {0, 1, 1, 1},
{1, 0, 1, 0},
{1, 1, 0, 1},
{1, 0, 1, 0}
OUTPUT: Solution Exists: Following are the assigned
colors: 1 2 3 2
EXPLANATION: By coloring the vertices with
following colors, adjacent vertices does not have same
colors.
INPUT: graph = {1, 1, 1, 1},
{1, 1, 1, 1},
{1, 1, 1, 1},
{1, 1, 1, 1}
OUTPUT:
Solution does not exist
7. EXPLANATION:
No solution exits .
NAIVE APPROACH: To solve the problem follow the below idea:
Generate all possible configurations of colors. Since each node can be
colored using any of the m available colors, the total number of color
configurations possible is mV. After generating a configuration of color, check
if the adjacent vertices have the same color or not. If the conditions are met,
print the combination and break the loop.
Follow the given steps to solve the problem:
Create a recursive function that takes the 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).
8. every assigned color recursively call the
function with next index and number of
verticersive function returns true break the loop
and returns true.
ALGORITHMS:-
Void m_coloring(index i)
{
int color;
if(promising(i))
if(i==n)
cout<<vcolor[1] through vcolor[n];
else
for (color=1; color<=m; color++){
vcolor[i+1] = color;
m_coloring(i+1);
9. bool promising (index i)
{
index I;
boot switch;
switch= True;
j=1;
while (j< I && switch)
if (W[i] [j] && vcolor [i] = = vcolor[j])
switch =false;
j++;
}
return switch;
}