1
1
"""
2
2
Graph Coloring also called "m coloring problem"
3
- consists of coloring given graph with at most m colors
4
- such that no adjacent vertices are assigned same color
3
+ consists of coloring a given graph with at most m colors
4
+ such that no adjacent vertices are assigned the same color
5
5
6
6
Wikipedia: https://en.wikipedia.org/wiki/Graph_coloring
7
7
"""
@@ -11,9 +11,9 @@ def valid_coloring(
11
11
neighbours : list [int ], colored_vertices : list [int ], color : int
12
12
) -> bool :
13
13
"""
14
- For each neighbour check if coloring constraint is satisfied
14
+ For each neighbour check if the coloring constraint is satisfied
15
15
If any of the neighbours fail the constraint return False
16
- If all neighbours validate constraint return True
16
+ If all neighbours validate the constraint return True
17
17
18
18
>>> neighbours = [0,1,0,1,0]
19
19
>>> colored_vertices = [0, 2, 1, 2, 0]
@@ -41,14 +41,14 @@ def util_color(
41
41
42
42
Base Case:
43
43
1. Check if coloring is complete
44
- 1.1 If complete return True (meaning that we successfully colored graph)
44
+ 1.1 If complete return True (meaning that we successfully colored the graph)
45
45
46
46
Recursive Step:
47
- 2. Itterates over each color:
48
- Check if current coloring is valid:
47
+ 2. Iterates over each color:
48
+ Check if the current coloring is valid:
49
49
2.1. Color given vertex
50
- 2.2. Do recursive call check if this coloring leads to solving problem
51
- 2.4. if current coloring leads to solution return
50
+ 2.2. Do recursive call, check if this coloring leads to a solution
51
+ 2.4. if current coloring leads to a solution return
52
52
2.5. Uncolor given vertex
53
53
54
54
>>> graph = [[0, 1, 0, 0, 0],
0 commit comments