MCPcopy Index your code
hub / github.com/TheAlgorithms/Go / ColorUsingBacktracking

Method ColorUsingBacktracking

graph/coloring/backtracking.go:10–21  ·  view source on GitHub ↗

ColorUsingBacktracking will return the Color of each vertex and the total number of different colors used, using backtracking

()

Source from the content-addressed store, hash-verified

8// ColorUsingBacktracking will return the Color of each vertex and the
9// total number of different colors used, using backtracking
10func (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
24func (g *Graph) colorVertex(v int, color map[int]Color) bool {

Callers 1

Calls 1

colorVertexMethod · 0.95

Tested by 1