A note on equitable Hamiltonian cycles

Given a complete graph with an even number of vertices, and with each edge colored with one of two colors (say red or blue), an equitable Hamiltonian cycle is a Hamiltonian cycle that can be decomposed into two perfect matchings such that both perfect matchings have the same number of red edges. We show that, for any coloring of the edges, in any complete graph on at least 6 vertices, an equitable Hamiltonian cycle exists. © 2020TheAuthors.PublishedbyElsevierB.V.ThisisanopenaccessarticleundertheCCBY


Introduction
Let G = (V , E) be a simple, complete graph on n ≡ |V | vertices, with n even.Each edge e ∈ E is colored with one of two colors, say red or blue.We will refer to the resulting object as a colored graph G.To avoid trivialities, we assume throughout this note that n ≥ 4; we refer to [3] for the definition of graph-theoretical terms that we use.Since n is even, any Hamiltonian cycle C present in the colored graph G, can be decomposed into two perfect matchings M E (C ) and M O (C ).We call M E (C ) (M O (C )) the even (odd) matching, and its edges the even (odd) edges.In case C is clear from the context, we write M E and M O .For an edge e ∈ C , the parity of this edge is even if e ∈ M E and odd if e ∈ M O .Notice that, as the matchings are perfect, the decomposition is unique up to deciding which matching is even or odd.Hence, once the parity of a single edge in a Hamiltonian cycle is fixed, the parity of each edge of this Hamiltonian cycle is fixed.Given a (perfect) matching M in G, we let r(M) denote the number of red edges in M. Consider now the following definition.As an example, consider the graph depicted in Fig. 1.One can verify that this colored graph is, in fact, nice, since it contains an equitable Hamiltonian cycle; for example, the cycle C = {(1, 2), (2,3), (3,6), (6,4), (4,5), (5, 1)} is Hamiltonian, and consists solely of red edges, and is therefore equitable.
In this note, we investigate whether colored graphs are nice, and we address algorithms that identify equitable Hamiltonian cycles if they exist.The motivation for studying this question comes from an optimization problem studied in Kinable et al. [11]; this problem can be seen as a member of a class of optimization problems called balanced optimization problems.Kinable et al. [11] are interested in finding solutions to the Traveling Salesman Problem where, instead of minimizing total cost, the absolute value of the difference between the costs of the two perfect matchings making up the tour is minimized; they call this variant the Equitable TSP.They show that this problem is NP-hard, using a reduction with many different values for the distances between two points; in addition, they study the performance of integer programming based approaches for this problem.Here, we settle the complexity of the Equitable TSP with two possible values for the distances.
More generally, we view the problem considered here as related to Ramsey theory: we prove that colored graphs of a certain size necessarily contain equitable Hamiltonian cycles.We refer to Graham et al. [9], and Conlon et al. [4] for overviews; however, as far as we are aware, our specific question has not been investigated before.
The fact that a Hamiltonian cycle can be seen as the union of two (perfect) matchings is an observation that has been used in many different contexts.In Cygan et al. [6], perfect matchings are used for fast Hamiltonicity checking of graphs.Kreweras [12] conjectured that a perfect matching in the hypercube extends to a Hamiltonian cycle, which was proven by Fink [7,8], and further considered in Gregor [10] and Wang and Sun [13].
There is also work on problems concerning so-called alternating Hamiltonian cycles in which the colors of consecutive edges in the cycle need to alternate; see e.g., Abouelaoualim et al. [1] and Contreras et al. [5] and Bang-Jensen and Gutin [2] for a survey.
Our results.In Section 2 we prove constructively that each colored graph on n ≥ 6 vertices is nice, i.e., contains an equitable Hamiltonian cycle.We also present the only colored graph that is not nice (see Fig. 2).We show in Section 3 that an equitable Hamiltonian cycle can be found efficiently; notice that this result is in contrast to the standard TSP, which is already NP-hard when the distances are in {1, 2}.In Section 4 we focus on a local search algorithm that uses a standard 2-OPT neighborhood.We show that, although this local search algorithm is not exact (i.e., the algorithm does not always return an equitable Hamiltonian cycle even if one exists), it is true that, in a local optimum, the number of red edges in the even matching differs by at most 1 from the number of red edges in the odd matching; moreover, this is tight.We conclude in Section 5.

