ColorUsingBacktracking will return the Color of each vertex and the total number of different colors used, using backtracking
()
| 8 | // ColorUsingBacktracking will return the Color of each vertex and the |
| 9 | // total number of different colors used, using backtracking |
| 10 | func (g *Graph) ColorUsingBacktracking() (map[int]Color, int) { |
| 11 | vertexColors := make(map[int]Color, g.vertices) |
| 12 | g.colorVertex(0, vertexColors) |
| 13 | |
| 14 | colorsUsed := 0 |
| 15 | for _, cr := range vertexColors { |
| 16 | if colorsUsed < int(cr) { |
| 17 | colorsUsed = int(cr) |
| 18 | } |
| 19 | } |
| 20 | return vertexColors, colorsUsed |
| 21 | } |
| 22 | |
| 23 | // colorVertex will try to color provided vertex, v |
| 24 | func (g *Graph) colorVertex(v int, color map[int]Color) bool { |