mirror of
https://github.com/TheAlgorithms/Python.git
synced 2024-11-23 21:11:08 +00:00
Fix comments in backtracking/coloring.py (#4857)
This commit is contained in:
parent
d1e70cfa3a
commit
6341f351aa
|
@ -1,7 +1,7 @@
|
|||
"""
|
||||
Graph Coloring also called "m coloring problem"
|
||||
consists of coloring given graph with at most m colors
|
||||
such that no adjacent vertices are assigned same color
|
||||
consists of coloring a given graph with at most m colors
|
||||
such that no adjacent vertices are assigned the same color
|
||||
|
||||
Wikipedia: https://en.wikipedia.org/wiki/Graph_coloring
|
||||
"""
|
||||
|
@ -11,9 +11,9 @@ def valid_coloring(
|
|||
neighbours: list[int], colored_vertices: list[int], color: int
|
||||
) -> bool:
|
||||
"""
|
||||
For each neighbour check if coloring constraint is satisfied
|
||||
For each neighbour check if the coloring constraint is satisfied
|
||||
If any of the neighbours fail the constraint return False
|
||||
If all neighbours validate constraint return True
|
||||
If all neighbours validate the constraint return True
|
||||
|
||||
>>> neighbours = [0,1,0,1,0]
|
||||
>>> colored_vertices = [0, 2, 1, 2, 0]
|
||||
|
@ -41,14 +41,14 @@ def util_color(
|
|||
|
||||
Base Case:
|
||||
1. Check if coloring is complete
|
||||
1.1 If complete return True (meaning that we successfully colored graph)
|
||||
1.1 If complete return True (meaning that we successfully colored the graph)
|
||||
|
||||
Recursive Step:
|
||||
2. Itterates over each color:
|
||||
Check if current coloring is valid:
|
||||
2. Iterates over each color:
|
||||
Check if the current coloring is valid:
|
||||
2.1. Color given vertex
|
||||
2.2. Do recursive call check if this coloring leads to solving problem
|
||||
2.4. if current coloring leads to solution return
|
||||
2.2. Do recursive call, check if this coloring leads to a solution
|
||||
2.4. if current coloring leads to a solution return
|
||||
2.5. Uncolor given vertex
|
||||
|
||||
>>> graph = [[0, 1, 0, 0, 0],
|
||||
|
|
Loading…
Reference in New Issue
Block a user