Almost all colored graphs are nice
This section contains our main result, Theorem 2.1.In Section 2.1 we sketch the outline of a procedure for finding an equitable Hamiltonian cycle whenever one exists, and in Section 2.2 we focus on a crucial step in this procedure.

General outline
Recall that the phrase ''colored graph'' stands for a complete graph with an even number of vertices, where each edge is colored either red or blue.Consider the colored graph depicted in Fig. 2 -we leave it to the reader to verify that this graph is not nice.
However, as phrased in the following theorem, we will prove that this colored graph is the only existing graph that is not nice.
Theorem 2.1.The only colored graph that is not nice is the one depicted in Fig. 2; all other colored graphs are nice.
It is not difficult to verify that any colored graph with n = 4, other than the one depicted in Fig. 2, is nice.Thus, from now on, we focus on the case n ≥ 6.
The main idea of the algorithm is as follows.
Step 1 If n ≤ 10, find an equitable Hamiltonian cycle C by complete enumeration Step 2 Else (n ≥ 12) Step 2a Let Step 3 Return C

Merging two equitable cycles
The key step in Algorithm 1 is the merging procedure (Step 2d), where we merge two equitable cycles into a single one.To argue that this is always possible, we have to distinguish several cases.To describe these cases, we need the concepts of a mono-chromatic pair, a connecting edge, and a box.Definition 2.2.Given is a colored graph G, and an equitable Hamiltonian cycle C in G. Let the edges {u 1 , u 2 } and {u 2 , u 3 } be incident in C .We say that these edges form a mono-chromatic pair if they have the same color.The vertex u 2 is then called the center of the mono-chromatic pair.
Notice that a Hamiltonian cycle without any mono-chromatic pair is alternating in color, and hence, is not equitable.Therefore, any equitable Hamiltonian cycle needs to contain at least one mono-chromatic pair.A stronger statement is made in Lemma 3.2.

be the center of the mono-chromatic pair of edges in an equitable
).The edge {u, v} connecting the two centers is called the connecting edge of the two mono-chromatic pairs.
In Fig. 3, a box with two red and two blue edges is depicted.The presence of a box allows for a relatively simple way of merging two equitable cycles.Indeed, given two equitable Hamiltonian cycles, form a box, Lemma 2.5 shows how to merge these two equitable cycles into a single equitable cycle that is a Hamiltonian cycle in G.

