0% found this document useful (0 votes)
26 views78 pages

Unit2 L14 UE22CS343AB3 GraphColoring

Uploaded by

shreyanav10
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
26 views78 pages

Unit2 L14 UE22CS343AB3 GraphColoring

Uploaded by

shreyanav10
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 78

Graph Theory and its Applications

Graph Theory and its Applications


S Upadhyaya
Department of Computer Science & Engineering

Acknowledgements:
These slides are modified versions of slides prepared by Dr. Surabhi Narayan for “Graph
Theory and Combinatorics”
Graph Theory and its Applications

Graph Theory and its Applications


Graph Coloring

S Upadhyaya
Department of Computer Science & Engineering
Graph Theory and its Applications

Graph Coloring

Graph Coloring Problem


Given a graph, color all the vertices so that two
adjacent vertices get different colors.

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.
Graph Theory and its Applications

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.

In the example above, the chromatic number is 4.


Graph Theory and its Applications
Graph Coloring

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

What is the Chromatic Number of the following


graph ?
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
Applications of 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.

•Scheduling the tasks - Allocate tasks to processors ensuring no two tasks


using the same resource run simultaneously.

•Sudoku - Ensure no repeating numbers in rows, columns, or subgrids by


Treating each cell as a vertex in a graph. Sudoku is also a variation of
Graph coloring problem where every cell represents a vertex. There is
an edge between two vertices if they are in same row or same column
or same block. In the example above, the chromatic number is
3.
Graph Theory and its Applications
Graph Coloring
• Prepare timetable - Assign times to classes or exams so no student has overlapping classes or
exams.

• Conflict resolution - Allocate different resources to competing entities to avoid conflicts.

• Mobile Radio Frequency Assignment: When frequencies are assigned to towers,


frequencies assigned to all towers at the same location must be different.

• 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.

• Conflict resolution - Allocate different resources to competing entities to avoid conflicts.

• Mobile Radio Frequency Assignment: When frequencies are assigned to towers,


frequencies assigned to all towers at the same location must be different.

• 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

An application of graph coloring in scheduling


Twelve faculty members in a mathematics department serve on the following committees:
▪ Undergraduate education: Sineman, Limitson, Axiomus, Functionini
▪ Graduate Education: Graphian, Vectorades, Functionini, Infinitescu
▪ Colloquium: Lemmeau, Randomov, Proofizaki
▪ Library: Van Sum, Sineman, Lemmeau
▪ Staffing: Graphian, Randomov, Vectorades, Limitson
▪ Promotion: Vectorades, Van Sum, Parabolton

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

An application of graph coloring in scheduling

P U Limitso Axiomu Functioni Randomo


Sineman n s ni Graphian Vectorades Infinitescu Lemmeau v Proofizaki Van Sum, Lemmeau Parabolto

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

This is a valid solution


Graph Theory and its Applications

Graph Coloring

An application of graph coloring in exam scheduling


Suppose that in a particular quarter there are students taking each of the following
combinations of courses: UU
▪ Math, English, Biology, Chemistry
▪ Math, English, Computer Science, Geography
▪ Biology, Psychology, Geography, Spanish
▪ Biology, Computer Science, History, French
▪ English, Psychology, Computer Science, History
▪ Psychology, Chemistry, Computer Science, French
▪ Psychology, Geography, History, Spanish
What is the minimum number of examination periods required for the exams in the ten
courses specified so that students taking any of the given combinations of courses have
no conflicts? Find a schedule that uses this minimum number of periods.
Graph Theory and its Applications

Graph Coloring
MATH

BIOLOGY What is the easier way of solving this problem?


