Vizing’s Theorem of graph theory states that every simple undirected graph has a chromatic index of one larger than the maximum degree ‘d’ of the graph. In simple meaning, the theorem states that the chromatic index can be either ‘d’ or ‘d’+1.
Chromatic Index of a graph is the minimum number of colors required to color the edges of the graph such that any two edges that share the same vertex have different colors.
Chromatic Index = 3
Edge from 1 to 2 : Color 1
Edge from 2 to 3 : Color 2
Edge from 3 to 4 : Color 1
Edge from 4 to 1 : Color 2
Edge from 1 to 3 : Color 3
Below is the step-by-step approach of the algorithm:-
- Initialize the number of edges and the edge list.
- Color the graph according to the Vizing’s Theorem.
- Assign a color to an edge and check if any adjacent edges have the same color or not.
- If any adjacent edge has the same color, then increment the color to try the next color for that edge.
- Repeat till all the edges get it’s color according to the theorem.
- Once done print the maximum value of color for all the edges and the colors of every edge.
Implementation of the above approach:
Chromatic Index = 3 Edge from 1 to 2 : Color 1 Edge from 2 to 3 : Color 2 Edge from 3 to 4 : Color 1 Edge from 4 to 1 : Color 2 Edge from 1 to 3 : Color 3
Attention reader! Don’t stop learning now. Get hold of all the important Java Foundation and Collections concepts with the Fundamentals of Java and Java Collections Course at a student-friendly price and become industry ready. To complete your preparation from learning a language to DS Algo and many more, please refer Complete Interview Preparation Course.