Algorithms_in_C++  1.0.0
Set of algorithms implemented in C++.
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.
96  {
97  // Create following graph and test whether it is 3 colorable
98  // (3)---(2)
99  // | / |
100  // | / |
101  // | / |
102  // (0)---(1)
103 
104  const int V = 4; // number of vertices in the graph
106  std::array <int, V>({0, 1, 1, 1}),
107  std::array <int, V>({1, 0, 1, 0}),
108  std::array <int, V>({1, 1, 0, 1}),
109  std::array <int, V>({1, 0, 1, 0})
110  };
111 
112  int m = 3; // Number of colors
113  std::array <int, V> color{};
114 
115  backtracking::graphColoring<V>(graph, m, color, 0);
116  return 0;
117 }
Graph Algorithms.