Aph Coloring
Aph Coloring
What is Coloring?
• Graph Coloring is an assignment of colors (or any distinct marks) to
the vertices of a graph. Strictly speaking, a coloring is a proper
coloring if no two adjacent vertices have the same color.
f : V (G ) S
Graph Coloring
• Special case of labeling graph elements subject to
certain constraints.
– Traditionally, "colors" are used as labels.
• Several forms
– Vertex coloring. Color vertices of a graph such that
no two adjacent vertices share the same color.
– Edge coloring. Color edges such that no two adjacent
edges share the same color.
– Face coloring of a planar graph. Assign color to each
face or region so that no two faces that share a
boundary have the same color.
Vertex Coloring
• A vertex coloring is an assignment of labels or colors
to each vertex of a graph such that no edge connects
two identically colored vertices
Edge Coloring
• Similar to vertex coloring, except edges are color.
• Adjacent edges have different colors.
Solution TO Problem
• The other graph coloring problems like Edge Coloring (No vertex is
incident to two edges of same color) and Face Coloring (Geographical
Map Coloring) can be transformed into vertex coloring.
Contd…
v1 v2 v3 v4
v5 v6 v7 v8
Example v1 v2 v3 v4
v5 v6 v7 v8
Order of vertices
v1 v2 v3 v4 v5 v6 v7 v8
c1 c1 c2 c1 c2 c2 c3 c4
Number of colors required ≤ Maximum degree + 1
≤ max{deg(v1), deg(v2), deg(v3), deg(v4), deg(v5),
deg(v6), deg(v7), deg(v8)} + 1
≤ max{3, 3, 2, 2, 2, 4, 5, 3} + 1
≤5+1
≤ 6.
Color using greedy algorithm(C1,C2,C3,C4)
Greedy Approach
1. Color first vertex with first color.
2. Do following for remaining V-1 vertices.
a) Consider the currently picked vertex and color it with the
lowest numbered color that has not been used on any previously
colored vertices adjacent to it. If all previously used colors
appear on vertices adjacent to v, assign a new color to it.
Sequential Coloring – Greedy Approach
• sequentialColoringAlgorithm(graph = (V,E))
1. Put vertices in a certain order {v1,v2,…,vn}.
2. Put colors in a certain order {c1,c2,…,ck}.
3. for i = 1 to n
4. j = the smallest index of color that does
not appear in any neighbor of vi.
5. color(vi) = j.
If every node in G has degree ≤ d, then the
algorithm uses at most d + 1 colors for G.
Welsh–Powell algorithm
• If vertices are ordered according to their degrees
(decreasing), then
v1 v2 v3 v4
v5 v6 v7 v8
v7 v6 v1 v2 v8 v3 v4 v5
c1 c2 c3 c1 c3 c2 c3 c2
m-Coloring Problem
• 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 have the same color.
• Input:
– An adjacency matrix, graph[V][V] where V is the
number of vertices in the graph.
– An integer m which is maximum number of colors that
can be used.
• Output:
– An array color[V] containing colors assigned to all the
vertices in the range 1 to m. False will be returned, if
the graph cannot be colored with m colors.
Following is an example of graph that can be colored with 3
different colors
• Naive Algorithm
Generate all possible configurations of
colors and print a configuration that
satisfies the given constraints.
while there are untried configurations
{ generate the next configuration if
no adjacent vertices are colored with
same color
{ print this configuration; } }
7 c2 c1 c2
6 c3 c1 c2 c3 v7 v1 v0 v4
5 c2 c1 c2
0 1 2 3 4 5 6 7
4 c3 c1 c2 c3 0 0 1 1 0 1 1 1 0
3 c1 1 1 0 1 0 1 0 1 0
2 1 1 0 0 0 0 0 1
2 c3 c1 c2 c3 3 0 0 0 0 1 1 0 1
1 c2 c1 c2 4 1 1 0 1 0 0 0 0
5 1 0 0 1 0 0 0 0
0 c1 6 1 1 0 0 0 0 0 0
7 0 0 1 1 0 0 0 0
Applications
• Scheduling.
• Frequency Assignment.
• Register Allocation.
• Bipartite Graphs.
• Map Coloring, etc. v2 v3 v5 v6
v7 v1 v0 v4
• The graph coloring problem has huge number of applications.
• 1) Making Schedule or Time Table: Suppose we want to make am exam schedule for a
university. We have list different subjects and students enrolled in every subject. Many
subjects would have common students (of same batch, some backlog students, etc). How
do we schedule the exam so that no two exams with a common student are scheduled at
same time? How many minimum time slots are needed to schedule all exams? This
problem can be represented as a graph where every vertex is a subject and an edge
between two vertices mean there is a common student. So this is a graph coloring
problem where minimum number of time slots is equal to the chromatic number of the
graph.
• 2) Mobile Radio Frequency Assignment: When frequencies are assigned to towers,
frequencies assigned to all towers at the same location must be different. How to assign
frequencies with this constraint? What is the minimum number of frequencies needed?
This problem is also an instance of graph coloring problem where every tower represents
a vertex and an edge between two towers represents that they are in range of each
other.
• Suppose that you are responsible for scheduling times for lectures in
a university. You want to make sure that any two lectures with a
common student occur at different times to avoid a conflict. We could
put the various lectures on a chart and mark with an “X” any pair that
has students in common:
We can code each time with a color, for example 11:00-12:00 might be given the color green, and those lectures that
meet at this time will be colored green. The no-conflict rule then means that we need to color the vertices of our
graph in such a way that no two adjacent vertices (representing courses which conflict with each other) have the
same color
Example. Minimizing exam period in school. How to
schedule exams in minimum parallel sessions, where no
two concurrent exams have a common student?
Define 𝐺 𝑉, 𝐸 , where 𝑣 ∈ 𝑉 corresponds to course, and
𝑒 𝑢, 𝑣 ∈ 𝐸 iff courses 𝑢 and 𝑣 have a common student.
An independent set of vertices implies a parallel exam
session. χ 𝐺 is the smallest number of parallel sessions.
Example. Chemical storage. Store 𝑛 different chemicals.
The interaction between some pairs is explosive.
What is the smallest required number of compartments
in the storage? χ 𝐺 .