Lemma 2.5. Given is a colored graph
. If these edges form a box, then the cycle C that results when {u 1 , u 2 } and {v 1 , v 2 } are replaced by {u 1 , v 1 } and {u 2 , v 2 }, is an equitable Hamiltonian cycle in G. Proof.See Fig. 3.We can choose the parity of {u 1 , u 2 } in C 1 and {v 1 , v 2 } in C 2 to be the same.The cycle C results when replacing {u 1 , u 2 } by {u 1 , v 1 } and {v 1 , v 2 } by {u 2 , v 2 }.Notice that this change does not change the parity of the other edges.Furthermore, since {u 1 , u 2 } and {v 1 , v 2 } form a box, we have replaced one edge by another edge of the same parity and color.Therefore, In the remainder of this section, we show how to deal with the absence of a box.Using a case-distinction, Lemma 2.6 shows how to merge two equitable Hamiltonian cycles respectively, given a mono-chromatic pair in each cycle of which no combination of edges form a box.
having connecting edge {u 2 , v 2 }.We refer to the edges {u 1 , v 2 }, {u 2 , v 1 }, {u 2 , v 3 } and {u 3 , v 2 } as the diagonal edges and to {u 1 , v 3 } and {u 3 , v 1 } as the long diagonal edges.Further, we denote by {u 0 , that are incident to edges of the monochromatic pair P u (P v ); we denote these edges as incident edges.
We distinguish three base cases (Case A, B, and C) depending on the colors of the edges of the mono-chromatic pairs and their connecting edge, see Fig. 4. Case A: Two blue mono-chromatic pairs and a blue connecting edge.As, by assumption, no two edges of the mono-chromatic pairs form a box, we know that both {u 1 , v 1 } and {u 3 , v 3 } are red edges.Case A.1: There exists a blue diagonal edge.If there exists a blue diagonal edge, say {u 1 , v 2 }, then we know that the edge {u 2 , v 1 } needs to be red as otherwise {u 1 , u 2 } and {v 1 , v 2 } form a box.We merge the two cycles, by removing all the edges of the two mono-chromatic pairs and replace them by the blue edges {u 1 , v 2 } and {u 2 , v 2 } and the red edges {u 2 , v 1 } and {u 3 , v 3 }, see Fig. 5.Note that the two red edges will have different parity and therefore the number of red edges in both the even and the odd matching is increased by one, resulting in a cycle that is equitable and Hamiltonian in G.
Case A.2: All diagonal edges are red.Then, it follows that the long diagonal edge {u 1 , v 3 } also needs to be red, as otherwise {u 1 , u 2 } and {v 2 , v 3 } form a box.We make a further case distinction depending on whether or not one of the two mono-chromatic pairs is incident to a red edge in its current cycle.

Case A.2.1:
There exists an incident red edge.Assume, without loss of generality, that {u 0 , u 1 } is a red edge.It follows that {u 0 , v 1 } needs to be a red edge, as otherwise {u 0 , u 1 } and {v 2 , v 1 } form a box, and we can apply Lemma 2.5 (see Fig. 6).We merge the two cycles by replacing the red edge {u 0 , u 1 } by the red edge {u 0 , v 1 } and replacing the two mono-chromatic pairs by the path {u 3 , v 2 , u 2 , u 1 , v 3 }, see the thick edges in Fig. 6 for the merged cycle.Note that the red edge {u 0 , v 1 } has the same parity as the deleted red edge {u 0 , u 1 } and the two red edges in the path have opposite parity.Therefore, the resulting cycle is equitable and Hamiltonian in G. Case A.2.2: All incident edges are blue.Finally, in case that both mono-chromatic pairs are only incident to blue edges in their own cycles, there exist blue edges {u 0 , u 1 } and {v 0 , v 1 } on either cycle.If the edge {u 0 , v 0 } is blue, then we replace the two blue edges {u 0 , u 1 } and {v 0 , v 1 } by the blue edge {u 0 , v 0 } and the two mono-chromatic pairs by the path {v 3 , u 1 , v 1 , v 2 , u 2 , u 3 }.As the two new red edges, {v 3 , u 1 } and {u 1 , v 1 }, are of opposite parity, the resulting cycle is equitable, see Fig. 7. On the other hand, if the edge {u 0 , v 0 } is red, we replace the two blue edges {u 0 , u 1 } and {v 0 , v 1 } by the red edge {u 0 , v 0 }, and the two mono-chromatic pairs by the path {v 3 , v 2 , u 1 , v 1 , u 2 , u 3 }, see Fig. 7. Assuming, without loss of generality, that the edge {u 0 , v 0 } in the merged cycle is even, we have that the edges {v 2 , u 1 } and {v 1 , u 2 } are odd and {u 1 , v 1 } is even.Hence, we have introduced as many red edges in the even matching as in the odd matching and therefore, the merged cycle is equitable and Hamiltonian in G. Case B: Two blue mono-chromatic pairs and a red connecting edge.We distinguish two subcases.8 for an illustration of this case.We replace the path {u 1 , u 2 , u 3 } by the path {u 1 , v 2 , u 3 } and the path {v 1 , v 2 , v 3 } by {v 1 , u 2 , v 3 }.This results in two disjoint cycles, each of which has a red mono-chromatic pair with connecting edge {u 2 , v 2 } which is also red.This situation is identical to Case A.

Case B.2:
There exists a blue diagonal edge.Assume, without loss of generality, that {u 1 , v 2 } is blue.Then {u 2 , v 3 } needs to be red as otherwise {u 1 , u 2 } and {v 2 , v 3 } form a box.Consider the edge {u 0 , u 1 } ∈ C 1 .If this edge is blue, then {u 0 , u 1 , u 2 } form a blue mono-chromatic pair in C 1 and the connecting edge to the blue mono-chromatic pair in C 2 , {u 1 , v 2 } is also blue, so we can merge according to Case A. Therefore, we assume that the edge {u 0 , u 1 } is red.Moreover, {u 0 , v 1 } needs to be blue as otherwise {u 0 , u 1 } and {v 1 , v 2 } form a box, and we can apply Lemma 2.5 (see Fig. 9).
We merge the two cycles, by replacing the edges {u 0 , u 1 } and {v 1 , v 2 } by the edge {u 0 , v 1 } and replacing the two monochromatic pairs by, in case that the edge {u 1 , The deleted red edge {u 0 , u 1 } has the same parity as, in the first case, the red edge {u 2 , v 2 } or, in the second case, the red edge {u 1 , u 3 }.In this case also note that two more red edges {v 3 , u 2 } and {u 2 , v 2 } are inserted in the new cycle, but these have opposite parity.Hence, the final cycle is equitable and Hamiltonian in G.
Case C: One blue mono-chromatic pair and a red one.As, by assumption, {u 1 , u 2 } and {v 2 , v 1 } do not form a box, we know that the edges {u 1 , v 2 } and {u 2 , v 1 } have the same color.Using the same arguments, it can be shown that all diagonal edges have the same color.We replace the path {u thereby obtaining two disjoint cycles having mono-chromatic pairs of the same color.Depending on the color of the connecting edge compared to the color of the mono-chromatic pairs, we can apply Case A or B, see Fig. 10.□ Theorem 2.1 now follows from Lemma 2.5 and Lemma 2.6.

The running time of Algorithm 1
Theorem 2.1 is an existence result.However, its proof shows that Algorithm 1 finds an equitable Hamiltonian cycle for n ≥ 6.In this section, we discuss the running time of this algorithm.Algorithm 1 recursively computes equitable cycles by splitting the graph into two induced subgraphs of almost equal size.This way, we can interpret the algorithm as a binary tree in which each node represents a subset of vertices on which an equitable Hamiltonian cycle is obtained by merging the equitable Hamiltonian cycles of its two children.The leaf-nodes of this tree represent the base case with n ≤ 10, see Fig. 11.We say that a node in the tree is at depth i, if the path from the node to the root-node has length i.
For these base cases in the leaf-nodes, we can find an equitable Hamiltonian cycle by complete enumeration in constant time as there are at most 10 vertices in the graph.To merge two equitable Hamiltonian cycles, we need to find a monochromatic pair in each cycle, and then we can merge in constant time using the procedure as described in Sub Section 2.2.Finding a mono-chromatic pair in an equitable Hamiltonian cycle can be done by searching the cycle until one is found.This takes time linear in the number of vertices on the cycle and therefore the time to merge two equitable cycles is linear in the length of the resulting cycle.The sum of the lengths of all the cycles at depth i is at most n and therefore, the time to find the equitable Hamiltonian cycles for the induced subgraphs at depth i of the algorithm is linear in the total number of vertices.As the maximum depth in the tree is O(log n), the running time can be bounded by O(n log n).
The running time of the algorithm can be improved by the following observation, which is shown in Lemma 3.2: any equitable Hamiltonian cycle on at least 12 vertices has at least two mono-chromatic pairs that have at least two edges in between.Consider merging two equitable Hamiltonian cycles, C 1 and C 2 , each of them on at least 12 vertices and let P 11 and P 12 (P 21 and P 22 ) be two mono-chromatic pairs on C 1 (C 2 ) at distance at least two edges of each other.Then, when merging C 1 and C 2 using mono-chromatic pairs P 11 and P 21 , the pairs P 12 and P 22 remain unaffected by the merging procedure, that is, P 12 and P 22 are mono-chromatic pairs on the merged cycle C .Moreover, P 12 and P 22 have at least two edges in between.Hence, if, for each equitable Hamiltonian cycle on at least 12 vertices, we also keep track of two mono-chromatic pairs at distance at least two edges of each other, then it only takes constant time to merge two equitable Hamiltonian cycles and obtain two mono-chromatic pairs at distance at least two.Hence, the total amount of work for the subgraphs induced by the subgraphs at depth i of the tree is reduced to the number of nodes at depth i, which is O(2 i ) and the algorithm can be implemented in time O( It remains to show that an equitable Hamiltonian cycle on at least 12 vertices indeed has two mono-chromatic pairs at distance at least two.

Lemma 3.2. Given a colored graph G consisting of at least 12 vertices, any equitable Hamiltonian cycle contains at least two mono-chromatic pairs that have at least two edges in between.
Proof.Consider an equitable Hamiltonian cycle in G on at least 12 vertices, say C = (u 1 , u 2 , . . ., u n ) and suppose w.l.o.g. that {u 1 , u 2 } and {u 2 , u 3 } form a mono-chromatic pair.If no such mono-chromatic pair exists, then C cannot be an equitable cycle.Consider the path P = (u 5 , . . ., u n−1 ) and suppose it does not contain a mono-chromatic pair.Then P needs to alternate colors and all even edges in this path are colored, say, red and all odd edges are colored blue.Then, we know that r(M E ∩ P) = (n − 6)/2 ≥ 3 and r(M O ∩ P) = 0. C \ P consists of 3 even edges and 3 odd edges of which {u 1 , u 2 } has the same color as {u 2 , u 3 } but different parity.Therefore, we know that the number of red odd edges in C \ P is at most 2 more than the number of red even edges in C \ P. Hence, r(M E ) − r(M O ) ≥ 3 − 2 = 1 and the cycle C cannot be equitable.Hence, in any equitable cycle containing a mono-chromatic pair P 1 = ({u 1 , u 2 }, {u 2 , u 3 }), the path P = (u 5 , . . ., u n−1 ) needs to contain at least one (other) mono-chromatic pair.As, on the cycle C , it takes two edges to go from u 3 to u 5 , and also two edges to go from u 1 to u n−1 , each equitable cycle C needs to contain two mono-chromatic pairs that have at least two edges in between.□ Remark.Consider the EquiTSP (see Kinable et al. [11]), where, given a complete graph with an even number of vertices, instead of a color, there is a distance associated with each edge.The problem is to find a tour, i.e., a Hamiltonian cycle such that the difference between the costs of the two perfect matchings making up the tour, is minimal.We denote by EquiTSPab the special case of EquiTSP where all distances are in {a, b} (a < b).

Corollary 3.3. Algorithm 1 finds a zero-cost solution for EquiTSPab in O(n) time (n ≥ 6).
Proof.Since each perfect matching consists of n 2 edges, it follows that a zero-cost solution of EquiTSPab must correspond to an equitable Hamiltonian cycle (where the edges with distance a (b) are the blue (red) edges).□

About 2-OPT
One might wonder whether a simple local search algorithm can be an alternative to the method described in the previous section.More concretely, we consider the well-known 2-OPT neighborhood: given some Hamiltonian cycle C , its neighborhood consists of all Hamiltonian cycles that share n − 2 edges with C .Note that if we delete two even edges, the new edges are even and the odd matching stays the same; a similar observation holds if we delete two odd edges.However, if we delete one even and one odd edge, then some edges will change parity.
It is a valid question to ask whether the local search algorithm based on the 2-OPT neighborhood finds an equitable Hamiltonian cycle.The answer to this question is ''no''; Fig. 12 shows a graph where the Hamiltonian cycle {(1, 2), (2, 3), (3,4), (4,5), (5,6), (6, 1)} is in fact locally optimal, yet it is not equitable.However, we show that a local optimum, i.e., a Hamiltonian cycle C whose 2-OPT neighborhood does not contain solutions decreasing |r(M E (C )) − r(M O (C ))|, is guaranteed to have a difference of at most 1.Notice that the phrase ''local optimum'' stands for a Hamiltonian cycle found by the local search algorithm using the 2-OPT neighborhood.
We record this observation in a theorem:  Proof.We prove this theorem by contradiction.Assume that there exists a local optimum Thus, the even matching M E (C ) contains at least 2 more red edges than the odd matching M O (C ).
We can partition C into maximal paths of the same color.As the even matching has at least 2 more red edges than the odd matching, we know that there need to exist at least two maximal paths of red edges that start and end with an even edge, say paths P 1 and P 2 .Let {b, c} be the first edge of P 1 and {e, f } be the first edge of P 2 , where we choose an arbitrary but fixed direction on the cycle C to properly define ''first edge''.Then the edges {a, b} and {d, e} of the cycle C need to be odd blue edges, see Fig. 13.
As C is a local optimum, we know that the solution obtained by replacing the odd edges {a, b} and {d, e} by {a, d} and {b, e} will not decrease r(M E ) − r(M O ).As both {a, b} and {d, e} are blue, it follows that also {a, d} and {b, e} are blue.On the other hand, the fact that C is a local optimum implies that when exchanging the red even edges {b, c} and {e, f } by {c, f } and {b, e} respectively, these latter edges need to be red.Hence, we have found a contradiction as {b, e} cannot be simultaneously blue and red.□ Referring back to the remark at the end of Section 2, we state the following corollary.

Concluding remarks
This note shows that the only edge-colored clique that does not contain an equitable Hamiltonian cycle is one on four vertices; all other graphs contain at least one equitable Hamiltonian cycle.
A number of follow-up questions are interesting.First, one may consider complete graphs with an even number of vertices, where each edge is colored with one of three (or one of k) colors.Then, by redefining the concept of an equitable Hamiltonian cycle as one where the number of edges of each color present in the two perfect matchings making up the tour, is the same, leads to similar existence questions as the one we settled here for two colors.
Second, another question deals with (estimating) the number of equitable Hamiltonian cycles.As each equitable cycle on at least 12 vertices contains two mono-chromatic pairs, there are at least four different ways to merge two equitable cycles on at least 12 vertices.As each merger creates its own unique set of newly added edges, a colored graph contains at least O(4 n/12 ) different equitable Hamiltonian cycles.
Finally, we mention a question that asks how many edges can be deleted from a colored graph so that it still contains an equitable Hamiltonian cycle.It is not difficult to see that if one is allowed to delete n − 3 edges, there exist colorings of the edges such that no equitable cycle exists (indeed, this situation arises when we remove all edges incident to a vertex except two, one of which is colored blue while all other edges are colored red).

Definition 1 . 1 .
Given is a colored graph G.A Hamiltonian cycle C in G is called equitable if C can be decomposed into two perfect matchings M E and M O with r(M E ) = r(M O ).If the colored graph G contains an equitable Hamiltonian cycle, we call the colored graph G nice.

Fig. 1 .Fig. 2 .
Fig. 1.A colored graph.(For interpretation of the references to color in this figure legend, the reader is referred to the web version of this article.)

Fig. 3 .
Fig. 3.A box. (For interpretation of the references to color in this figure legend, the reader is referred to the web version of this article.)

Fig. 4 .Fig. 5 .Fig. 6 .Fig. 7 .Fig. 8 .
Fig. 4. The three base cases.(For interpretation of the references to color in this figure legend, the reader is referred to the web version of this article.)

Fig. 9 .Fig. 10 .Fig. 11 .
Fig. 9. Case B.2: blue diagonal.(For interpretation of the references to color in this figure legend, the reader is referred to the web version of this article.)

Fig. 13 .
Fig. 13.Representation of a cycle with r(M E ) > r(M O ) + 1. (For interpretation of the references to color in this figure legend, the reader is referred to the web version of this article.)

Corollary 4 . 2 . 2 -
OPT is an additive approximation algorithm finding a solution to EquiTSPab with cost bounded by b − a.
Given is a colored graph G.If n ∈ {6, 8, 10}, we find an equitable Hamiltonian cycle in G by enumeration.In Appendix A we argue that such an equitable Hamiltonian cycle indeed exists.Otherwise, when n ≥ 12, we partition the graph into two subgraphs of (almost) equal size, and we recursively merge the two equitable Hamiltonian cycles in each of these subgraphs into a single equitable Hamiltonian cycle in G.A formal description of this recursive procedure is given in Algorithm 1, where G[U] denotes the colored subgraph of G induced by vertex set U ⊆ V .
no pair of edges from P u × P v form a box, cycles C 1 and C 2 can be merged into an equitable Hamiltonian cycle in G.Proof.Recall that we denote the two mono-chromatic pairs by {{u 1