Java Program to Implement the Vizing’s Theorem Last Updated : 22 Feb, 2021 Comments Improve Suggest changes Like Article Like Report 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. Examples: Input: Output: 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 Algorithm: 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: Java // Java program to Implement // Vizing's Theorem import java.util.*; public class chromaticIndex { // Function to find the chromatic index public void edgeColoring(int[][] edges, int e) { // Initialize edge to first // edge and color to color 1 int i = 0, color = 1; // Repeat until all edges are done coloring while (i < e) { // Give the selected edge a color edges[i][2] = color; boolean flag = false; // Iterate through all others edges to check for (int j = 0; j < e; j++) { // Ignore if same edge if (j == i) continue; // Check if one vertex is similar if ((edges[i][0] == edges[j][0]) || (edges[i][1] == edges[j][0]) || (edges[i][0] == edges[j][1]) || (edges[i][1] == edges[j][1])) { // Check if color is similar if (edges[i][2] == edges[j][2]) { // Increment the color by 1 color++; flag = true; break; } } } // If same color faced then repeat again if (flag == true) { continue; } // Or else proceed to a new vertex with color 1 color = 1; i++; } // Check the maximum color from all the edge colors int maxColor = -1; for (i = 0; i < e; i++) { maxColor = Math.max(maxColor, edges[i][2]); } // Print the chromatic index System.out.println("Chromatic Index = " + maxColor); for (i = 0; i < e; i++) { System.out.println("Edge from " + edges[i][0] + " to " + edges[i][1] + " : Color " + edges[i][2]); } } // Driver code public static void main(String[] args) { // Number of edges int e = 5; // Edge list int[][] edges = new int[e][3]; // Initialize all edge colors to 0 for (int i = 0; i < e; i++) { edges[i][2] = -1; } // Edges edges[0][0] = 1; edges[0][1] = 2; edges[1][0] = 2; edges[1][1] = 3; edges[2][0] = 3; edges[2][1] = 4; edges[3][0] = 4; edges[3][1] = 1; edges[4][0] = 1; edges[4][1] = 3; // Run the function chromaticIndex c = new chromaticIndex(); c.edgeColoring(edges, e); } } OutputChromatic 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 Comment More infoAdvertise with us Next Article Java Program to Implement the Vizing’s Theorem D debrc Follow Improve Article Tags : Java Technical Scripter Java Programs Technical Scripter 2020 Practice Tags : Java Similar Reads Java Program to Implement VList VList is a data structure that combines fast indexing of arrays with the easy extension of singly-linked lists. VList generally supports the following functions. Insert ElementGet Element at index kClear ListDisplay ListEtc. VList has rows connected as Singly Linked List where the Nth row contains m 3 min read Java Program to Implement RenderingHints API Graphics attribute used by the Graphics2D class is java.awt.RenderingHints. This class is a mapping (a java.util.Map) from a set of rendering hint names to a set of rendering hint values. Unlike with other attributes, Graphics2D defines more than one method to set the rendering hints attribute. setR 5 min read Java Program to Implement Bowyer-Watson Algorithm To gain some practical programming experience related to computational geometry topics, we will apply the Bowyer-Watson algorithm that will be able to facilitate the process to some extent. Bowyer-Watson AlgorithmThe Bowyer-Watson algorithm is a computational algorithm for constructing Delaunay tria 4 min read Java Program to Implement of Gabow Scaling Algorithm Gabow's Algorithm is a scaling algorithm that aims in solving a problem by initially considering only the highest order bit of each relevant input value (such as an edge weight). Then it refines the initial solution by looking at the two highest-order bits. It progressively looks at more and more hi 4 min read Java Program to Apply Delaunay Triangulation Algorithm Computational geometry to triangulate a set of points in a plane or in higher dimensions is not an easy task but we can perform this using Delaunay Triangulation Algorithm. Let us apply Delaunay Triangulation Algorithm in this article. What is Delaunay Triangulation Algorithm? Delaunay triangulation 8 min read Java Program that Shows Use of Collection Interface The Collection framework is a unified architecture for representing and manipulating collections, enabling collections to be manipulated independently of implementation details. Uses and advantages of Collection Framework: This reduces the efforts of programmers by providing data structures and algo 3 min read Implement Filter Function using Reduce in Java 8 Streams Many times, we need to perform operations where a stream reduces to a single resultant value, for example, maximum, minimum, sum, product, etc. Reducing is the repeated process of combining all elements. reduce operation applies a binary operator to each element in the stream where the first argumen 2 min read Implement a Sparse Matrix Representation and Operations in Java A matrix with a high proportion of zero members is called a Sparse Matrix. Memory and computing resources may be conserved by effectively representing and manipulating sparse matrices. Java provides many methods for doing fundamental operations and representing sparse matrices. In this article, we w 4 min read Java Collection Programs - Basic to Advanced As it cleared from its name itself "Collection" it is a pre-defined collective bunch of classes and Interfaces present in the "Collection Framework" in Java. Their Classes, Interfaces and Methods are frequently used in competitive programming. This article provides a variety of programs on Java Coll 4 min read Like