For a given complete graph $G$ having $n$ nodes, how can we build a edge coloring of $G$ with $n$ colors.
-
Finding the "optimal" coloring (with the lowest number) is NP-hard, so for an arbitrary *n* that will result in backtracking. – Willem Van Onsem Jun 02 '20 at 12:57
-
you have to visit every edges of the graph, try this](https://stackoverflow.com/questions/10043060/algorithm-to-traverse-all-edges-in-a-graph) – Francesco Attorre Jun 02 '20 at 13:06
2 Answers
Just color the edge i,j with the color number i+j. You will need n-1 colors.

- 1,033
- 1
- 7
- 14
-
1Assuming you mean `i+j mod n` (otherwise you would need `2n-1` colors): this needs `n` colors, not `n-1`. Consider the complete graph `G` with 3 vertices. Obviously you need 3 colors. – Vincent van der Weele Jun 03 '20 at 07:35
You can look at the graph as a sports tournament where each node is a team, each edge is a match, and each color is a round. You are then looking for a round-robin tournament and can use the circle method (see wikipedia) to find the coloring:
The circle method is the standard algorithm to create a schedule for a round-robin tournament. All competitors are assigned to numbers, and then paired in the first round:
Round 1. (1 plays 14, 2 plays 13, ... )
Next, one of the competitors in the first or last column of the table is fixed (number one in this example) and the others rotated clockwise one position
Round 2. (1 plays 13, 14 plays 12, ... )
Round 3. (1 plays 12, 13 plays 11, ... )
This is repeated until you end up almost back at the initial position:
Round 13. (1 plays 2, 3 plays 14, ... )
For n
even this leads to a coloring with n - 1
colors.
The standard round-robin approach to deal with an odd number of teams is to add a dummy team. So for n
odd there is one additional round and you'll get a coloring with n
colors.

- 12,927
- 1
- 33
- 61