![]() |
VOOZH | about |
Graph coloring in programming refers to the assignment of colors to the vertices of a graph in a way that no two adjacent vertices share the same color. In this article, we will cover the concepts of Graph coloring, why is it important to learn for Competitive Programming and other related concepts like: Bipartite Graph, Chromatic Number, etc.
Table of Content
Graph coloring refers to the problem of coloring vertices of a graph in such a way that no two adjacent vertices have the samecolor. This is also called the vertex coloring problem. If coloring is done using at most m colors, it is called m-coloring.
In CP as the difficulty of problems increases, the problem setter mostly chooses a graph-based problem. The solution of many such problems lies in the concept of graph coloring which mainly revolves around 3 key concepts:
In this article, we will see how these concepts are used in a problem.
A bipartite graph is a graph in which the vertices can be divided into two disjoint sets, such that no two vertices within the same set are adjacent. In other words, it is a graph in which every edge connects a vertex of one set to a vertex of the other set.
Imagine a problem where the solution exists only when the graph has a cycle of Even length and for Odd length cycles the solution is invalid. In these type of problem Bi-partite coloring is the easiest solution as Bipartite coloring is only possible for Even length cycles as shown in Below image:
👁 img1drawio
Using bipartite coloring a graph can be partitioned into two subsets such that all the vertices in the same set, does not contain any edge among them as shown in the image below:
👁 ImageTry to Solve to understand this concept properly.
: O(V+E) where V is the number of edges and E is the number of Edges in the graph.
The "M-coloring" of a graph refers to the assignment of colors to the vertices of a graph such that no two adjacent vertices share the same color. The chromatic number of a graph is the minimum number of colors needed to color the vertices of the graph in such a way that no two adjacent vertices have the same color.
Article Link | Problem Link |
|---|---|
Minimum labelled node to be removed from undirected Graph such that there is no cycle | Solve Now |
Solve Now | |
Solve Now | |
Solve Now | |
Solve Now | |
Solve Now | |
Minimize colors to paint graph such that no path have same color | Solve Now |