For given graphs and the anti-Ramsey number is defined to be the maximum number such that there exists an assignment of colors to the edges of in which every copy of in has at least two edges with the same color. Classically, the graph is a large complete graph or complete bipartite graph and the graph is from a particular graph class.
The study of anti-Ramsey numbers was initiated by Erdös, Simonovits and Sós in 1975 . Since then, there is a large number of papers on the topic. There are papers that study the case when and is a: cycle, e.g., [10, 28, 5, 24], e.g., tree [23, 22], e.g., clique [14, 10, 6], e.g., matching [31, 8, 17, 26] and others, e.g., [10, 21, 4].
The anti-Ramsey numbers are connected with the rainbow number  which is defined as the minimum number such that in any coloring of the edges of with colors, there exists a rainbow copy of . Thus, . We call a coloring without rainbow copy of , a -free coloring.
Various combinatorial work studied the case when is a path or a cycle, for instance the work of Simonovits and Sos  shows that there exists a constant such that for sufficiently long path , the cominatorial analysis of the problem is extermly difficult when instead of we use an arbitrary graph as the host graph. For a more detailed exposition of the combinatorial results on anti-Ramsey numbers, we refer the reader to the following surveys: [32, 15].
Besides the extremal results, the anti-Ramsey numbers have been studied from the computational point of view in several papers. The anti-Ramsey numbers when is an arbitrary graph was studied for the case when is a star. The problem was introduced by Feng et al. [12, 11, 13], motivated by applications in wireless mesh networks and was termed the maximum edge -coloring. The maximum edge -coloring models interference in a new type of wireless mesh network where each computer has interface cards. Thus, the nodes of the graph correspond to computers, the edges with the communication links and the colors with the frequencies on which two computers communicate (see more details in [12, 11, 13]).
They provide a -approximation algorithm for and a -approximation for . They show that the problem is solvable in polynomial time for trees and complete graphs in the case , later, Adamaszek and Popa  show that the problem is APX-hard and present a -approximation algorithm for graphs which have a perfect matching. For more results related to the maximum edge -coloring, the reader can refer to .
We study the complexity of the problem on paths. In , Bujtas et al. study a similar problem to -free coloring. They named it the 3-consecutive edge coloring of a graph. In this problem we are required to color the edges of the graph with the largest number of colors such that for any three consecutive edges (i.e., a path of length or a triangle) it holds that and have the same color or and have the same color. Notice that, although the definitions of two problems seem similar, they are actually different even for a simple case of a triangle. Their problem has a very tight relation to the stable cut problem so they obtained hardness result on deciding whether the -consecutive coloring number of the graph is or . They also provide an algorithm for trees.
Our general goal is to develop the understanding of the anti-Ramsey numbers by focusing on the computational complexity of the problem. It is intriguing that the problem has been studied extensively in the combinatorics community, while in the algorithms community the problem has been considered only recently. Due to its practical applications in networking [29, 30, 12, 11, 13] and its success in combinatorics community, the problem is interesting to study from the computational point of view.
In this paper, we study the problem for the case when is a path and is either an arbitrary graph or a restricted class of graphs such as trees or bipartite graphs. We obtain both algorithmic and hardness of approximation results.
We prove the inapproximability of by factor via a reduction from the maximum independent set problem even on -partite graphs. Our inapproximability holds under the condition —similarly it works under with a slightly worse factor. The key of the reduction is to analyze how do the edges of the graph influence each other. Thus, we also provide a better understanding on the global behavior of the problem.
We show a slight variant of the -free coloring problem, namely, Precolored -free coloring, does not admit an exact algorithm with running time assuming ETH. We obtain this with a fine grained reduction from -SAT. To provide the desirable gadgets and wire them together we introduce some new ideas.
On the positive side, we provide a general algorithmic idea which we call it color connected coloring which for instance yields in linear time algorithm for trees. The known combinatorial results for cycles of length three on outerplanar graphs  and algorithm for trees for consecutive coloring of  are closest works to ours. Our algorithm is completely independent of the latter, however, at the end of Section 5 we will see that the two problems are essentially the same when the host graph is a tree. Color connectedness property combined with some other attributes could lead to the design of exact algorithms with running time , matching the lower bound of general graphs.
The paper is organized as follows. In Section 2 we introduce preliminaries and prove several useful lemmas. Then, we prove the hardness of inapproximability results for -free coloring in Section 3 and in Section 4 we show the exact complexity result for Precolored -free coloring. In Section 5 we show exact polynomial time algorithms for trees and approximation algorithms for some other classes of graphs. Finally, in Section 6 we present directions for future work.
2 Preliminaries and useful lemmas
We use to denote the set of natural numbers and we write to denote the set . We refer the reader to  for basic notions related to graph theory. All the graphs considered in this paper are simple and undirected.
Let be a graph, we write for its vertices and for its edges. For any vertex we define to be the open neighborhood of , and as its closed neighborhood. Similarly for any subset of vertices we define , and . For we denote by a path with vertices. The length of is . Also let be a , depending on the context we may write where or where to describe a path. For two vertices we denote by the length of a shortest path connecting the two. Also, we denote by such a shortest path. We define the distance of two subgraphs of , denoted by , as the minimum where and .
Definition 1 (Coloring).
Given an undirected graph , the coloring of the edges of is a function . Similarly for any subset we define .
We call a coloring of the edges of a graph a rainbow coloring if for every pair of edges we have . Let be two graphs, an edge coloring of is -free coloring if there is no rainbow subgraph of isomorphic to . We denote the number of distinct colors used in by . Let be the set of all -free colorings of . The anti- number of is .
As we already discussed, in this paper we will be focusing on paths and in particular path of length three, thus in the following we present upper bounds on the number of colors when the graph is a path.
In any -free coloring of there are at most distinct colors.
Let be a -free coloring of with maximum number of distinct colors and let be an edge minimal subgraph of which is colored by distinct colors w.r.t. and let be the components of . Each , , is rainbow colored otherwise it contradicts to the edge minimality condition of our choice of .
We prove that the number of edges in each is at most and thus, the lemma follows. In particular, we prove that for all , it holds that is either a star or a triangle.
Fix and let be a vertex of maximum degree in . Let be neighbors of . If then is a star.
If , then is a star, otherwise there exists an edge or . Assume w.l.o.g. that . If , it’s a triangle. Otherwise we have path of length : .
If , then is star. Otherwise, there are two possibilities: a) there is an edge () and we have (for ); or b) there is an edge () and we have a (for ).
If is a star then . If is a triangle then .
Thus, the lemma follows.
The following lemma is the generalization of the previous lemma with a slightly weaker upperbound.
Similar to the previous lemma let be a -free coloring of with the maximum number of colors, we take the maximum size set of edges of distinct colors w.r.t. . The resulting graph has no as a subgraph and hence it does not have any as a minor so by Mader’s theorem [27, 9] it does have at most edges where . ∎
Note that the proof of above lemma does not work for arbitrary . For instance, if a graph does not have a cycle of length (), then it might have a minor of and hence we cannot apply Mader’s theorem.
Next lemma shows that if is part of the input, then the problem of computing is at least as hard as finding a Hamiltonian path in the graph.
Let and be a graph then computing is NP-hard.
For a graph with vertices and edges let suppose . Then if and only if does not have a Hamiltonian Path. Thus, if we can compute the in polynomial time, then we can solve the Hamiltonian Path in polynomial time. ∎
In the classical complexity setting the goal is to group the problems in broad classes such as polynomial, NP-hard, FPT and so on. In the fine-grained complexity our goal is to do a more precise classification of algorithms according to their running times. One of the main tools to prove hardness results in this setting is the Exponential Time Hypothesis (ETH) introduced by Impagliazzo and Paturi . The ETH states that there exists such that there is no algorithm that solves 3-SAT in .
3 Inapproximability of Anti-Ramesy Coloring
In this section we show that for every there is no polynomial time -approximation for -free coloring unless , or similarly there is no polynomial
-approximation to estimateunless . We prove our hardness result via a gap preserving reduction from the maximum independent set problem.
Given an instance of the maximum independent set, i.e. an undirected graph , we construct a graph as follows:
For each we introduce two new vertices and internally disjoint paths of length , , connecting to .
For each edge , add new edges in : , . We call this set of edges .
We abuse a notation and say an edge coloring is valid if it is a -free coloring. We start by providing some lemmas and observations on the structure of valid colorings of .
In any -free coloring of the set of edges will receive at most distinct colors.
The subgraph of induced on endpoints of edges in has exactly edges hence lemma follows from Lemma 2. ∎
If is a cycle of length then .
There is not any valid coloring of with more than colors in one for .
For the sake of contradiction suppose there is a valid coloring of so that is colored with more than colors. At least one has two edges with distinct colors and . By Observation 6 all other edges in should be colored either with or contradicting that has colors. ∎
Let . In any -free coloring of if there are at least distinct colors in then is colored with at most colors.
Firstly, we claim that if is colored by at least distinct colors then and are incident to three edges with distinct colors. Assume the contrary, then w.l.o.g. is incident to two edges of distinct colors and then there is an edge incident to with . Then, it holds that as otherwise we get a rainbow colored path , similarly . Then consider an edge . We show that and thus we obtain a contradiction.
Assume that we have . Then if (or ) the path (or ) is a rainbow colored path, hence thus there are edges of distinct colors incident to and follows there are at least edges of distinct colors incident to .
Now suppose has at least distinct colors then similarly both of its ends () are incident to edges of distinct colors but those edges with edge (or ) and edges of distinct colors incident to will result in a rainbow path of length . ∎
For each , there is a valid coloring so that colored with distinct colors.
. Assign color to the edges of for . This is a valid coloring as any contains one of the ’s. ∎
Let be a maximum independent set of .
For color with different colors and all other edges of with the same color . By Observation 9 there is no rainbow colored in for all and all other ’s have at least edges with color or they contain exactly one of the ’s. ∎
Unless , for any fixed , there is no polynomial time -approximation for -free coloring even in -partite graphs.
First of all note that the graph constructed above is a -partite graph: put every for in part , every in part and every other vertex in part . We provide a gap preserving reduction from independent set problem. More precisely we know there is no polynomial time -approximation for MIS for any fixed  unless . We show that if there is a -approximation for -free coloring (for any constant ) then there is a -approximation for MIS in polynomial time.
The graph has vertices. Hence , so we prove there is no approximation of unless there is such an approximation for MIS in .
In the rest of proof we show . Before completing the proof note that given the coloring, it is easy to obtain the set in polynomial time. Hence, proving this claim implies that we find a large independent set , contradicting the known inapproximability of the independent set problem in general graphs. So the size of set is less than for any , hence the number of colors used in a coloring cannot be in for any constant .
To aim contradiction assume . We calculate the maximum number of colors and prove that it is less than (a contradiction). By Observation 7 we have at most colors for ’s in , colors for other s and for the remaining edges by Lemma 5. So we have:
4 Precoloring has no subexponential algorithm already for
In this section we study the complexity of exact algorithms computing the anti-Ramsey number where is a path with edges. For any connected graph is always as we cannot color two consecutive edges of with different colors. We now consider a variant of problem for exact time complexity of the problem.
Problem 12 (Precolored ).
The input consists of a graph where . The edges in have assigned a color while the edges in are uncolored. The goal is to color the edges in with as many colors as possible such that there is no rainbow copy of in .
In the following we provide a fine grained reduction from 3SAT to show hardness of the problem. That is we provide an instance of Precolored problem, i.e., a graph where some of the edges are precolored, that asymptotically has a same size as the instance of the problem, hence if there is a algorithm to compute precolored then there is a subexponential algorithm to solve 3SAT problem and this is impossible unless ETH fails.
The Precolored is NP-hard.
We show the hardness using a reduction from the 3-SAT problem. Given a Boolean formula with variables and clauses, we create a graph as follows. To simplify the understanding we abuse a notation and color some edges with colors or —one may assume are two distinct integers.
For each variable we create two vertices in , namely and as corresponding literals of . Moreover, we add the edge and we do not precolor it. In the next step we construct clause gadgets and connect them to the literal gadgets.
For a clause we distinguish two cases:
Either all literals are negated variables, or all are non-negated. In this case, we add vertices and we add edges which are not precolored. Then we add edges , which are precolored with , if ’s are non-negated variables or with if ’s are negated variables.
Two of the literals are either non-negated or negated. Assume without loss of generality that and are both variables or both negations of variables. Then we add vertices and we add edges which are not precolored. Then we add edges . The edge is precolored with , if is a positive instance of a variable and it is precolored with if is the negation of a variable.
See Figure 1 for sketch of construction of the gadgets.
W.l.o.g., we assume that for every both variable and its negation appear in some clauses as literals. Otherwise, if a variable appears only negated or non-negated, we can simply satisfy all the clauses that contain that variable. The above assumption enforces any valid coloring to color by either or .
We claim that the formula is satisfiable if and only if , that is there is a coloring of the edges of with colors (, and another new colors, one for each clause).
For the direct implication, if the formula is satisfiable we color the edges of as follows. For each variable , if is assigned to True, then we color the edge with , otherwise we color this edge with .
Let . Assume without loss of generality that is satisfied by the literal . Then we color the edge with a new color (or the edge ). Then, if corresponds to a negation of a variable, we color all the other edges in the clause gadget with . Otherwise, we color all the other edges with .
Now we show that the coloring is valid. We have two cases:
All the literals in a clause are either negated variables or non-negated variables. Assume w.l.o.g., that is satisfied by . Then since and have the same color, then any containing is not rainbow. Thus, the only path that we have to check is . This path is not rainbow since the edge , has the same color as the edge .
Two of the literals in a clause are false and the other is true, or vice-versa. The same argument as in the previous case holds. We distinguish two cases. First, assume that the clause is satisfied by the literal that is different from the other two, i.e. . Observe that the color of the edge is the same as the color of the edges and . Thus, all the paths containing and are not rainbow. The only path in the clause gadget left to check is , which is not rainbow since from our assignment has the same color as .
In the second case, the clause is satisfied by or . Assume, w.l.o.g., that satisfies the clause and that is not the negation of a variable. Then, similarly as in the previous case, observe that the color of the edge is the same as the color of the edges and . Thus, all the paths containing and are not rainbow. The only two paths in the clause gadget left to check is and , which are not rainbow since from our assignment has the same color as and .
For the reverse implication, assume that we are given a coloring of with colors. We show how to recover a satisfying assignment for . First of all, notice that in a clause gadget we can add at most one new color. Assume, for the sake of contradiction that there are two edges from a clause gadget that have two distinct new colors. If these two edges are incident, then they form a rainbow path with another incident edge since the edges have either color or . If these two edges are not incident (e.g., , ) then either the edge incident between them has a different color as well, and thus we have a rainbow path, or the edges between them has one of the two new colors and then, we have the contradiction form the previous case.
Thus, we achieve the satisfying assignment as follows. If the edge is set to then we set to True, otherwise we set to False.
Finally, we show that this is a satisfying assignment for . We have two cases:
If or is the edge colored with the new color. Then the color of is equal to the color of , since otherwise we would have a rainbow path. However, this implies that satisfies .
The edge is colored with the new color. Assume by contradiction that the clause is not satisfied. Then are colored with the same color as , respectively (otherwise we have a rainbow path). However, since has a different color than (this is how the clause was constructed), then is a rainbow path, leading to a contradiction.
Given the above lemma and sparsification lemma we conclude the following theorem.
There is no algorithm for Precolored unless ETH fails.
We may assume the 3SAT instance used in the construction of the graph in the proof of Lemma 13 is sparse, that is the number of clauses is in order of number of variables , i.e. . Thus by sparsification lemma  there is no algorithm to solve Precolored (unless ETH fails).
On the other hand in the construction of the graph for each variable we have one edge and for each clause we have at most edges so in total the number of edges in the graph is bounded above by hence therefore there is no algorithm for Precolored unless ETH fails. ∎
5 Color Connected Coloring and its Applications
In this section, we introduce an idea of color connected coloring and using that we provide a polynomial time algorithm to compute , where is a tree. Roughly speaking in color connected coloring we try to color the graph with the maximum number of colors so that the set of edges of every color class induces a connected subgraph.
Our proof implicitly shows that the algorithm works for -consecutive coloring as well and more generally it shows that anti-Ramsey coloring and -consecutive coloring are essentially the same when the host graph is a tree. Algorithm of  is based on the observation that they have to find a stable separator that maximizes the number of remaining components. However, we need more ideas to arrive at that point.
Definition 15 (rainbow and monochrome vertices).
Let be a graph with coloring . Vertex is monochrome if all the edges incident to have the same color, i.e. . Vertex is rainbow if edges incident to have distinct colors, i.e. .
Definition 16 (, ).
Let be a rooted tree and . We define as the maximum number of colors in the subtree rooted at if is monochrome. Similarly let be the maximum number of colors in the subtree rooted at if is rainbow.
Let be a rooted tree. Algorithm 1 computes in .
Before proving Theorem 17 we introduce the main idea we use in this section and we need some definitions and lemmas to take advantage of it.
Let be a -free coloring of a graph and let be one of such colors used in . Then we call the induced graph as an induced -graph and we write it . If is a connected component then we say is a connected color otherwise it is a disjoint color.
Definition 18 (Color Connected Coloring).
Given a graph , a -free coloring of is color connected coloring if every color used in is a connected color. A graph is color connected if there is a color connected coloring of with many distinct colors.
There is a -free coloring of with distinct colors so that for every color of the graph is a connected graph.
Let be a -free coloring of with colors and minimum number of disjoint colors. If there is no disjoint color used in we are done, otherwise towards the contradiction let suppose for a color of , for some . W.l.o.g. suppose is the first component of one visits by preorder traversal of starting at its root. Then as is rooted we know that for the root of every subtree has a parent and hence there is a parental edge and in addition to that we know . We recolor every component with a color for . This clearly creates a new coloring with the exact same set of colors used in however it has one less disjoint color contradicting to our assumption on so to complete the contradiction it is sufficient to show is a -free coloring.
Suppose is not a -free coloring and let be a rainbow . Since was a -free coloring and we only recolored colored edges, there are three cases:
. and are in the same component, therefore, after our update , a contradiction.
. It is similar to the previous case.
. So and are in different components w.r.t. color classes, and is incident to both of them, hence should be the parental edge for one of them, therefore, we have either or , a contradiction.
Hence there is no rainbow with the new coloring scheme and the lemma follows. ∎
Let be a tree and . Let be a color connected -free coloring of . Then at least one of is monochrome.
Proof is by contradiction. Assume that there is an edge where none of its endpoints are monochrome. There is a and a such that . Since is a color connected coloring which immediately yields a rainbow , a contradiction. ∎
Let be a tree. There is a color connected -free coloring of with colors such that for every vertex , is either rainbow or monochrome .
By Lemma 19 there exists a color connected coloring with distinct colors. We show that any is rainbow or monochrome. For the sake of contradiction assume is a vertex with such that and for simplicity assume that is the root of . We show that we can use an extra color contradicting the optimality of . By Lemma 20 all the children of , e.g. , are monochrome. Let be a new color. Recolor and every edge in subtree of with . It is enough to show that is still a -free coloring. Let be a rainbow . Since we recolored the subtree of , should contain edges from this subtree. There are two cases:
is completely in subtree of . In this case switching back the colored edges to color again leaves us with a rainbow , a contradiction.
Otherwise there are two subcases:
. Then and is monochrome, hence .
. Similarly and is monochrome, thus .
Therefore the new coloring is -free. Hence, was not an optimum coloring. ∎
Now we are ready to prove Theorem 17.
According to Lemma 21 there is an optimum -free coloring of so that each vertex is either monochrome or rainbow. Algorithm 1 uses a dynamic programming approach to solve the problem for those two roles, in the subtree rooted at vertex . Afterward the appropriate choice for vertex can be decided when the algorithm is solving subtree of .
If is rainbow then all of its children should be monochrome with color thus:
If is monochrome then its children can be either monochrome or rainbow, hence they pick the one that maximizes the number of colors.
And finally the answer for tree rooted at is .
To show that the algorithm produces a -free coloring it is enough to show that in each step the edges of are not part of a rainbow in the subtree which is rooted at . Let be an arbitrary starting from and going down in the tree (getting far from the root).
is monochrome. Then where is the set of monochrome children of and is the set of rainbow children. Then we have two cases:
. Then .
. Then is monochrome, hence .
is rainbow. Then for all , is monochrome, hence .
Therefore is also a -free coloring. ∎
5.1 Bounded Degree and Bipartite Graphs
We end the section by providing a simple constant factor approximation algorithm on bounded degree graphs and a more refined version for bounded degree bipartite graphs. Note that the independent set problem remains hard in bounded degree graphs  so the reduction of previous sections still proves the hardness of the problem on bounded degree graphs. Recall that the problem is hard on -partite graphs, however, we do not know how hard it is on bipartite graphs. In this section we concentrate on -free coloring, hence, we simply write valid coloring for such a coloring.
Let be the maximum degree of a graph. For bounded degree graphs a greedy choice will provide a constant factor approximation to the optimum solution i.e. we have the following lemma.
There is a -approximation for -free coloring.
We color the graph iteratively. In round , choose an uncolored edge . Let be the set of paths of length at most intersecting either or . We color with and color every other edges in paths of with . In each iteration we colored at most edges and we used at least one new color, note that we may color an edge of color multiple times, but once an edge gets a color other than it never changes to any other color. We may suppose there are at least edges in the graph. So we colored the graph with at least distinct colors. ∎
Let be a bipartite graph with parts and and denoting the edges of the graph. Also for the rest of this section assume that . The proof of the following is similar to Proposition 18 of .
There is a -approximation for -free coloring in bipartite graphs.
First observe that there is a -free coloring of with distinct colors. Just color all edges incident to with color for . Then by considering the lemma is a direct consequence of Lemma 2 ∎
Observe that the above observation helps to provide a better approximation on bounded degree bipartite graphs, for instance in grid graphs (subgraph of infinite grid) it is easy to obtain a -approximation in linear time.
Let be a bipartite graph of maximum degree , then the algorithm of Lemma 23 is a approximation for -free coloring.
Let be the optimal coloring on and be an edge maximal subgraph of disjoint union of edges of such that each of them colored with a distinct color. is bipartite then is a set of disjoint stars and the largest star