C++ Program to Perform Edge Coloring on Complete Graph

A complete graph is a graph which has a connecting edge between any pair of vertices. This is a C++ Program to Perform Edge Coloring on Complete Graph.

Algorithm

Begin
   Take the input of the number of vertices ‘n’.
   Construct a complete graph using e=n*(n-1)/2 edges, in ed[][].
   Function EdgeColor() is used to Color the graph edges.
   A) Assign color to current edge as c i.e. 1 initially.
   B) If the same color is occupied by any of the adjacent edges, then
      discard this color and go to flag again and try next color.
   C) Print the color for each edge.
End

Example

#include
using namespace std;
void EdgeColor(int ed[][3], int e) {
   int i, c, j;
   for(i = 0; i >n;
   e = (n*(n-1))/2;
   int ed[e][3];
   for(i = 1; i 

Output

Enter the number of vertexes for the complete graph: 4
The color of the edge between vertex n(1):1 and n(2):2 is: color1.
The color of the edge between vertex n(1):1 and n(2):3 is: color2.
The color of the edge between vertex n(1):1 and n(2):4 is: color3.
The color of the edge between vertex n(1):2 and n(2):3 is: color3.
The color of the edge between vertex n(1):2 and n(2):4 is: color2.
The color of the edge between vertex n(1):3 and n(2):4 is: color1.
Updated on: 2019-07-30T22:30:25+05:30

391 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements