2 Graph Theory Graph Coloring
2 Graph Theory Graph Coloring
Graph coloring
Z.GUELLIL
Graph Coloring
• Graph coloring can be described as the process of assigning labels (or
colors) to the vertices of a graph.
• A proper graph coloring is an assignment of colors to the vertices of a graph
such that no two adjacent vertices have the same color.
• We say that G is k-colorable.
• Formally: For a graph G = (V, E), where V is the set of vertices and E is the
set of edges,
oa proper coloring is a function c: V → S,
owhere S is a set of colors,
osuch that c(u) ≠ c(v) for all edges (u, v) ∈ E.
Chromatic number
• The chromatic number of a graph G is the smallest number of colors
needed to achieve a proper coloring of the graph.
3-colourable
-1-
Chromatic number
• The chromatic number of a graph G is the smallest number of colors
needed to achieve a proper coloring of the graph.
Trees
-1- -2-
Chromatic number
• The chromatic number of a graph G is the smallest number of colors
needed to achieve a proper coloring of the graph.
Trees
-1- -2-
-3-
Chromatic number
• The chromatic number of a graph G is the smallest number of colors
needed to achieve a proper coloring of the graph.
Trees
-1- -2-
-3-
(Kn ) = n -4-
Greedy Coloring
• Colors each vertex in a sequential order, assigning the smallest possible color
that hasn't been used by its adjacent vertices.
• Positive aspects :
oSimple and easy to implement.
oRuns in linear time with respect to the number of vertices and edges.
• Negative aspects :
oDepends heavily on the vertex ordering. It can use more colors than
necessary if the vertices are not ordered optimally.
oMay produce suboptimal colorings (i.e., use more than the chromatic
number).
Welsh and Powell algorithm 1/2
• A variation of the greedy algorithm that sorts vertices by degree (number of
neighbors) before coloring.
• Algorithm:
1.Sort vertices in descending order of degree.
2.Assign the first color to the first vertex in the ordered list and to every
vertex not adjacent to it.
3.Repeat step 2 with a new color for the uncolored vertices until all
vertices are colored.
Welsh and Powell algorithm 2/2
• Positive aspects :
oGenerally, produces better colorings than the basic greedy algorithm
since higher-degree vertices are colored first.
oSimple to implement and has better performance for dense graphs.
• Negative aspects :
oStill not guaranteed to find the chromatic number.*
oIt is affected by the tie-breaking method when vertices have the same
degree.
Example
• Five students have to take written exams.
➢ Student 1: A, D, C
➢ Student 2: E, B, C
➢ Student 3: C, F, A
➢ Student 4: A, B
➢ Student 5: D, F
• If each writing lasts 1/2 day, what is the minimum number of days that
should be planned?
1/9 Welsh and Powell
D
A C
F B
Summit C A D F B E
Degree 5 4 3 3 3 2
Color
2 Welsh and Powell
D
A C
F B
Summit C A D F B E
Degree 5 4 3 3 3 2
Color Red
3/9 Welsh and Powell
D
A C
F B
Summit C A D F B E
Degree 5 4 3 3 3 2
Color Red
4/9 Welsh and Powell
D
A C
F B
Summit C A D F B E
Degree 5 4 3 3 3 2
Color Red YEL
5/9 Welsh and Powell
D
A C
F B
Summit C A D F B E
Degree 5 4 3 3 3 2
Color Red YEL YEL
6/9 Welsh and Powell
D
A C
F B
Summit C A D F B E
Degree 5 4 3 3 3 2
Color Red YEL YEL
7/9 Welsh and Powell
D
A C
F B
Summit C A D F B E
Degree 5 4 3 3 3 2
Color Red YEL GR YEL
8/9 Welsh and Powell
D
A C
F B
Summit C A D F B E
Degree 5 4 3 3 3 2
Color Red YEL GR GR YEL
9/9 Welsh and Powell
D
A C
F B
Summit C A D F B E
Degree 5 4 3 3 3 2
Color Red YEL GR BLUE GR YEL
DSatur Algorithm 1/2
• Colors vertices based on saturation degree, prioritizing those with the highest
number of differently colored neighbors.
• Algorithm:
1.Order vertices by degree.
2.Color a vertex of maximal degree with the first color.
3.Choose a vertex with maximal saturation degree. If there's a tie, choose the
vertex with highest degree in the uncolored subgraph.
4.Color the chosen vertex with the lowest possible color number.
5.Repeat steps 3-4 until all vertices are colored.
DSatur Algorithm 2/2
• Positive aspects :
oGenerally produces better colorings than Greedy or Welsh-Powell
oTends to produce colorings closer to the chromatic number, especially for
dense graphs.
oAdapts to the graph structure during the coloring process
• Negative aspects :
oSlightly more complex to implement due to the need to track saturation
degrees and dynamically update them after each coloring step.
oHeuristic algorithms like DSatur are designed to find good solutions
quickly, but they may not always find the best possible solution.
1/8 DSatur Algorithm
D
A C
F B
Summit C A D F B E
Degree 5 4 3 3 3 2
Color
saturation
0 0 0 0 0 0
degree
2/8 DSatur Algorithm
D
A C
F B
Summit C A D F B E
Degree 5 4 3 3 3 2
Color Red
saturation
0 0 0 0 0 0
degree
3/8 DSatur Algorithm
D
A C
F B
Summit C A D F B E
Degree 5 4 3 3 3 2
Color Red
saturation
0 1 1 1 1 1
degree
4/8 DSatur Algorithm
D
A C
F B
Summit C A D F B E
Degree 5 4 3 3 3 2
Color Red Yel
saturation
1 1 2 2 2 1
degree
5/8 DSatur Algorithm
D
A C
F B
Summit C A D F B E
Degree 5 4 3 3 3 2
Color Red Yel Gr
saturation
2 2 2 3 2 1
degree
6/8 DSatur Algorithm
D
A C
F B
Summit C A D F B E
Degree 5 4 3 3 3 2
Color Red Yel Gr Blue
saturation
3 3 3 3 2 1
degree
7/8 DSatur Algorithm
D
A C
F B
Summit C A D F B E
Degree 5 4 3 3 3 2
Color Red Yel Gr Blue Blue
saturation
4 4 3 3 2 2
degree
8/8 DSatur Algorithm
D
A C
F B
Summit C A D F B E
Degree 5 4 3 3 3 2
Color Red Yel Gr Blue Blue Gr
saturation
4 4 3 3 2 2
degree
• Applying the coloring algorithm, it took four colors to color this graph.