Unit2 L14 UE22CS343AB3 GraphColoring
Unit2 L14 UE22CS343AB3 GraphColoring
Acknowledgements:
These slides are modified versions of slides prepared by Dr. Surabhi Narayan for “Graph
Theory and Combinatorics”
Graph Theory and its Applications
S Upadhyaya
Department of Computer Science & Engineering
Graph Theory and its Applications
Graph Coloring
Graph Coloring
Definition: A graph has been Properly colored if a color has been assigned to each
vertex in such a way that adjacent vertices have different colors.
Definition: The chromatic number of a graph is the smallest number of colors with
which it can be colored.
https://mathworld.wolfram.com/ChromaticNumber.html
Graph Theory and its Applications
Graph Coloring
Graph Theory and its Applications
Graph Coloring
Graph Theory and its Applications
Graph Coloring
Graph Theory and its Applications
Graph Coloring
•Assignment - Assign tasks or projects to individuals ensuring no two tasks assigned to the same
person overlap.
•Map coloring - Color regions of a map so no adjacent regions share the same color, to ensure
clear and distinct visualization.
• Register Allocation: In compiler optimization, register allocation is the process of assigning a large
number of target program variables onto a small number of CPU registers. This problem is also a
graph coloring problem.
• Bipartite Graphs: We can check if a graph is Bipartite or not by coloring the graph using two colors.
If a given graph is 2-colorable, then it is Bipartite, otherwise not.
• Another one: CCTV camera placement in a building with many corners in order to
Graph Theory and its Applications
Graph Coloring
• Prepare timetable - Assign times to classes or exams so no student has overlapping classes or
exams.
• Register Allocation: In compiler optimization, register allocation is the process of assigning a large
number of target program variables onto a small number of CPU registers. This problem is also a
graph coloring problem.
• Bipartite Graphs: We can check if a graph is Bipartite or not by coloring the graph using two colors.
If a given graph is 2-colorable, then it is Bipartite, otherwise not.
• Another one: CCTV camera placement in a building with many corners in order to
Graph Theory and its Applications
Graph Coloring
The committees must all meet during the first week of classes, but there are only three
time slots available. Find a schedule that will allow all faculty members to attend the
meetings of all committees on which they serve.
Graph Theory and its Applications
Graph Coloring
An application of graph coloring in scheduling
▪ U- Undergraduate education: Sineman, Limitson, Axiomus, Functionini
▪ G- Graduate Education: Graphian, Vectorades, Functionini, Infinitescu
▪ C- Colloquium: Lemmeau, Randomov, Proofizaki
▪ L- Library: Van Sum, Sineman, Lemmeau U G C L S P
▪ S-Staffing: Graphian, Randomov, Vectorades, Limitson
U x x *
▪ P-Promotion: Vectorades,Van Sum, Parabolton
G * *
P U C * *
L *
S *
P
L G
C S
Graph Theory and its Applications
Graph Coloring
U x x x x
G x x x x
C x x x
L G X X X
S
L x x x x
P x x x
C S
Graph Coloring
An application of graph coloring in exam scheduling
This solution ensures no student has a
conflict. However, the question
specifies that only two air-conditioned
lecture halls are available. Therefore,
each time slot must be limited to only
two classes.
An application of graph coloring in exam scheduling
Graph Coloring
Graph Coloring
MATH
Graph Coloring
time
122
145
Flight Gates
Flights 67
257
306
99
Graph Theory and its Applications
Graph Coloring
assign
gates:
67
306
257, 67
122,145
4 colors 99
99
6 gates 306
Graph Theory and its Applications
Graph Coloring
Better Coloring
257 122
145
67
306
3 colors
99
3 gates
Graph Theory and its Applications
Planar Graphs
c(G’5) = 4
Graph Theory and its Applications
Planar Graphs
Graph Theory and its Applications
Planar Graphs
If v has ≤ 3 neighbors, there's always a free color for v.
If v has 4 neighbors, there might not be a free color immediately available.
If v has 5 neighbors, there definitely isn't a free color immediately available.
Graph Theory and its Applications
Graph Coloring
Map Coloring
Color the map using minimum number of colors so that two states/countries sharing a
border are assigned different colors.
Graph Theory and its Applications
Graph Coloring
Planar Graphs
Graph Coloring
Map Coloring
Can we draw a map so that there are 5 countries NO
such that any two of which are adjacent?
Graph Coloring
Planar Graphs
Graph Coloring
Graph Coloring
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
Graph Theory and its Applications
Graph Coloring
Edge Coloring
• Similar to vertex coloring, except edges are color.
• Adjacent edges have different colors.
Graph Theory and its Applications
Graph Coloring
Edge Coloring
Graph Theory and its Applications
Graph Coloring
Edge Coloring
Graph Coloring
K-colorable
• A graph G is k-colorable if it has a k-coloring.
Chromatic Number
• The smallest integer k for which G is k-colorable is called the
chromatic number of G, is denoted by the χ(G).
• Chromatic Index is the number of colors required for proper edge coloring
denoted by χ’(G).
Graph Theory and its Applications
Graph Coloring
Graph Coloring
Graph Coloring
Graph Coloring
Graph Theory and its Applications
Graph Coloring
Graph Coloring
Graph Coloring
Observations
Graph Coloring
Graph Coloring
Graph Coloring
Complete Graphs
Graph Coloring
Bipartite Graphs
Graph Coloring
Trees
Graph Coloring
Proof:
Graph Coloring
Proof: A circuit (or cycle) in a graph is a path that starts and ends at the same vertex without retracing
any edge.
The length of a circuit is the number of edges in the circuit.
An odd-length circuit is a circuit where the number of edges is odd.
The graph G, has a circuit {A, F, E, A}, with a path length of 3,
a Circuit {A, E, D, C, B} with a path length of 5,
And circuit { A, F, E, D, C, B, A} with a path length of 6,
Graph Coloring
• There exists no efficient algorithm for coloring a graph with minimum number of
colors.
• Graph Coloring is a NP complete problem.
However, a following greedy algorithm is known for finding the chromatic number of any
given graph.
Graph Theory and its Applications
Graph Coloring
Greedy Algorithm
• Color the currently picked vertex with the lowest numbered color if it has not
been used to color any of its adjacent vertices.
• If it has been used, then choose the next least numbered color.
• If all the previously used colors have been used, then assign a new color to
the currently picked vertex.
Graph Theory and its Applications
Graph Coloring
Verte
a b c d e f
x
Color C1 C2 C1 C2 C1 C2
Graph Theory and its Applications
Graph Coloring
Vertex a b c d e f
Color C1 C2 C2 C3 C3 C1
Graph Theory and its Applications
Graph Coloring
Verte
a b c d e f g
x
Color C1 C2 C1 C3 C2 C3 C4
Graph Theory and its Applications
Graph Coloring
Graph Theory and its Applications
Graph Coloring
Greedy Algorithm
Graph Theory and its Applications
Graph Coloring
Greedy Algorithm
Graph Theory and its Applications
Graph Coloring
Greedy Algorithm
Graph Theory and its Applications
Graph Coloring
Graph Coloring
Drawbacks of Greedy Algorithm
Graph Coloring
Drawback of Greedy Algorithm
Different Order of
picking the vertices
E -> Color 1
A -> Color 1 D -> Color 2
C -> Color 1
B -> Color 2 B -> Color 3
C -> Color 1 A -> Color 1
D -> Color 3
E -> Color 4
Graph Theory and its Applications
Graph Coloring
Graph Coloring
Vertex Degree
A 2
B 2
C 1
D 4
E 2
F 2
G 3
First, order the list in descending order of degrees. H 5
Incase of tie, we can randomly choose any ways to I 3
break it. J 3
So, the new order will be : H, K, D, G, I, J, A, B, E, F, C K 5
Graph Theory and its Applications
Graph Coloring
H, K, D, G, I, J, A, B, E, F, C
Graph Theory and its Applications
Graph Coloring D 7
A 6
Apply Welsh Powell Algorithm to color the graph I 5
A C 4
B E 4
G
H F H 4
K 4
D E F 3
C
G 3
J K
J 3
I B 2
Graph Theory and its Applications
Graph Coloring D 7
A 6
Apply Welsh Powell Algorithm to color the graph I 5
A C 4
B E 4
G
H F H 4
4 CHROMATIC K 4
D E
C F 3
J K G 3
J 3
I
B 2
Graph Theory and its Applications
Graph Coloring
Graph Coloring
V 2
1 3
4
Graph Theory and its Applications
Graph Coloring
4
4 4
4 4
4 4
4 4
4 4
Graph Theory and its Applications
Graph Coloring
4 4
4 4
4 4
Graph Theory and its Applications
Graph Coloring
4 6 4
6 3
Graph Theory and its Applications
Graph Coloring
THANK YOU
S Upadhyaya
Department of Computer Science & Engineering
sujathar@pes.edu