MCPcopy Create free account
hub / github.com/PrajaktaSathe/Java / graphColoring

Method graphColoring

Programs/Mcolor.java:39–65  ·  view source on GitHub ↗
(boolean[][] graph, int m,
                                 int i, int[] color)

Source from the content-addressed store, hash-verified

37 one solutions, this function prints one
38 of the feasible solutions.*/
39 static boolean graphColoring(boolean[][] graph, int m,
40 int i, int[] color)
41 {
42 // if current index reached end
43 if (i == V) {
44
45 // if coloring is safe
46 if (isSafe(graph, color)) {
47
48 // Print the solution
49 printSolution(color);
50 return true;
51 }
52 return false;
53 }
54
55 // Assign each color from 1 to m
56 for (int j = 1; j <= m; j++) {
57 color[i] = j;
58
59 // Recur of the rest vertices
60 if (graphColoring(graph, m, i + 1, color))
61 return true;
62 color[i] = 0;
63 }
64 return false;
65 }
66
67 // Driver code
68 public static void main(String[] args)

Callers 1

mainMethod · 0.95

Calls 2

isSafeMethod · 0.95
printSolutionMethod · 0.95

Tested by

no test coverage detected