ENGLISH CHEMISTRY
Consider subjects that never appear in the same
combination as one node
COMPUTER GEOGRAPHY ▪ Math, English, Biology, Chemistry
SCIENCE ▪ Math, English, Computer Science, Geography
▪ Biology, Psychology, Geography, Spanish
SPANISH ▪ Biology, Computer Science, History, French
PSYCHOLOGY ▪ English, Psychology, Computer Science, History
FRENCH ▪ Psychology, Chemistry, Computer Science, French
HISTORY
▪ Psychology, Geography, History, Spanish
Graph Theory and its Applications

Graph Coloring

flights need gates, but times


overlap.

how many gates needed?

time

122

145
Flight Gates
Flights 67

257

306

99
Graph Theory and its Applications

Graph Coloring

Coloring the Vertices


257 122
145

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

- Each vertex is a region.


- Two regions have an edge
if they are adjacent.

This is a planar graph.

A graph is planar if there is a way to draw it in the


plane without edges crossing.
Graph Theory and its Applications

Graph Coloring

Map Coloring
Can we draw a map so that there are 5 countries NO
such that any two of which are adjacent?

Can we draw a map which need 5 colours? NO

What are we trying to do here?


Trying to draw K5 as a planar graph

Conjecture (1852) Every map is 4-colourable.


Graph Theory and its Applications

Graph Coloring

Planar Graphs

Can we draw a map so that there are 5 countries


such that any two of which are adjacent? NO
Graph Theory and its Applications

Graph Coloring

Applications of Graph Coloring

• Making Schedule or Time Table


• Mobile Radio Frequency Assignment: When frequencies are assigned to towers,
frequencies assigned to all towers at the same location must be different
• Sudoku: Sudoku is also a variation of Graph coloring problem where every cell
represents a vertex. There is an edge between two vertices if they are in same row or
same column or same block.
• 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.
• Map Coloring
Graph Theory and its Applications

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

• Every edge-coloring problem can be transformed into a vertex-coloring problem


• Coloring the edges of graph G is the same as coloring the vertices in L(G)
• Not every vertex-coloring problem can be transformed to an edge-coloring problem
Graph Theory and its Applications

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

Independent set (of vertices)


A set of vertices I is called independent set if no two vertices in set I are
adjacent to each other

A matching or independent edge set

In an undirected graph, a set of edges without common vertices


Graph Theory and its Applications

Graph Coloring

Vertex coloring problem


Graph Theory and its Applications

Graph Coloring

Edge coloring problem


Graph Theory and its Applications

Graph Coloring
Graph Theory and its Applications

Graph Coloring

Find the chromatic number of the following graphs

Bipartite graph - K3,3 Chromatic no is 2


Graph Theory and its Applications

Graph Coloring

Find the chromatic number of the following graphs


Graph Theory and its Applications

Graph Coloring

Observations

• A graph consisting of only isolated vertices is 1- chromatic.


• A graph with one or more edges is atleast 2-chromatic.
• If G is a graph of n vertices then χ(G) <= n
• χ(Kn) = n for all n>=1
• If a graph G contains a graph G1 as subgraph, then χ(G) >= χ(G1)
• If a graph G contains Kn as a subgraph, then χ(G)>= n
Graph Theory and its Applications

Graph Coloring

Chromatic Number of some common types of graphs


Cycle Graph

• A simple graph of ‘n’ vertices (n>=3) and ‘n’


edges forming a cycle of length ‘n’ is called as
a cycle graph.
• In a cycle graph, all the vertices are of
degree 2.
• If number of vertices in cycle graph is even,
then its chromatic number = 2.
• If number of vertices in cycle graph is odd,
then its chromatic number = 3.
Graph Theory and its Applications

Graph Coloring

Prove that a graph of order n>=2 consisting of a single cycle is 2-


chromatic if n is even and 3-chromatic if n is odd. v1
Vn v2
Proof: This cycle cannot be 1-chromatic
Assign 2 colors alternatively to the vertices.
Odd numbered vertices: color1
Even numbered vertices: color2. v3
n is even : properly colored
n is odd: Vn should be colored with color3
Graph Theory and its Applications

Graph Coloring

Chromatic Number of some common types of graphs

