graph_coloring.cpp File Reference

prints the assigned colors using Graph Coloring algorithm More...

`#include <iostream>`
`#include <array>`
`#include <vector>`
Include dependency graph for graph_coloring.cpp:

## Namespaces

| backtracking
| Backtracking algorithms.

## Functions

template<size_t V>
void | backtracking::printSolution (const std::array< int, V > &color)
template<size_t V>
bool | backtracking::isSafe (int v, const std::array< std::array< int, V >, V > &graph, const std::array< int, V > &color, int c)
template<size_t V>
void | backtracking::graphColoring (const std::array< std::array< int, V >, V > &graph, int m, std::array< int, V > color, int v)
int | main ()

## Detailed Description

prints the assigned colors using Graph Coloring algorithm

In graph theory, graph coloring is a special case of graph labeling; it is an assignment of labels traditionally called "colors" to elements of a graph subject to certain constraints. In its simplest form, it is a way of coloring the vertices of a graph such that no two adjacent vertices are of the same color; this is called a vertex coloring. Similarly, an edge coloring assigns a color to each edge so that no two adjacent edges are of the same color, and a face coloring of a planar graph assigns a color to each face or region so that no two faces that share a boundary have the same color.

Author
  Anup Kumar Panwar
  David Leal

## Function Documentation

## main()

int main | ( | void |  | ) |

Main function

Driver Code

Examples
  /Users/runner/work/C-Plus-Plus/C-Plus-Plus/numerical_methods/rungekutta.cpp, and /Users/runner/work/C-Plus-Plus/C-Plus-Plus/sorting/wiggle_sort.cpp.

{
// Create following graph and test whether it is 3 colorable
// (3)---(2)
// | / |
// | / |
// | / |
// (0)---(1)
const int V = 4; // number of vertices in the graph
std::array <std::array <int, V>, V> graph = {
std::array <int, V>({0, 1, 1, 1}),
std::array <int, V>({1, 0, 1, 0}),
std::array <int, V>({1, 1, 0, 1}),
std::array <int, V>({1, 0, 1, 0})
};
int m = 3; // Number of colors
std::array <int, V> color{};
backtracking::graphColoring<V>(graph, m, color, 0);
return 0;
}
std::array
graph
Graph Algorithms.