Chromatic Number in JavaThe chromatic numbers are generally used in the coloring of graph nodes with some constraints. Chromatic Numbers in Java tell the minimum number of unique colors required to color all the nodes of a graph such that any two adjacent nodes do not have the same color. It can be used in many applications. In this section, we will implement the greedy approach to find the chromatic number for a graph. Steps to Find the Chromatic NumbersStep 1: Assign the first color to the first node of the graph. Step 2: Do the following for the remaining N  1 node. Consider the currently picked node and assign a color to it with the lowest numbered color. Provided that the color has not been applied on any of the previously colored nodes adjacent to it. If all colors that are previously used appear on the nodes that are adjacent to, assign a new color to it. Examples of Chromatic NumberChromatic Number Java ProgramThe following program is based on the steps defined above. FileName: Graphs.java Output: Coloring of the graph 1 is: Node 0 > Color  0 Node 1 > Color  1 Node 2 > Color  2 Node 3 > Color  0 Node 4 > Color  1 The chromatic number of the graph is: 3 Coloring of the graph 2 is: Node 0 > Color  0 Node 1 > Color  1 Node 2 > Color  1 Node 3 > Color  0 The chromatic number of the graph is: 2 Let's see the graph, we have used in the above program. Graph1 Graph2 Application of Chromatic NumberThere is a lot of applications where chromatic number is used. A few of them are mentioned below. 1) Assignment of Mobile Radio Frequency: At the same location, when frequencies are being assigned to mobile towers, there must be the difference in the frequencies assigned to all the towers. To assign the frequencies with this constraint, and the number of frequencies should also be the minimum, we need the help of chromatic numbers. The towers can be treated as nodes, and an edge between these two nodes shows the towers are in the range of each other. Now, this is the standard graph coloring problem, where we have to reduce the total number of unique colors, which is given by the chromatic number of the graph. 2) Time Table or Making Schedule: Suppose, one has to create an exam schedule for a college or university. The person has the information about all the subjects, and the students enrolled in them. A simple way of scheduling is to conduct exam of only one subject in a onetime slot. Thus, the total time slot will be equal to the total number of subjects available. However, such kind of scheduling is not efficient, as it is required to minimize the time slots. Also, one cannot schedule the exam of all subjects in a single time slot. It is because one student may get enrolled in different subjects. If the exam is happening of those subjects in a single time slot, then the student can only give exam of the single subject, rest of other exams is going to be missed by the student. Thus, the time slots have to be minimized in such a way that there is no conflict. To do so, we take the graph coloring technique. The subjects are treated as nodes, and an edge will only exist between two nodes if there is a common student that is enrolled to those two subjects. After creating the graph, find its chromatic number. The chromatic number gives the minimum time slots required to conduct the exam successfully.
Next TopicSublime Number in Java