Complete Graphs

• A complete graph is a graph in which every


two distinct vertices are joined by exactly one
edge.
• In a complete graph, each vertex is
connected with every other vertex.
• So to properly it, as many different colors
are needed as there are number of vertices in
the given graph.
Graph Theory and its Applications

Graph Coloring

Chromatic Number of some common types of graphs

Bipartite Graphs

• A Bipartite Graph consists of two sets of


vertices X and Y.
• The edges only join vertices in X to vertices
in Y, not vertices within a set.
• Chromatic Number of any Bipartite Graph =
2
Graph Theory and its Applications

Graph Coloring

Chromatic Number of some common types of graphs

Trees

• A Tree is a special type of connected graph


in which there are no circuits.
• Every tree is a bipartite graph.
• So, chromatic number of a tree with any
number of vertices = 2.
Graph Theory and its Applications

Graph Coloring

Theorem: Every Tree with two or more vertices is 2-


chromatic

Proof:

Select any vertex v to be the root of the tree T.


v: assign color1
Vertices adjacent to v: color2
Vertices adjacent to vertices(color2): color1
Only one path between any two vertices
Graph Theory and its Applications

Graph Coloring

Theorem: A graph with at least one edge is 2-chromatic if and


only if it has no circuits of odd length

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,

As seen in the diagram, the Graph G cannot, be 2-chromatic, this


is due to the presence of circuits of odd length.
Graph Theory and its Applications

Graph Coloring

Graph Coloring Algorithm

• 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 first vertex with the first color.


• Now, consider the remaining (V-1) vertices one by one and do the following-

• 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

Applying Greedy Algorithm, we have-

Verte
a b c d e f
x
Color C1 C2 C1 C2 C1 C2
Graph Theory and its Applications

Graph Coloring

Applying Greedy Algorithm, we have-

Vertex a b c d e f
Color C1 C2 C2 C3 C3 C1
Graph Theory and its Applications

Graph Coloring

Applying Greedy Algorithm, we have-

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

Greedy Algorithm (Another example)


(Try Yourself)
Graph Theory and its Applications
Graph Coloring

Greedy Algorithm(TRY Yourself)


Graph Theory and its Applications

Graph Coloring
Drawbacks of Greedy Algorithm

There are following drawbacks of the above Greedy Algorithm

• The above algorithm does not always use minimum number


of colors.

• The # of colors used depend on the order in which the


vertices are processed.
Graph Theory and its Applications

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

Welsh Powell Graph coloring Algorithm


1. Find the degree of each vertex
2. List the vertices in order of descending degrees.
3. Color the first vertex with color 1.
4. Move down the list and color all the vertices not connected to the colored vertex, with
the same color.
5. Repeat step 4 on all uncolored vertices with a new color, in descending order of degrees
until all the vertices are colored.
Graph Theory and its Applications

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

Apply Welsh Powell Algorithm to color the graph


Graph Theory and its Applications

Graph Coloring

Apply Welsh Powell Algorithm to color the graph

V 2

1 3

4
Graph Theory and its Applications

Graph Coloring

Apply Welsh Powell Algorithm to color the graph


4

4
4 4
4 4

4 4

4 4

4 4
Graph Theory and its Applications

Graph Coloring

Apply Welsh Powell Algorithm to color the graph


4

4 All vertices are of degree 4


4 4
4 4 Virtices are chosen in random order

4 4

4 4

4 4
Graph Theory and its Applications

Graph Coloring

Apply Welsh Powell Algorithm to color the graph

Degree of the vertex shown in blue


4 Start in the order of H, F, A,B,C,D,G, E
4 4

4 6 4

6 3
Graph Theory and its Applications

Graph Coloring

Apply Welsh Powell Algorithm to color the graph

Left for student to work


Graph Theory and its Applications

THANK YOU

S Upadhyaya
Department of Computer Science & Engineering
sujathar@pes.edu

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy