![]() |
VOOZH | about |
In graph theory, Vizing's theorem states that every simple undirected graph may be edge colored using a number of colors that is at most one larger than the maximum degree 'd' of the graph. In simple meaning this theorem states that the chromatic index of the simple graph can be either 'd' or 'd' +1. The minimum number of colors needed for the edge coloring of the graph is called chromatic index.
There are 5 vertices in the above graph G. Highest Degree is 4, but we need 5 colors, so that no edge shares the same color with any edge of the adjacent vertices, as you can see in the above graph. Therefore the required number of valid colors for this graph is equal to 5, which is ( 'highest degree' + 1 ).
Note: c1, c2, c3, c4 and c5 in the above diagram implies distinct colors.
Examples :
Input :
v = 3, e = 3
{{ 1, 2, -1 },
{ 2, 3, -1 },
{ 3, 1, -1 }};
Output :
3 colors needs to generate a valid edge coloring :
color between v(1): 1 and v(2): 2 is: color 1
color between v(1): 2 and v(2): 3 is: color 2
color between v(1): 3 and v(2): 1 is: color 3
Algorithm:
Below is the implementation of the above approach:
3 colors needs to generate a valid edge coloring: color between v(1): 1 and v(2): 2 is: color 1 color between v(1): 2 and v(2): 3 is: color 2 color between v(1): 3 and v(2): 4 is: color 1 color between v(1): 4 and v(2): 1 is: color 2 color between v(1): 1 and v(2): 3 is: color 3
Time Complexity: O(e2)
Auxiliary Space: O(1)
As constant extra space is used.