Graph Coloring
Graph Coloring
for c from 1 to m:
if isSafe(v, graph, color, c):
color[v] = c
if solve(v + 1, graph, color, m):
return true
color[v] = 0 // Backtrack
return false
Space complexity
In terms of space complexity, the algorithm uses an array of size V to store color
assignments, so the space complexity is O(V). There is also recursive stack space used during
backtracking, which can go up to depth V, hence additional O(V) space. So, total space
complexity is O(V).
19.4 Source code
Output