1 Introduction

A proper \(k\) -coloring (or \(k\) -coloring) of a graph \(G\) is an assignment of \(k\) different colors to the vertices of \(G\), such that no two adjacent vertices receive the same color. That is, a \(k\)-coloring is a partition of the vertices of \(G\) into \(k\) independent sets. The corresponding \(k\) -coloring problem is the problem of deciding whether a given graph \(G\) admits a \(k\)-coloring of its vertices, and to compute one if it exists. Furthermore, the minimum number \(k\) of colors for which there exists a \(k\)-coloring is denoted by \(\chi (G)\) and is termed the chromatic number of \(G\). The minimum coloring problem is to compute the chromatic number of a given graph \(G\), and to compute a \(\chi (G)\)-coloring of \(G\).

One of the most well known complexity results is that the \(k\)-coloring problem is NP-complete for every \(k\ge 3\), while it can be solved in linear time for \(k=2\) [12]. Therefore, since graph coloring has numerous applications besides its theoretical interest, there has been a considerable interest in studying how several graph parameters affect the tractability of the \(k\)-coloring problem, where \(k\ge 3\). In view of this, the complexity status of the coloring problem has been established for many graph classes.

It has been proved that \(3\)-coloring remains NP-complete even when the input graph is restricted to be a line graph [15], a triangle-free graph with maximum degree \(4\) [20], or a planar graph with maximum degree \(4\) [12]. On the positive side, one of the most famous result in this context has been that the minimum coloring problem can be solved in polynomial time for perfect graphs using the ellipsoid method [13]. Furthermore, polynomial algorithms for \(3\)-coloring have been also presented for classes of non-perfect graphs, such as \(P_{6}\)-free graphs [24] and AT-free graphs [25]. Here, a graph \(G\) is a \(P_{6}\)-free graph if \(G\) does not contain any path on \(6\) vertices as an induced subgraph. Furthermore, a graph \(G\) is an AT-free graph if \(G\) does not contain any asteroidal triple, i.e. three vertices where every two of them are connected by a path avoiding the neighborhood of the third one. Although the minimum coloring problem is NP-complete on \(P_{5}\)-free graphs, the \(k\)-coloring problem is polynomial on these graphs for every fixed \(k\) [14]. Courcelle’s celebrated theorem states that every problem definable in Monadic Second-Order logic (MSO) can be solved in linear time on graphs with bounded treewidth [9], and thus also the coloring problem can be solved in linear time on such graphs.

For the cases where \(3\)-coloring is NP-complete, considerable attention has been given to devising exact algorithms that are faster than the brute-force algorithm (see e.g. the recent book [11]). In this context, asymptotic lower bounds of the time complexity have been provided for the main NP-complete problems, based on the Exponential Time Hypothesis (ETH) [16, 17]. ETH states that there exists no deterministic algorithm that solves the \(3\)SAT problem in time \(2^{o(n)}\), given a boolean formula with \(n\) variables. In particular, assuming ETH, \(3\)-coloring cannot be solved in time \(2^{o(n)}\) on graphs with \(n\) vertices, even when the input is restricted to graphs with diameter \(4\) and radius \(2\) (see [19, 22]). Therefore, since it is assumed that no subexponential \(2^{o(n)}\) time algorithms exist for \(3\)-coloring, most attention has been given to decreasing the multiplicative factor of \(n\) in the exponent of the running time of exact exponential algorithms, see e.g. [5, 11, 21]. For a more detailed discussion about ETH we refer to Sect. 2.

One of the most central notions in a graph is the distance between two vertices, which is the basis of the definition of other important parameters, such as the diameter, the eccentricity, and the radius of a graph. For these graph parameters, it is known that \(3\)-coloring is NP-complete on graphs with diameter at most \(4\) (see e.g. the standard proof of [22]). Furthermore, it is straightforward to check that \(k\)-coloring is NP-complete for graphs with diameter at most \(2\), for every \(k\ge 4\): we can reduce \(3\)-coloring on arbitrary graphs to \(4\)-coloring on graphs with diameter \(2\), just by introducing to an arbitrary graph a new vertex that is adjacent to all others.

In contrast, in spite of extensive studies of the \(3\)-coloring problem with respect to several basic parameters, the complexity status of this problem on graphs with small diameter, i.e. with diameter at most \(2\) or at most \(3\), has been an open problem, see e.g.  [6, 8, 18]. The complexity status of \(3\)-coloring is open also for triangle-free graphs of diameter \(2\) and of diameter \(3\). It is worthwhile mentioning here that a graph is triangle-free and of diameter \(2\) if and only if it is a maximal triangle free graph. Moreover, it is known that \(3\)-coloring is NP-complete for triangle-free graphs [20], however it is not known whether this reduction can be extended to maximal triangle free graphs. Another interesting result is that almost all graphs have diameter \(2\) [7]; however, this result cannot be used in order to establish the complexity of \(3\)-coloring for graphs with diameter \(2\).

Our Contribution In this paper we provide subexponential algorithms and hardness results for the \(3\)-coloring problem on graphs with low diameter, i.e. with diameter \(2\) and \(3\). As a preprocessing step, we first present two reduction rules that we apply to an arbitrary graph \(G\) such that the resulting graph \(G^{\prime }\) is \(3\)-colorable if and only \(G\) is \(3\)-colorable. We use these reduction rules to reduce the size of the given graph and to simplify the algorithms that we present. Whenever these two reduction rules cannot be applied to a graph, we call this graph irreducible; for a detailed discussion we refer to Sect. 2.

For graphs with diameter at most \(2\), we first provide a subexponential algorithm for \(3\)-coloring with running time \({2^{O\left( \min \{\delta ,\frac{n}{ \delta }\log \delta \}\right) }}\), where \(n\) is the number of vertices and \(\delta \) is the minimum degree of the input graph. This algorithm is simple and has worst-case running time \(2^{O(\sqrt{n\log n})}\). To the best of our knowledge, this is the first subexponential algorithm for graphs with diameter \(2\). We demonstrate that this is indeed the worst-case of our algorithm by providing, for every \(n\ge 1\), a \(3\)-colorable graph \(G_{n}=(V_{n},E_{n})\) with \(\varTheta (n)\) vertices, such that \(G_{n}\) has diameter \(2\) and both its minimum degree and the size of a minimum dominating set is \(\varTheta (\sqrt{n})\). In addition, this graph is triangle-free and irreducible with respect to the above two reduction rules. Furthermore we define the notion of an articulation neighborhood in a graph, which extends the notion of an articulation vertex. For any vertex \(v\) of a graph \(G\), the closed neighborhood \(N[v] = N(v) \cup \{v\}\) is an articulation neighborhood if \(G-N[v]\) is disconnected. We present a polynomial algorithm for \(3\)-coloring irreducible graphs \(G\) with diameter \(2\) having at least one articulation neighborhood.

For graphs with diameter at most \(3\), we establish the complexity of deciding \(3\)-coloring, even for the case of triangle-free graphs. Namely we prove that \(3\)-coloring is NP-complete on irreducible and triangle-free graphs with diameter \(3\) and radius \(2\), by providing a reduction from 3SAT. In addition, we provide a \(3\)-coloring algorithm with running time \({ 2^{O\left( \min \{\delta \varDelta ,\ \frac{n}{\delta }\log \delta \}\right) }}\) for arbitrary graphs with diameter \(3\), where \(n\) is the number of vertices and \( \delta \) (resp. \(\varDelta \)) is the minimum (resp. maximum) degree of the input graph. To the best of our knowledge, this algorithm is the first subexponential algorithm for graphs with \({\delta =\omega (1)}\) and for graphs with \({\delta =O(1)}\) and \({\varDelta =o(n)}\). Table 1 summarizes the current state of the art of the complexity of \(k\)-coloring, as well as our algorithmic and NP-completeness results.

Table 1 Current state of the art and our algorithmic and NP-completeness results for \(k\)-coloring on graphs with diameter \(diam(G)\)

Furthermore, we provide three different amplification techniques that extend our hardness results for graphs with diameter \(3\). In particular, we first show that \(3\)-coloring is NP-complete on irreducible and triangle-free graphs \(G\) of diameter \(3\) and radius \(2\) with \(n\) vertices and minimum degree \(\delta (G)=\varTheta (n^{\varepsilon })\), for every \(\varepsilon \in [\frac{1}{2},1)\) and that, for such graphs, there exists no algorithm for \(3\)-coloring with running time \({2^{o\left( \frac{n}{\delta } \right) }=2^{o\left( n^{1-\varepsilon }\right) }}\), assuming ETH. This lower bound is asymptotically almost tight, due to our above algorithm with running time \({ 2^{O\left( \frac{n}{\delta }\log \delta \right) }}\), which is subexponential when \(\delta (G)=\varTheta (n^{\varepsilon })\) for some \(\varepsilon \in [\frac{1}{2} ,1)\). With our second amplification technique, we show that \(3\)-coloring remains NP-complete also on irreducible and triangle-free graphs \(G\) of diameter \(3\) and radius \(2\) with \(n\) vertices and minimum degree \({\delta (G)=\varTheta (n^{\varepsilon })}\), for every \(\varepsilon \in [0,\frac{1 }{2})\). Moreover, we prove that for such graphs, when \({\varepsilon \in [0,\frac{1}{3})}\), there exists no algorithm for \(3\)-coloring with running time \({2^{o\left( \sqrt{\frac{n}{\delta }}\right) }=2^{o\big (n^{\left( \frac{ 1-\varepsilon }{2}\right) }\big )}}\), assuming ETH. Finally, with our third amplification technique, we prove that for such graphs, when \({\varepsilon \in [\frac{1}{3},\frac{1}{2})}\), there exists no algorithm for \(3\)-coloring with running time \({2^{o(\delta )}=2^{o\left( n^{\varepsilon }\right) }}\), assuming ETH. Table 2 summarizes our time complexity lower bounds for \(3\)-coloring on irreducible and triangle-free graphs with diameter \(3\) and radius \(2\), parameterized by their minimum degree \(\delta \).

We note here that the way we use the term “parameterized by” should not be confused with the way this term is being used in the context of parameterized complexity (such as in FPT algorithms). In this paper we use the term “parameterized by” in the sense that our upper and lower bounds are given as a function of several parameters of the graph, such as the minimum degree \(\delta \), or the maximum degree \(\varDelta \).

Table 2 Summary of the results of Theorems 11, 12, and 13

Organization of the Paper We provide in Sect. 2 details about the ETH, as well as the necessary notation and terminology, our two reduction rules, and the notion of an irreducible graph. In Sects. 3 and 4 we present our results for graphs with diameter \(2\) and \(3\), respectively.

2 Preliminaries and Notation

A theorem proving an NP-hardness result for a decision problem does not provide any information about how efficiently (although not polynomially, unless P \(\ne \) NP) this decision problem can be solved. In the context of providing lower bounds for the time complexity of solving NP-complete problems, Impagliazzo, Paturi, and Zane formulated the ETH [17].

Exponential Time Hypothesis (ETH) [17] There exists no algorithm solving \(3\)SAT in time \(2^{o(n)}\), where \(n\) is the number of variables in the input CNF formula.

ETH is a strong hypothesis which might be true or not. In particular, if ETH is true then it immediately follows that P \(\ne \) NP. In addition to formulating ETH, Impagliazzo, Paturi, and Zane also proved the celebrated Sparsification Lemma [17], which has the following theorem as a direct consequence. (This result is quite useful for providing lower bounds assuming ETH, as it parameterizes the running time by the size of the input CNF formula, rather than only the number of its variables.)

Theorem 1

([16]) \(3\)SAT can be solved in time \(2^{o(n)}\) if and only if it can be solved in time \(2^{o(m)}\), where \(n\) is the number of variables and \(m\) is the number of clauses in the input CNF formula.

The following very well known theorem about the \(3\)-coloring problem is based on the fact that there exists a standard polynomial-time reduction from Not-All-Equal-\(3\)-SAT to \(3\)-coloringFootnote 1 [22], in which the constructed graph has diameter \(4\) and radius \(2\), and its number of vertices is linear in the size of the input formula (see also [19]).

Theorem 2

([19, 22]) Assuming ETH, there exists no \(2^{o(n)}\) time algorithm for \(3\)-coloring on graphs \(G\) with diameter \(4\), radius \(2\), and \( n\) vertices.

Notation We consider in this article simple undirected graphs with no loops or multiple edges. In an undirected graph \(G\), the edge between vertices \(u\) and \(v\) is denoted by \(uv\), and in this case \(u\) and \(v\) are said to be adjacent in \(G\). Otherwise \(u\) and \(v\) are called non-adjacent or independent. Given a graph \({G=(V,E)}\) and a vertex \( {u\in V}\), denote by \({N(u)=\{v\in V : uv\in E\}}\) the set of neighbors (or the open neighborhood) of \(u\) and by \({N[u]=N(u)\cup \{u\}}\) the closed neighborhood of \(u\). Whenever the graph \(G\) is not clear from the context, we will write \(N_{G}(u)\) and \(N_{G}[u]\), respectively. Denote by \(\deg (u)=|N(u)|\) the degree of \(u\) in \(G\) and by \(\delta (G)=\min \{\deg (u) : u\in V\}\) the minimum degree of \(G\). Let \(u\) and \(v\) be two non-adjacent vertices of \(G\). Then, \(u\) and \(v\) are called (false) twins if they have the same set of neighbors, i.e. if \(N(u)=N(v)\). Furthermore, we call the vertices \(u\) and \(v\) siblings if \({ N(u)\subseteq N(v)}\) or \({N(v)\subseteq N(u)}\); note that two twins are always siblings.

Given a graph \({G=(V,E)}\) and two vertices \(u,v\in V\), we denote by \(d(u,v)\) the distance of \(u\) and \(v\), i.e. the length of a shortest path between \(u\) and \(v\) in \(G\). Furthermore, we denote by \(diam(G)=\max \{d(u,v) : u,v\in V\}\) the diameter of \(G\) and by \(rad(G)=\min _{u\in V}\{\max \{d(u,v) : v\in V\}\}\) the radius of \(G\). Given a subset \({S\subseteq V}\), \(G[S]\) denotes the subgraph of \(G\) induced by \(S\). We denote for simplicity by \(G-S\) the induced subgraph \(G[V{\setminus } S]\) of \(G\). A subset \(S\subseteq V\) is an independent set in \(G\) if the graph \(G[S]\) has no edges. Furthermore, a subset \(S\subseteq V\) is a clique if the graph \(G[S]\) has all \({\left( {\begin{array}{c}|S|\\ 2\end{array}}\right) }\) possible edges among its vertices. A clique with \(t\) vertices is denoted by \(K_{t}\). A graph \(G\) that contains no \(K_{t}\) as an induced subgraph is called \(K_{t}\) -free. Furthermore, a subset \( D\subseteq V\) is a dominating set of \(G\) if every vertex of \( V{\setminus } D\) has at least one neighbor in \(D\). For simplicity, we refer in the remainder of the article to a proper \(k\)-coloring of a graph \(G\) just as a \(k\) -coloring of \(G\). Throughout the article we perform several times the merging operation of two (or more) independent vertices, which is defined as follows: we merge the independent vertices \(u_{1},u_{2},\ldots ,u_{t}\) when we replace them by a new vertex \(u_{0}\) with \(N(u_{0})=\cup _{i=1}^{t}N(u_{i})\). In addition to the well known big-\(O\) notation for asymptotic complexity, sometimes we use the \(O^{*}\) notation that suppresses polynomially bounded factors. For instance, for functions \(f\) and \(g\), we write \(f(n)=O^{*}(g(n))\) if \( f(n)=O(g(n)\ poly(n))\), where \(poly(n)\) is a polynomial.

In the following we provide two reduction rules that can be applied to an arbitrary graph \(G\). Throughout the article, we assume that any given graph \(G\) of low diameter is irreducible with respect to these two reduction rules, i.e. that these reduction rules have been iteratively applied to \(G\) until they cannot be applied any more. Note that the iterative application of these reduction rules on a graph with \(n\) vertices can be done in time polynomial in \(n\). The correctness of these two reduction rules is almost trivial, therefore they could be considered as folklore. Such reductions are well-known tools in exact exponential and parameterized algorithms.

Observe that, whenever a graph \(G\) contains a clique with four vertices as an induced subgraph, then \(G\) is not \(3\)-colorable. Furthermore, we can check easily in polynomial time (e.g. with brute-force) whether a given graph \(G\) contains a \(K_{4}\). Therefore we assume in the following that all given graphs are \(K_{4}\)-free. Furthermore, since a graph is \(3\)-colorable if and only if all its connected components are \(3\)-colorable, we assume in the following that all given graphs are connected. In order to present our two reduction rules of an arbitrary \(K_{4}\)-free graph \(G\), recall first that the diamond graph is a graph with \(4\) vertices and \( 5\) edges, i.e. it consists of a \(K_{4}\) without one edge. The diamond graph is illustrated in Fig. 1a. Suppose that four vertices \( u_{1},u_{2},u_{3},u_{4} \) of a given graph \(G=(V,E)\) induce a diamond graph, and assume without loss of generality that \({u_{1}u_{2}\notin E}\). Then, it is easy to see that in any \(3\)-coloring of \(G\) (if such exists), \(u_{1}\) and  \(u_{2}\) necessarily obtain the same color. Therefore we can merge \(u_{1}\) and \(u_{2}\) into one vertex, as the next reduction rule states, and the resulting graph is \(3\)-colorable if and only if \(G\) is \(3\)-colorable.

Reduction Rule 1

(diamond elimination) Let \({G=(V,E)}\) be a \(K_{4}\)-free graph. If the quadruple \({ \{u_{1},u_{2},u_{3},u_{4}\}}\) of vertices in \(G\) induces a diamond graph, where \({u_{1}u_{2}\notin E}\), then merge vertices \(u_{1}\) and \(u_{2}\).

Note that, after performing a diamond elimination in a \(K_{4}\)-free graph \(G\), we may introduce a new \(K_{4}\) in the resulting graph. An example of such a graph \(G\) is illustrated in Fig. 1b. In this example, the graph on the left-hand side has no \(K_{4}\) but it has two diamonds, namely on the quadruples \({\{u_{1},u_{2},u_{3},u_{4}\}}\) and \({ \{u_{4},u_{5},u_{6},u_{7}\}}\) of vertices. However, after eliminating the first diamond by merging \(u_{1}\) and \(u_{4}\), we create a new \(K_{4}\) on the quadruple \({\{u_{1},u_{5},u_{6},u_{7}\}}\) of vertices, cf. the graph of the right-hand side of Fig. 1b.

Fig. 1
figure 1

a The diamond graph and b an example of a diamond elimination of a \(K_{4}\)-free graph, which creates a new \(K_{4}\) on the vertices \({ \{u_{1},u_{5},u_{6},u_{7}\}}\) in the resulting graph

Suppose now that a graph \(G\) has a pair of siblings \(u\) and \(v\) and assume without loss of generality that \({N(u)\subseteq N(v)}\). Then, we can extend any proper \(3\)-coloring of \(G-\{u\}\) (if such exists) to a proper \(3\)-coloring of \(G\) by assigning to \(u\) the same color as \(v\). Therefore, we can remove vertex \(u\) from \(G\), as the next reduction rule states, and the resulting graph \(G-\{u\}\) is \(3\)-colorable if and only if \(G\) is \(3\)-colorable.

Reduction Rule 2

(siblings elimination) Let \({G=(V,E)}\) be a \(K_{4}\)-free graph and \({u,v\in V}\), such that \({N(u)\subseteq N(v)}\). Then remove \(u\) from \(G\).

Definition 1

Let \(G=(V,E)\) be a \(K_{4}\)-free graph. If neither Reduction Rule 1 nor Reduction Rule 2 can be applied to \( G\), then \(G\) is irreducible.

Due to Definition 1, a \(K_{4}\)-free graph is irreducible if and only if it is diamond-free and siblings-free. Given a \(K_{4}\)-free graph \(G\) with \(n\) vertices, clearly we can iteratively execute Reduction Rules 1 and 2 in time polynomial in \(n\), until we either find a \(K_{4}\) or none of the Reduction Rules 1 and 2 can be further applied. If we find a \(K_{4}\), then clearly the initial graph \(G\) is not \(3\)-colorable. Otherwise, we transform \(G\) in polynomial time into an irreducible (\(K_{4}\)-free) graph \(G^{\prime }\) of smaller or equal size, such that \(G^{\prime }\) is \(3\)-colorable if and only if \(G\) is \(3\)-colorable.

Observe that during the application of these reduction rules to a graph \(G\), neither the diameter nor the radius of \(G\) increase. Moreover, note that in the irreducible graph \(G^{\prime }\), the neighborhood \(N_{G^{\prime }}(u)\) of every vertex \(u\) in \(G^{\prime }\) induces a graph with maximum degree at most \(1\), since otherwise \(G^{\prime }\) would have a \(K_{4}\) or a diamond as an induced subgraph. That is, the subgraph of \(G^{\prime }\) induced by \( N_{G^{\prime }}(u)\) contains only isolated vertices and isolated edges. Furthermore, if \(G\) (and thus also \(G^{\prime }\)) is connected and if \( G^{\prime }\) has more than two vertices, then the minimum degree of \( G^{\prime }\) is \(\delta (G^{\prime })\ge 2\), since \(G^{\prime }\) is siblings-free. All these facts are summarized in the next observation. In the remainder of the article, we assume that any given graph \(G\) is irreducible.

Observation 1

Let \({G=(V,E)}\) be a connected \(K_{4}\)-free graph and \({ G^{\prime }=(V^{\prime },E^{\prime })}\) be an irreducible graph obtained from \(G\). If \(G^{\prime }\) has more than two vertices, then \({\delta (G^{\prime })\ge 2}\), \({diam(G^{\prime })\le diam(G)}\), \({rad(G^{\prime })\le rad(G)}\), and \({G^{\prime }}\) is \(3\)-colorable if and only if \(G\) is \( 3\)-colorable. Moreover, for every \({u\in V^{\prime }}\), \(N_{G^{\prime }}(u)\) induces in \(G^{\prime }\) a graph with maximum degree \(1\).

3 Algorithms for \(3\)-Coloring on Graphs with Diameter \(2\)

In this section we present our results on graphs with diameter \(2\). In particular, we provide in Sect. 3.1 our subexponential algorithm for \(3\)-coloring on such graphs. We then provide, for every \(n\), an example of an irreducible and triangle-free graph \(G_{n}\) with \(\varTheta (n)\) vertices and diameter \(2\), which is \(3\)-colorable, has minimum dominating set of size \(\varTheta (\sqrt{n})\), and its minimum degree is \(\delta (G_n) = \varTheta (\sqrt{n})\). Furthermore, we define in Sect. 3.2 the notion of an articulation neighborhood, and we provide our polynomial algorithm for irreducible graphs \(G\) with diameter \(2\), which have at least one articulation neighborhood.

3.1 An \(2^{O(\sqrt{n\log n})}\)-Time Algorithm for Any Graph with Diameter \(2\)

We first provide in the next lemma a well known algorithm that decides the \( 3 \)-coloring problem on an arbitrary graph \(G\), using a dominating set (DS) of \(G\) [21]. For completeness we provide a short proof of this lemma.

Lemma 1

([21], the DS-approach) Let \({G=(V,E)}\) be a graph and \( D\subseteq V\) be a dominating set of \(G\). Then, the \(3\)-coloring problem can be decided in \(O^{*}(3^{|D|})\) time on \(G\).

Proof

We iterate over all possible proper \(3\)-colorings of \(D\). There are at most \(3^{|D|}\) such colorings; note that, if there is no proper \(3\)-coloring of \(G[D]\), then clearly \(G\) is not \(3\)-colorable. Fix now a proper \(3\)-coloring of \(G[D]\). If we want to construct a 3-coloring of G that agrees with this precoloring of \(G[D]\), then for every vertex of \(G{\setminus } D\) there will be only two possible colors that this vertex can use in such a coloring (if one exists). Therefore, the question of whether this \(3\)-coloring of \(G[D]\) can be extended to a \(3\)-coloring of \(G\) is a list \(2\)-coloring problem, which can be solved in polynomial time as it can be formulated as a 2SAT instance (a similar approach has been first used in [10], in the context of coloring problems on dense graphs). Therefore, by considering in worst case all possible \(3\)-colorings of the dominating set \(D\), we can decide \(3\)-coloring on \(G\) in time \(O^{*}(3^{|D|})\). \(\square \)

In the next theorem we use Lemma 1 to provide an improved \(3\)-coloring algorithm for the case of graphs with diameter \(2\). The time complexity of this algorithm is parameterized by the minimum degree \(\delta \) of the given graph \(G\), as well as by the fraction \( \frac{n}{\delta }\).

Theorem 3

Let \({G\!=\!(V,E)}\) be an irreducible graph with \(n\) vertices. Let \({diam(G)=2}\) and \({\delta }\) be the minimum degree of \(G\). Then, the \(3\)-coloring problem can be decided in \( {2^{O\left( \min \{\delta , \frac{n}{\delta }\log \delta \}\right) }}\) time on \(G\).

Proof

In an arbitrary graph \(G\) with \(n\) vertices and minimum degree \(\delta \), it is well known how to construct in polynomial time a dominating set \(D\) with cardinality \(|D|\le n\frac{1+\ln (\delta +1)}{\delta +1}\) [2, 3, 23] (see also [1]). Therefore we can decide by Lemma 1 the \(3\)-coloring problem on \(G\) in time \(O^{*}(3^{n\frac{1+\ln (\delta +1)}{\delta +1}})\). Note by Observation 1 that \(\delta \ge 2\), since \(G\) is irreducible by assumption. Therefore the latter running time is \(2^{O\left( \frac{n}{\delta }\log \delta \right) }\).

The DS-approach of Lemma 1 applies to any graph \(G\). However, since \(G\) has diameter \(2\) by assumption, we can design a second algorithm for \(3\)-coloring of \(G\) as follows. Consider a vertex \( u\in V\) with minimum degree, i.e. \(\deg (u)=\delta \). Since \(diam(G)=2\), it follows that for every other vertex \(u\in V\), either \(d(u,v)=1\) or \(d(u,v)=2\). Therefore \(N(u)\) is a dominating set of \(G\) with cardinality \(\delta \). Fix a proper \(3\)-coloring of \(G[N(u)]\). Similarly to the proof of Lemma 1, note that if we want to construct a 3-coloring of G that agrees with this precoloring of \(G[N(u)]\), then for every vertex of \(G{\setminus } N(u)\) there will be only two possible colors that this vertex can use in such a coloring (if one exists). We iterate now for all possible proper \(2\)-colorings of \(G[N(u)]\) (instead of all \(3\)-colorings of the dominating set as in the proof of Lemma 1). There are at most \(2^{\delta }\) such colorings. Similarly to the algorithm of Lemma 1, for every such \(2\)-coloring of \(G[N(u)]\) we solve in polynomial time the corresponding list \(2\)-coloring of \(G-N[u]\). Thus, considering at most all possible \(2\)-colorings of \(G[N(u)]\), we can decide the \(3\)-coloring problem on \(G\) in time \(O^{*}(2^{\delta })=2^{O(\delta )}\).

Summarizing, we can combine these two \(3\)-coloring algorithms for \(G\), obtaining an algorithm with time complexity \({2^{O\left( \min \{\delta ,\frac{n}{ \delta }\log \delta \}\right) }}\).\(\square \)

The next corollary provides the first subexponential algorithm for the \(3\)-coloring problem on graphs with diameter \(2\). Its correctness follows by Theorem 3.

Corollary 1

Let \(G=(V,E)\) be an irreducible graph with \(n\) vertices and let \(diam(G)=2\). Then, the \(3\)-coloring problem can be decided in \(2^{O(\sqrt{n\log n})}\) time on \(G\).

Proof

Let \({\delta =\delta (G)}\) be the minimum degree of \(G\). If \({\delta \le \sqrt{n\log n}}\), then the \(3\)-coloring problem can be decided in \({ 2^{O(\delta )}=2^{O(\sqrt{n\log n})}}\) time on \(G\) by Theorem 3. Suppose now that \({\delta >\sqrt{ n\log n}}\). Note that \({\log \delta <\log n}\), since \({\delta <n}\). Therefore \({\frac{\log \delta }{\delta }<\frac{\log n}{\sqrt{n\log n}}=\sqrt{ \frac{\log n}{n}}}\), and thus \({\frac{n}{\delta }\log \delta <n\sqrt{\frac{ \log n}{n}}}\), i.e. \({\frac{n}{\delta }\log \delta <\sqrt{n\log n}}\). Therefore the \(3\)-coloring problem can be decided in \({2^{O\left( \frac{n}{\delta } \log \delta \right) }=2^{O(\sqrt{n\log n})}}\) time on \(G\) by Theorem 3.\(\square \)

Given the statements of Lemma 1 and Theorem 3, a question that arises naturally is whether the worst case complexity of the algorithm of Theorem 3 is indeed \(2^{O(\sqrt{n\log n})}\) (as given in Corollary 1). That is, do there exist \(3\)-colorable irreducible graphs \(G\) with \(n\) vertices and \(diam(G)=2\), such that both \(\delta (G)\) and the size of the minimum dominating set of \(G\) are \(\varTheta (\sqrt{n\log n})\), or close to this value? We prove that such graphs exist; therefore our analysis of the DS-approach (cf. Lemma 1 and Theorem 3, see also [13, 23]) is asymptotically almost tight in the case of \(3\)-coloring of graphs with diameter \(2\). In particular, we provide in the next theorem for every \(n\) an example of an irreducible \(3\)-colorable graph \(G_{n}\) with \(\varTheta (n)\) vertices and \( diam(G_{n})=2\), such that both \(\delta (G_{n})\) and the size of the minimum dominating set of \(G\) are \(\varTheta (\sqrt{n})\). In addition, each of these graphs \(G_{n}\) is triangle-free, as the next theorem states. The construction of the graphs \(G_{n}\) is based on a suitable and interesting matrix arrangement of the vertices of \(G_{n}\).

Theorem 4

Let \({n\ge 1}\). Then there exists an irreducible and triangle-free \(3\) -colorable graph \({ G_{n}=(V_{n},E_{n})}\) with \(\varTheta (n)\) vertices, where \({diam(G_{n})=2}\) and \({\delta (G}_{n}){=\varTheta (\sqrt{n})}\). Furthermore, the size of the minimum dominating set of \(G_{n}\) is \(\varTheta (\sqrt{n})\).

Proof

We assume without loss of generality that \({n=4k^{2}+1}\) for some integer \({k>1}\) and we construct a graph \({G_{n}=(V_{n},E_{n})}\) with \(n\) vertices (otherwise, if \({n\ne 4k^{2}+1}\) for any \({k>1}\), we provide the same construction of \(G_{n}\) with \({4\lceil \frac{\sqrt{n}}{2}+1\rceil ^{2}+1=\varTheta (n)}\) vertices). We arrange the first \(n-1\) vertices of \(G_{n}\) (i.e. all vertices of \(G_{n}\) except one of them) in a matrix of size \( 2k\times 2k\). For simplicity of notation, we enumerate these \(4k^{2}\) vertices in the usual fashion, i.e. vertex \(v_{i,j}\) is the vertex in the intersection of row \(i\) and column \(j\), where \({1\le i,j\le 2k}\). Furthermore, we denote the \((4k^{2}+1)\)th vertex of \(G_{n}\) by \(v_{0}\). We assign the \(3\) colors red, blue, green to the vertices of \(G_{n}\) as follows. The vertices \({\{v_{i,j}:1\le i\le k,\ 1\le j\le k\}}\) are colored blue, the vertices \({\{v_{i,j}:k+1\le i\le 2k,\ 1\le j\le k\}}\) are colored green, the vertices \({\{v_{i,j}:1\le i\le 2k,\ k+1\le j\le 2k\}}\) are colored red, and vertex \(v_{0}\) is colored green.

We add edges among vertices of \(V_{n}\) as follows. First, vertex \(v_{0}\) is adjacent to exactly all vertices that are colored red in the above \(3\)-coloring of \(G_{n}\). Then, the vertices of \(j\)th column \( \{v_{1,j},v_{2,j},\ldots ,v_{2k,j}\}\) and the vertices of the \((2k+1-j)\)th column \(\{v_{1,2k+1-j},v_{2,2k+1-j},\ldots ,v_{2k,2k+1-j}\}\) form a complete bipartite graph, without the edges \(\{v_{i,j}v_{i,2k+1-j}:1\le i\le 2k\}\), i.e. without the edges between vertices of the same row. Furthermore, the vertices of \(i\)th row \(\{v_{i,1},v_{i,2},\ldots ,v_{i,2k}\}\) and the vertices of the \((2k+1-i)\)th row \(\{v_{2k+1-i,1},v_{2k+1-i,2},\ldots ,v_{2k+1-i,2k}\}\) form a complete bipartite graph, without the edges \( \{v_{i,j}v_{2k+1-i,j}:1\le j\le k\}\cup \{v_{i,j}v_{2k+1-i,\ell }:k+1\le j,\ell \le 2k\}\). That is, there are no edges between vertices of the same column and no edges between vertices colored red in the above \(3\)-coloring of \(G_{n}\). Note also that there are no edges between vertices colored blue (resp. green, red), and thus this coloring is a proper \(3\)-coloring of \( G_{n} \). The \(2k\times 2k\) matrix arrangement of the vertices of \(G_{n}\) is illustrated in Fig. 2a. In this figure, the three color classes are illustrated by different shades of gray. Furthermore, the edges of \(G_{n}\) between different rows and between different columns in this matrix arrangement are illustrated in Fig. 2b, c, respectively.

Fig. 2
figure 2

a The \({2k\times 2k}\) matrix arrangement of the vertices of \( G_{n} \), where \({n=4k^{2} + 1}\), b the edges of \(G_{n}\) between the \(i\)th and the \({(2k+1-i)}\)th rows, and c the edges of \(G_{n}\) between the \(j\)th and the \({(2k+1-j)}\)th columns of this matrix arrangement. The three color classes are illustrated by different shades of gray

It is easy to see by the construction of \(G_{n}\) that \(3k\le \deg (v_{i,j})\le 4k-2\) for every vertex \(v_{i,j}\in V_{n}{\setminus } \{v_{0}\}\) and that \(\deg (v_{0})=2k^{2}\). In particular, \(\deg (v_{i,j})=3k\) (resp. \( \deg (v_{i,j})=4k-2\)) for every vertex \(v_{i,j}\) that has been colored red (resp. blue or green) in the above coloring of \(G_{n}\). Therefore, since \( k=\varTheta (\sqrt{n})\), it follows that \(\deg (v_{i,j})=\varTheta (\sqrt{n})\) for every \(v_{i,j}\in V_{n}{\setminus } \{v_{0}\}\) and that \(\deg (v_{0})=\frac{n-1 }{2}\). That is, the minimum degree is \(\delta (G_{n})=\varTheta (\sqrt{n})\).

Note now that the set \(\{v_{0}\}\cup \{v_{1,1},v_{2,1},\ldots ,v_{2k,1}\}\) of vertices is a dominating set of \(G\) with \(2k+1=\varTheta (\sqrt{n})\) vertices, since for every \(i=1,2,\ldots ,2k\), vertex \(v_{i,1}\) is adjacent to all vertices of the \((2k+1-i)\)th row of the matrix, except vertex \( v_{2k+1-i,1}\). Suppose that there exists a dominating set \(D\subseteq V_{n}\) with cardinality \(o(\sqrt{n})\), i.e. \(|D|=\frac{\sqrt{n}}{f(n)}\), where \( f(n)=\omega (1)\). Denote \(D^{\prime }=D\cup \{v_{0}\}\); note that \( |D^{\prime }|\le \frac{\sqrt{n}}{f(n)}+1\). Then, since \(\deg (v_{i,j})=\varTheta (\sqrt{n})\) for every vertex \(v_{i,j}\in V_{n}{\setminus } \{v_{0}\}\), the vertices of \(D^{\prime }\) can be adjacent to at most

$$\begin{aligned} \frac{n-1}{2}+|D^{\prime }{\setminus } \{v_{0}\}|\cdot \varTheta (\sqrt{n})\le \frac{n-1}{2}+\frac{\sqrt{n}}{f(n)}\cdot \varTheta (\sqrt{n})=\frac{n-1}{2}+ \frac{\varTheta (n)}{f(n)} \end{aligned}$$

vertices of \(V_{n}{\setminus } D^{\prime }\) in total. However \(|V_{n}{\setminus } D^{\prime }|\ge n-\frac{\sqrt{n}}{f(n)}-1\ge n-\sqrt{n}-1\) and \(\frac{n-1}{ 2}+\frac{\varTheta (n)}{f(n)}\) is asymptotically smaller than \(n-\sqrt{n}-1\), since \(f(n)=\omega (1)\). That is, the vertices of \(D^{\prime }\) (and thus also of \(D\)) cannot dominate all vertices of \(V_{n}{\setminus } D^{\prime }\subseteq V_{n}{\setminus } D\). Thus \(D\) is not a dominating set, which is a contradiction. Therefore the size of a minimum dominating set of \(G_{n}\) is \( \varTheta (\sqrt{n})\).

Now we will prove that \(diam(G_{n})=2\). First note that for every vertex \( v_{i,j}\in V_{n}{\setminus } \{v_{0}\}\) we have \(d(v_{0},v_{i,j})\le 2\). Indeed, if \(v_{i,j}\) is colored red, then \(v_{i,j}\) is adjacent to \(v_{0}\); otherwise \(v_{0}\) and \(v_{i,j}\) have vertex \(v_{2k+1-i,2k}\) as common neighbor. Now consider two arbitrary vertices \(v_{i,j}\) and \(v_{p,q}\), where \((i,j)\ne (p,q)\). Since any two red vertices have \(v_{0}\) as common neighbor (and thus they are at distance \(2\) from each other), assume that at most one of the vertices \(\{v_{i,j},v_{p,q}\}\) is colored red. We will prove that \(d(v_{i,j},v_{p,q})\le 2\). If \(p=i\), then \(v_{i,j}\) and \(v_{p,q}\) lie both in the \(i\)th row of the matrix. Therefore \(v_{i,j}\) and \(v_{p,q}\) have all vertices of \(\{v_{2k+1-i,1},v_{2k+1-i,2},\ldots ,v_{2k+1-i,k}\}{\setminus } \{v_{2k+1-i,j},v_{2k+1-i,q}\}\) as their common neighbors, and thus \( d(v_{i,j},v_{p,q})=2\). If \(q=j\), then \(v_{i,j}\) and \(v_{p,q}\) lie both in the \(j\)th column of the matrix. Therefore \(v_{i,j}\) and \(v_{p,q}\) have all vertices of \(\{v_{1,2k+1-j},v_{2,2k+1-j},\ldots ,v_{2k,2k+1-j}\}{\setminus } \{v_{i,2k+1-j},v_{p,2k+1-j}\}\) as their common neighbors, and thus \( d(v_{i,j},v_{p,q})=2\). Suppose that \(p\ne i\) and \(q\ne j\). If \(p=2k+1-i\) or \(q=2k+1-j\), then \(v_{i,j}v_{p,q}\in E_{n}\) by the construction of \(G_{n}\) , and thus \(d(v_{i,j},v_{p,q})=1\). Suppose now that also \(p\ne 2k+1-i\) and \( q\ne 2k+1-j\). Since at most one of the vertices \(\{v_{i,j},v_{p,q}\}\) is colored red, we may assume without loss of generality that \(v_{i,j}\) is blue or green, i.e. \(j\le k\). Then there exists the path \( (v_{i,j},v_{2k+1-i,2k+1-q},v_{p,q})\) in \(G_{n}\), and thus \( d(v_{i,j},v_{p,q})=2\). Summarizing, \(d(u,v)\le 2\) for every pair of vertices \(u\) and \(v\) in \(G_{n}\), and thus \(diam(G_{n})=2\).

Now we will prove that \(G_{n}\) is a triangle-free graph. First note that \( v_{0}\) cannot belong to any possible triangle in \(G_{n}\), since its neighbors are by construction an independent set. Suppose now that the vertices \(v_{i,j},v_{p,q},v_{r,s}\) induce a triangle in \(G_{n}\). Since the above coloring of the vertices of \(V_{n}\) is a proper \(3\)-coloring of \(G_{n}\) , we may assume without loss of generality that \(v_{i,j}\) is colored blue, \( v_{p,q}\) is colored green, and \(v_{r,s}\) is colored red in the above coloring of \(G_{n}\). That is, \(i,j\in \{1,2,\ldots ,k\}\), \(p\in \{k+1,k+2,\ldots ,2k\}\), \(q\in \{1,2,\ldots ,k\}\), \(r\in \{1,2,\ldots ,2k\}\) , and \(s\in \{k+1,k+2,\ldots ,2k\}\). Thus, since \(v_{i,j}v_{p,q}\in E_{n}\), it follows by the construction of \(G_{n}\) that \(p=2k+1-i\). Furthermore, since \(v_{p,q}v_{r,s}\in E_{n}\), it follows that \(p=2k+1-r\) or \(q=2k+1-s\). If \(p=2k+1-r\), then \(r=i\) (since also \(p=2k+1-i\)). Therefore \(v_{i,j}\) and \( v_{r,s}\) lie both in the \(i\)th row of the matrix, which is a contradiction, since we assumed that \(v_{i,j}v_{r,s}\in E_{n}\). Therefore \(q=2k+1-s\). Finally, since \(v_{i,j}v_{r,s}\in E_{n}\), it follows that \(r=2k+1-i\) or \( s=2k+1-j\). If \(r=2k+1-i\), then \(r=p\) (since also \(p=2k+1-i\)). Therefore \( v_{p,q}\) and \(v_{r,s}\) lie both in the \(p\)th row of the matrix, which is a contradiction, since we assumed that \(v_{p,q}v_{r,s}\in E_{n}\). Therefore \( s=2k+1-j\). Thus, since also \(q=2k+1-s\), it follows that \(q=j\), i.e. \(v_{i,j}\) and \(v_{p,q}\) lie both in the \(j\)th column of the matrix. This is again a contradiction, since we assumed that \(v_{i,j}v_{p,q}\in E_{n}\). Therefore, no three vertices of \(G_{n}\) induce a triangle, i.e. \(G_{n}\) is triangle-free.

Note now that \(G_{n}\) is diamond-free, since it is also triangle-free, and thus the Reduction Rule 1 does not apply on \(G_{n}\). Furthermore, it is easy to check that there exist no pair \(v_{i,j}\) and \(v_{p,q}\) of vertices such that \(N(v_{i,j})\subseteq N(v_{p,q})\), and that there does not exist any vertex \(v_{i,j}\) such that \(N(v_{i,j})\subseteq N(v_{0})\) or \(N(v_{0})\subseteq N(v_{i,j})\). That is, \(G_{n}\) is siblings-free, and thus also the Reduction Rule 2 does not apply on \(G_{n}\). Therefore \(G_{n}\) is irreducible. This completes the proof of the theorem.\(\square \)

3.2 A Tractable Subclass of Graphs with Diameter \(2\)

In this section we present a subclass of graphs with diameter \(2\), which admits an efficient algorithm for \(3\)-coloring. We first introduce the definition of an articulation neighborhood in a graph.

Definition 2

Let \(G=(V,E)\) be a graph and let \(v\in V\). If \(G-N[v]\) is disconnected, then \(N[v]\) is an articulation neighborhood in \(G\).

We prove in Theorem 5 that, given an irreducible graph with \(diam(G)=2\), which has at least one articulation neighborhood, we can decide \(3\)-coloring on \(G\) in polynomial time. Note here that there exist instances of  \(K_{4}\)-free graphs \(G\) with diameter \(2\), in which \(G\) has no articulation neighborhood, but in the irreducible graph \(G^{\prime }\) obtained by \(G\) (by iteratively applying the Reduction Rules 1 and 2), \( G^{\prime }-N_{G^{\prime }}[v]\) becomes disconnected for some vertex \(v\) of \( G^{\prime }\). That is, \(G^{\prime }\) may have an articulation neighborhood, although \(G\) has none. Therefore, if we consider as input the irreducible graph \(G^{\prime }\) instead of \(G\), we can decide in polynomial time the \(3\)-coloring problem on \(G^{\prime }\) (and thus also on \(G\)).

Theorem 5

Let \({G\!=\!(V,E)}\) be an irreducible graph with \(n \) vertices and \({diam(G)=2}\). If \(G\) has at least one articulation neighborhood, then we can decide \(3\)-coloring on \(G\) in time polynomial in \(n\).

Proof

Let \(v_{0}\in V\) such that \({G-N[v_{0}]}\) is disconnected and let \( C_{1},C_{2},\ldots ,C_{k}\) be the connected components of \(G-N[v_{0}]\). In order to compute a proper \(3\)-coloring of \(G\), the algorithm assigns without loss of generality the color red to vertex \(v_{0}\). Suppose that at least one component \(C_{i}\), \(1\le i\le k\), is trivial, i.e. \(C_{i}\) is an isolated vertex \(u\). Then, since \({u\in V{\setminus } N[v_{0}]}\) and \(u\) has no adjacent vertices in \(V{\setminus } N[v_{0}]\), it follows that \(N(u)\subseteq N(v_{0})\), i.e. \(u\) and \(v_{0}\) are siblings in \(G\). This is a contradiction, since \(G\) is an irreducible graph. Therefore, every connected component \(C_{i}\) of \({G-N[v_{0}]}\) is non-trivial, i.e. it contains at least one edge. Thus, in any proper \(3\)-coloring of \(G\) (if such exists), there exists at least one vertex of every connected component \(C_{i}\) of \({G-N[v_{0}]}\) that is colored not red, i.e. with a different color than \(v_{0}\).

Suppose now that \(G\) is \(3\)-colorable, and let \(c\) be a proper \(3\) -coloring of \(G\). Assume without loss of generality that \(c\) uses the colors red, blue, and green (recall that \(v_{0}\) is already colored red). Let \(C_{i},C_{j}\) be an arbitrary pair of connected components of \(G-N[v_{0}]\); such a pair always exists, as \( G-N[v_{0}]\) is assumed to be disconnected. Let \(u\) and \(v\) be two arbitrary vertices of \(C_{i}\) and of \(C_{j}\), respectively, such that both \(u\) and \(v\) are not colored red in \(c\); such vertices \(u\) and \(v\) always exist, as we observed above. Then, since \(diam(G)=2\), there exists at least one common neighbor \(a\) of \(u\) and \(v\), where \(a\in N(v_{0})\). That is, \(a\in N(v_{0})\cap N(u)\cap N(v)\). Therefore, since \(v_{0}\) is colored red in \(c\) and \(u,v\) are not colored red in \(c\), it follows that both \(u\) and \(v\) are colored by the same color in \(c\). Assume without loss of generality that both \(u\) and \(v\) are colored blue in \(c\). Thus, since \(u\) and \(v\) have been chosen arbitrarily under the single assumption that they are not colored red in \(c\), it follows that for every vertex \(u\) of \( G-N[v_{0}]\), \(u\) is either colored red or blue in \(c\). Furthermore, since \(v_{0}\) has been assumed to be red and hence the neighbors of \(v_{0}\) use colors blue and green, each vertex now has only two possible colors that it can use. This reduces the problem to the list 2-coloring problem that can be solved in polynomial time (by reducing to the 2SAT problem). This completes the proof of the theorem.\(\square \)

A question that arises now naturally by Theorem 5 is whether there exist any irreducible \( 3\)-colorable graph \({G=(V,E)}\) with \({diam(G)=2}\), which has no articulation neighborhood at all. A negative answer to this question would imply that we can decide the \(3\)-coloring problem on any graph with diameter \(2\) in polynomial time using Theorem 5. However, the answer to that question is positive: for every \(n\ge 1\), the graph \(G_{n}=(V_{n},E_{n})\) that has been presented in Theorem 4 is irreducible, \(3\)-colorable, has diameter  \(2\), and \(G_{n}-N[v]\) is connected for every \(v\in V_{n}\), i.e. \(G_{n}\) has no articulation neighborhood. Therefore Theorem 5 cannot be used in a trivial way to decide in polynomial time the \(3\)-coloring problem for an arbitrary graph of diameter \(2\). We leave the tractability of the \(3\)-coloring problem of arbitrary diameter-\(2\) graphs as an open problem.

4 Almost Tight Results for Graphs with Diameter \(3\)

In this section we present our results on graphs with diameter \(3\). In particular, we first provide in Sect. 4.1 our algorithm for \(3\)-coloring arbitrary graphs with diameter \(3\) that has running time \({2^{O\left( \min \{\delta \varDelta ,\ \frac{n}{\delta }\log \delta \}\right) } }\), where \(n\) is the number of vertices and \(\delta \) (resp. \(\varDelta \)) is the minimum (resp. maximum) degree of the input graph. Then we prove in Sect. 4.2 that \(3\)-coloring is NP-complete on irreducible and triangle-free graphs with diameter \(3\) and radius \(2\) by providing a reduction from \(3\)SAT. Finally, we provide in Sect. 4.3 our three different amplification techniques that extend our hardness results of Sect. 4.2. In particular, we provide in Theorems 9 and 10 our NP-completeness amplifications, and in Theorems 11, 12, and 13 our lower bounds for the time complexity of \(3\)-coloring, assuming ETH.

4.1 An \(2^{O\left( \min \{\delta \varDelta ,\ \frac{n}{\delta }\log \delta \}\right) }\)-Time Algorithm for Any Graph with Diameter \(3\)

In the next theorem we use the DS-approach of Lemma 1 to provide a \(3\)-coloring algorithm for the case of graphs with diameter \(3\). The time complexity of this algorithm is parameterized by the minimum degree \(\delta \) of the given graph \(G\), as well as by the fraction \(\frac{n}{\delta }\).

Theorem 6

Let \({G\!=\!(V,E)}\) be an irreducible graph with \(n\) vertices and \({diam(G)=3}\). Let \(\delta \) and \({ \varDelta }\) be the minimum and the maximum degree of \(G\), respectively. Then, the \(3\)-coloring problem can be decided in \(2^{O\left( \min \{\delta \varDelta ,\ \frac{n}{\delta }\log \delta \}\right) }\) time on \(G\).

Proof

First recall that, in an arbitrary graph \(G\) with \(n\) vertices and minimum degree \(\delta \), we can construct in polynomial time a dominating set \(D\) with cardinality \(|D|\le n\frac{1+\ln (\delta +1)}{\delta +1}\) [2]. Therefore, similarly to the proof of Theorem 3, we can use the DS-approach of Lemma 1 to obtain an algorithm that decides \(3\)-coloring on \(G\) in \(2^{O\left( \frac{n}{\delta }\log \delta \right) }\) time.

The DS-approach of Lemma 1 applies to any graph \(G\). However, since \(G\) has diameter \(3\) by assumption, we can design a second algorithm for \(3\)-coloring of \(G\) as follows. Consider a vertex \({ u\in V}\) with minimum degree, i.e. \({\deg (u)=\delta }\). Since \({diam(G)=3}\), we can partition the vertices of \({V{\setminus } N[u]}\) into two sets \(A\) and \( B \), such that \({A=\{v\in V{\setminus } N[u] : d(u,v)=2\}}\) and \({B=\{v\in V{\setminus } N[u] : d(u,v)=3\}}\). Note that every vertex \({v\in A}\) is adjacent to at least one vertex of \(N(u)\). Therefore, since \(|N(u)|=\delta \) and the maximum degree in \(G\) is \(\varDelta \), it follows that \({|A|\le \delta \cdot \varDelta }\). Furthermore, the set \(A\cup \{u\}\) is a dominating set of \(G\) with cardinality at most \({\delta \varDelta +1}\). Thus we can decide \(3\)-coloring on \(G \) by considering in the worst case all possible \(3\)-colorings of  \({A\cup \{u\}} \) in \(O^{*}(3^{\delta \varDelta +1})=2^{O(\delta \varDelta )}\) time by using the DS-approach of Lemma 1.

Summarizing, we can combine these two \(3\)-coloring algorithms for \(G\), obtaining an algorithm with time complexity \(2^{O\left( \min \{\delta \varDelta ,\ \frac{n}{\delta }\log \delta \}\right) }\).\(\square \)

To the best of our knowledge, the algorithm of Theorem 6 is the first subexponential algorithm for graphs with diameter \(3\), whenever \(\delta =\omega (1)\), as well as whenever \(\delta =O(1)\) and \(\varDelta =o(n)\). As we will later prove in Sect. 4.3, the running time provided in Theorem 6 is asymptotically almost tight whenever \(\delta =\varTheta (n^{\varepsilon })\), for any \( \varepsilon \in [\frac{1}{2},1)\).

Note now that for any graph \(G\) with \(n\) vertices and \(diam(G)=3\), the maximum degree \(\varDelta \) of \(G\) is \({\varDelta =\varOmega (n^{\frac{1}{3}})}\). Indeed, suppose otherwise that \(\varDelta =o(n^{\frac{1}{3}})\), and let \(u\) be any vertex of \(G\). Then, there are at most \(\varDelta \) vertices in \(G\) at distance \(1\) from \(u\), at most \(\varDelta ^{2}\) vertices at distance \(2\) from \( u \), and at most \(\varDelta ^{3}\) vertices at distance \(3\) from \(u\). That is, \( G \) contains at most \({1+\varDelta +\varDelta ^{2}+\varDelta ^{3}=o(n)}\) vertices, since we assumed that \({\varDelta =o(n^{\frac{1}{3}})}\), which is a contradiction. Therefore \({\varDelta =\varOmega (n^{\frac{1}{3}})}\). Furthermore note that, whenever \({\delta =\varOmega (n^{\frac{1}{3}}\sqrt{\log n})}\) in a graph with \(n\) vertices and diameter \(3\), we have \({\delta \varDelta =\varOmega ( \frac{n}{\delta }\log \delta )}\). Indeed, since \({\varDelta =\varOmega (n^{\frac{1 }{3}})}\) as we proved above, it follows that in this case \({\delta ^{2}\varDelta =\varOmega (n\log n)=\varOmega (n\log \delta )}\), since \({\delta <n}\), and thus \({\delta \varDelta =\varOmega (\frac{n}{\delta }\log \delta )}\). Therefore, if the minimum degree of \(G\) is \({\delta =\varOmega (n^{\frac{1}{3}} \sqrt{\log n})}\), the running time of the algorithm of Theorem 6 becomes \({2^{O\left( \frac{n}{\delta }\log \delta \right) }=2^{O\left( n^{\frac{2}{3}}\sqrt{\log n}\right) }}\).

4.2 The \(3\)-Coloring Problem is NP-Complete on Graphs with Diameter \(3\) and Radius \(2\)

In this section we provide a reduction from the \(3\)SAT problem to the \(3\)-coloring problem of triangle-free graphs with diameter \(3\) and radius \(2\). Given a boolean formula \(\phi \) in conjunctive normal form with three literals in each clause (3-CNF), \(\phi \) is satisfiable if there is a truth assignment of \(\phi \), such that every clause contains at least one true literal. The problem of deciding whether a given 3-CNF formula is satisfiable, i.e. the 3SAT problem, is one of the most known NP-complete problems [12]. Let \(\phi \) be a 3-CNF formula with \(n\) variables \(x_{1},x_{2},\ldots ,x_{n}\) and \(m\) clauses \(\alpha _{1},\alpha _{2},\ldots ,\alpha _{m}\). We can assume in the following without loss of generality that each clause has three distinct literals. We now construct an irreducible and triangle-free graph \(H_{\phi }=(V_{\phi },E_{\phi })\) with diameter \(3\) and radius \(2\), such that \(\phi \) is satisfiable if and only if \(H_{\phi }\) is \(3\)-colorable. Before we construct \(H_{\phi }\), we first construct an auxiliary graph \(G_{n,m}\) that depends only on the number \(n\) of the variables and the number \(m\) of the clauses in \(\phi \), rather than on \(\phi \) itself.

We construct the graph \({G_{n,m}=(V_{n,m},E_{n,m})}\) as follows. Let \(v_{0}\) be a vertex with \(8m\) neighbors \(v_{1}, v_{2}, \ldots , v_{8m}\), which induce an independent set. Consider also the sets \({U=\{u_{i,j}:1\le i\le n+5m,1\le j\le 8m\}}\) and \({W=\{w_{i,j}:1\le i\le n+5m,1\le j}\) \({\le 8m\}}\) of vertices. Each of these sets has \(({n+5m)}8m\) vertices. The set \(V_{n,m}\) of vertices of \(G_{n,m}\) is defined as \({V_{n,m}=U\cup W\cup \{v_{0},v_{1},v_{2},\ldots ,v_{8m}\}}\). That is, \({|V_{n,m}|=2\cdot ({n+5m} )8m+8m+1}\), and thus \(|V_{n,m}|=\varTheta (m^{2})\), since \(m=\varOmega (n)\).

The set \(E_{n,m}\) of the edges of \(G_{n,m}\) is defined as follows. Define first for every \(j\in \{1,2,\ldots ,8m\}\) the subsets \(U_{j}= \{u_{1,j},u_{2,j},\ldots ,u_{{n+5m},j}\}\) and \(W_{j}=\{w_{1,j},w_{2,j}, \ldots ,w_{{n+5m},j}\}\) of \(U\) and \(W\), respectively. Then define \( N(v_{j})=\{v_{0}\}\cup U_{j}\cup W_{j}\) for every \(j\in \{1,2,\ldots ,8m\}\), where \(N(v_{j})\) denotes the set of neighbors of vertex \(v_{j}\) in \(G_{n,m}\) . For simplicity of the presentation, we arrange the vertices of \(U\cup W\) on a rectangle matrix of size \(2({n+5m)}\times 8m\), cf. Fig. 3a. In this matrix arrangement, the \((i,j)\)th element is vertex \(u_{i,j}\) if \(i\le {n+5m}\), and vertex \(w_{i-{n-5m},j}\) if \(i\ge {n+5m}+1\). In particular, for every \(j\in \{1,2,\ldots ,8m\}\), the \(j\)th column of this matrix contains exactly the vertices of \(U_{j}\cup W_{j}\), cf. Fig. 3a. Note that, for every \(j\in \{1,2,\ldots ,8m\}\), vertex \(v_{j}\) is adjacent to all vertices of the \(j\)th column of this matrix. Denote now by \(\ell _{i}=\{u_{i,1},u_{i,2},\ldots ,u_{i,8m}\}\) (resp. \(\ell _{i}^{\prime }=\{w_{i,1},w_{i,2},\ldots ,w_{i,8m}\} \)) the \(i\)th (resp. the \(({n+5m}+i)\)th) row of this matrix, cf. Fig. 3a. For every \(i\in \{1,2,\ldots ,{n+5m}\}\) , the vertices of \(\ell _{i}\) and of \(\ell _{i}^{\prime }\) induce two independent sets in \(G_{n,m}\). We then add between the vertices of \(\ell _{i} \) and the vertices of \(\ell _{i}^{\prime }\) all possible edges, except those of \(\{u_{i,j}w_{i,j}:1\le j\le 8m\}\). That is, we add all possible \( (8m)^{2}-8m \) edges between the vertices of \(\ell _{i}\) and of \(\ell _{i}^{\prime }\), such that they induce a complete bipartite graph without a perfect matching between the vertices of \(\ell _{i}\) and of \(\ell _{i}^{\prime }\), cf. Fig. 3b. Note by the construction of \(G_{n,m}\) that both \(U\) and \(W\) are independent sets in \( G_{n,m}\). Furthermore note that the minimum degree in \(G_{n,m}\) is \(\delta (G_{n,m})=\varTheta (m)\) and the maximum degree is \(\varDelta (G_{n,m})=\varTheta (n+m)\). Thus, since \(m=\varOmega (n)\), we have that \(\delta (G_{n,m})=\varDelta (G_{n,m})=\varTheta (m)\). The construction of the graph \(G_{n,m}\) is illustrated in Fig. 3.

Fig. 3
figure 3

a The \(2(n+5m)\times 8m\)-matrix arrangement of the vertices \( U\cup W\) of \(G_{n,m}\) and their connections with the vertices \( \{v_{0},v_{1},v_{2},\ldots ,v_{8m}\}\)b the edges between the vertices of the \(i\)th row \(\ell _{i}\) and the \((n+5m+i)\)th row \(\ell _{i}^{\prime }\) in this matrix, and c the gadget with \(8\) vertices and \(10\) edges that we associate in \(H_{\phi }\) to the clause \(\alpha _{k}\) of \(\phi \), where \({1\le k\le m}\)

Lemma 2

For every \(n,m\ge 1\), the graph \(G_{n,m}\) has diameter \(3\) and radius \(2\).

Proof

First note that for any \(j\in \{1,2,\ldots ,8m\}\), every vertex \(u_{i,j}\) (resp. \(w_{i,j}\)) is adjacent to \(v_{j}\). Therefore, since \(v_{j}\in N(v_{0}) \) for every \(j\in \{1,2,\ldots ,8m\}\), it follows that \( d(v_{0},u)\le 2\) for every \(u\in V_{n,m}{\setminus } \{v_{0}\}\), and thus \( G_{n,m}\) has radius \(2 \). Furthermore note that \(d(v_{j},v_{k})\le 2\) for every \(j,k\in \{1,2,\ldots ,8m\}\), since \(v_{j},v_{k}\in N(v_{0})\). Consider now an arbitrary vertex \(u_{i,j}\) (resp. \(w_{i,j}\)) and an arbitrary vertex \( v_{k}\). If \(j=k\), then \({d(v_{k},u_{i,j})=1}\) (resp. \({d(v_{k},w_{i,j})=1}\)). Otherwise, if \(j\ne k\), then there exists the path \( (v_{k},v_{0},v_{j},u_{i,j})\) (resp. \((v_{k},v_{0},v_{j},w_{i,j})\)) of length \(3\) between \(v_{k}\) and \(u_{i,j}\) (resp. \(w_{i,j}\)). Therefore also \( d(v_{k},u)\le 3\) for every \(k=1,2,\ldots ,8m\) and every \({u\in V_{n,m}{\setminus } \{v_{k}\}}\).

We will now prove that \(d(u_{i,j},u_{p,q})\le 3\) for every \((i,j)\ne (p,q)\). If \(q\ne j\), then there exists the path \((u_{i,j},v_{j},w_{p,j},u_{p,q})\) of length \(3\) between \(u_{i,j}\) and \( u_{p,q} \). If \(q=j\), then \(d(u_{i,j},u_{p,q})=2\), as \(u_{i,j},u_{p,q}\in N(v_{j})\). Therefore \(d(u_{i,j},u_{p,q})\le 3\) for every \((i,j)\ne (p,q)\). Similarly we can prove that \({d(w_{i,j},w_{p,q})\le 3}\) for every \( (i,j)\ne (p,q)\). It remains to prove that \(d(u_{i,j},w_{p,q})\le 3\) for every \((i,j)\) and every \((p,q)\). If \(p\ne i\) and \(q\ne j\), then there exists the path \((u_{i,j},v_{j},u_{p,j},w_{p,q})\) of length \(3\) between \( u_{i,j}\) and \(w_{p,q}\). If \(q=j\), then \(d(u_{i,j},w_{p,q})=2\), since \( u_{i,j},w_{p,q}\in N(v_{j})\). If \(p=i\) and \(q\ne j\), then \(w_{p,q}=w_{i,q}\) , and thus \(u_{i,j}w_{p,q}\in E_{n,m}\). Therefore \(d(u_{ij},w_{pq})\le 3\) for every \((i,j)\) and every \((p,q)\), and thus \(G_{n,m}\) has diameter \(3\).\(\square \)

Lemma 3

For every \(n,m\ge 1\), the graph \(G_{n,m}\) is irreducible and triangle-free.

Proof

First observe that, by construction, \(G_{n,m}\) has no pair of sibling vertices, and thus the Reduction Rule 2 does not apply to \(G_{n,m}\). Thus, in order to prove that \(G_{n,m}\) is irreducible, it suffices to prove that \(G_{n,m}\) is triangle-free, and thus also diamond-free, i.e. also the Reduction Rule 1 does not apply to \(G_{n,m}\). Suppose otherwise that \(G_{n,m}\) has a triangle with vertices \(a,b,c\). Note that vertex \(v_{0}\) does not belong to any triangle in \(G_{n,m}\), since its neighbors \(N(v_{0})=\{v_{1},v_{2},\ldots ,v_{8m}\}\) induce an independent set in \(G_{n,m}\). Furthermore, note that also vertex \(v_{j}\), where \(1\le j\le 8m\), does not belong to any triangle in \(G_{n,m}\). Indeed, by construction of \(G_{n,m}\), its neighbors \(N(v_{j})=\{v_{0}\}\cup U_{j}\cup W_{j}\) induce an independent set in \(G_{n,m}\). Therefore all the vertices \( a,b,c\) of the assumed triangle of \(G_{n,m}\) belong to \(U\cup W\). Therefore, at least two vertices among \(a,b,c\) belong to \(U\), or at least two of them belong to \(W\). This is a contradiction, since by the construction of \( G_{n,m} \) the sets \(U\) and \(W\) induce two independent sets. Therefore \( G_{n,m}\) is triangle-free. Thus \(G_{n,m}\) is also diamond-free, i.e. the Reduction Rule 1 does not apply to \(G_{n,m}\). Summarizing, \( G_{n,m} \) is irreducible and triangle-free.\(\square \)

We now construct the graph \(H_{\phi }=(V_{\phi },E_{\phi })\) from \(\phi \) by adding \(10m\) edges to \(G_{n,m}\) as follows. Let \(k\in \{1,2,\ldots ,m\}\) and consider the clause \(\alpha _{k}=(l_{k,1}\vee l_{k,2}\vee l_{k,3})\), where \( l_{k,p}\in \{x_{i_{k,p}},\overline{x_{i_{k,p}}}\}\) for \(p\in \{1,2,3\}\) and \( i_{k,1},i_{k,2},i_{k,3}\in \{1,2,\ldots ,n\}\). For this clause \(\alpha _{k}\) , we add on the vertices of \(G_{n,m}\) an isomorphic copy of the gadget in Fig. 3c, which has \(8\) vertices and \(10\) edges, as follows. Let \(p\in \{1,2,3\}\). The literal \(l_{k,p}\) corresponds to vertex \(g_{k,p}\) of this gadget. If \(l_{k,p}=x_{i_{k,p}}\), we set \( g_{k,p}=u_{i_{k,p},8k+1-p}\). Otherwise, if \(l_{k,p}=\overline{x_{i_{k,p}}}\), we set \(g_{k,p}=w_{i_{k,p},8k+1-p}\). Furthermore, for \(p\in \{4,\ldots ,8\}\), we set \(g_{k,p}=u_{n+5k+4-p,8k+1-p}\).

Note that, by construction, the graphs \(H_{\phi }\) and \(G_{n,m}\) have the same vertex set, i.e. \(V_{\phi }=V_{n,m}\), and that \(E_{n,m}\subset E_{\phi } \). Therefore \(diam(H_{\phi })\le 3\) and \(rad(H_{\phi })\le 2\), since \( diam(G_{n,m})=3\) and \(rad(G_{n,m})=2\) by Lemma 2. Observe now that every positive literal of \(\phi \) is associated to a vertex of \(U\), while every negative literal of \(\phi \) is associated to a vertex of \(W\). In particular, each of the \(3m\) literals of \(\phi \) corresponds by this construction to a different column in the matrix arrangement of the vertices of \(U\cup W\). If a literal of \(\phi \) is the variable \(x_{i}\) (resp. the negated variable \(\overline{x_{i}}\)), where \(1\le i\le n\), then the vertex of \(U\) (resp. \(W\)) that is associated to this literal lies in the \(i\)th row \( \ell _{i}\) (resp. in the \((n+5m+i)\)th row \(\ell _{i}^{\prime }\)) of the matrix.

Moreover, note by the above construction that each of the \(8m\) vertices \(\{g_{k,1},g_{k,2},\ldots ,g_{k,8}\}_{k=1}^{m}\) corresponds to a different column in the matrix of the vertices of \(U\cup W\). Finally, each of the \(5m\) vertices \(\{g_{k,4},g_{k,5},g_{k,6},g_{k,7},g_{k,8}\}_{k=1}^{m}\) corresponds to a different row in the matrix of the vertices of \(U\). We emphasize here that, by construction, each copy of the gadget of Fig. 3c is an induced subgraph of \(H_{\phi }\).

Observation 2

The gadget of Fig. 3c has no proper \(2\)-coloring, as it contains an induced cycle of length \(5\).

Observation 3

Consider the gadget of Fig. 3c. If we assign to vertices \(g_{k,1},g_{k,2},g_{k,3}\) the same color, we cannot extend this coloring to a proper \(3\)-coloring of the gadget. Furthermore, if we assign to vertices \(g_{k,1},g_{k,2},g_{k,3}\) in total two or three colors, then we can extend this coloring to a proper \( 3 \)-coloring of the gadget.

The next observation follows by the construction of \(H_{\phi }\) and by our initial assumption that each clause of \(\phi \) has three distinct literals.

Observation 4

For every \(i\in \{1,2,\ldots ,n+5m\}\), there exists no pair of adjacent vertices in the same row \(\ell _{i}\) or \(\ell _{i}^{\prime }\) in \(H_{\phi }\).

Lemma 4

For every formula \(\phi \), the graph \(H_{\phi }\) is irreducible and triangle-free.

Proof

First observe that, similarly to \(G_{n,m}\), the graph \(H_{\phi }\) has no pair of sibling vertices, and thus the Reduction Rule 2 does not apply to \(H_{\phi }\). We will now prove that \(H_{\phi }\) is triangle-free. Suppose otherwise that \(H_{\phi }\) has a triangle with vertices \(a,b,c\). Similarly to \(G_{n,m}\), note that the neighbors of \(v_{0}\) in \(H_{\phi }\) induce an independent set, and thus vertex \(v_{0}\) does not belong to any triangle in \(H_{\phi }\). Furthermore, note by the construction of \(H_{\phi }\) that we do not add any edge between vertices \(u_{i,j}\) and \(w_{i,j}\), where \( 1\le i\le n+5m\) and \(1\le j\le 8m\). Therefore, similarly to \(G_{n,m}\), the neighbors of \(v_{j}\) induce an independent set in \(H_{\phi }\), where \( j\in \{1,2,\ldots ,8m\}\), and thus \(v_{j}\) does not belong to any triangle in \(H_{\phi }\). Therefore all the vertices \(a,b,c\) of the assumed triangle of \(H_{\phi }\) belong to \(U\cup W\). Since \(G_{n,m}\) is triangle-free by Lemma 3, it follows that at least one edge in this triangle belongs to \(E_{\phi }{\setminus } E_{n,m}\), i.e. to at least one of the copies of the gadget in Fig. 3c. Note that not all of the three vertices \(a,b,c\) belong to the same copy of this gadget, since the gadget is triangle-free, cf. Fig. 3c. Assume without loss of generality that vertices \(a\) and \(b\) (and thus also the edge \(ab\)) of the assumed triangle of \(H_{\phi }\) belong to the copy of the gadget that corresponds to clause \(\alpha _{k}\), where \(1\le k\le m\). Then, since vertex \(c\) does not belong to this gadget, the edges \(ac\) and \( bc \) of the assumed triangle belong also to the graph \(G_{n,m}\). Therefore, since \(a,b,c\in U\cup W\), it follows by the construction of \(G_{n,m}\) that \( a \) and \(b\) belong to some row \(\ell _{i}\) and \(c\) belongs to the row \(\ell _{i}^{\prime }\), or \(a\) and \(b\) belong to some row \(\ell _{i}^{\prime }\) and \(c\) belongs to the row \(\ell _{i}\). This is a contradiction, since no pair of adjacent vertices (such as \(a\) and \(b\)) belong to the same row \(\ell _{i}\) or \(\ell _{i}^{\prime }\) in \(H_{\phi }\) by Observation 4. Therefore \(H_{\phi }\) is triangle-free, and thus also diamond-free, i.e. the Reduction Rule 2 does not apply to \( H_{\phi }\). Summarizing, \(H_{\phi }\) is irreducible and triangle-free.\(\square \)

We are now ready to state the main theorem of this section.

Theorem 7

The formula \(\phi \) is satisfiable if and only if \(H_{\phi }\) is \(3\)-colorable.

Proof

We will first prove that \(G_{n,m}\) is always \(3\)-colorable. Recall that both \(U\) and \(W\) are independent sets in \(G_{n,m}\), and that the only edges among the vertices of \(U\cup W\) in \(G_{n,m}\) are all possible edges between the rows \(\ell _{i}\) (that contains only vertices of \(U\)) and \(\ell _{i}^{\prime }\) (that contains only vertices of \(W\)), except for a perfect matching between the vertices of \(\ell _{i}\) and of \(\ell _{i}^{\prime }\). Consider three colors, say red, green, and blue. We assign to vertex \(v_{0}\) the color red. Furthermore we assign arbitrarily the color blue or green to each of its neighbors \(v_{j}\), \(1\le j\le 8m\). For each of these \(2^{8m}\) different colorings of vertex \(v_{0}\) and its neighbors, we can construct \( 2^{n+5m}\) different proper \(3\)-colorings of \(G_{n,m}\) as follows. For every \( i\in \{1,2,\ldots ,n+5m\}\), we have at least two possibilities for coloring the vertices of \(\ell _{i}\) and of \(\ell _{i}^{\prime }\): (a) color all vertices of \(\ell _{i}\) red, and for every vertex \(w_{i,j}\) of \(\ell _{i}^{\prime }\), color \(w_{i,j}\) blue (resp. green) if \(v_{j}\) is colored green (resp. blue), and (b) color all vertices of \(\ell _{i}^{\prime }\) red, and for every vertex \(u_{i,j}\) of \(\ell _{i}\), color \(u_{i,j}\) blue (resp. green) if \(v_{j}\) is colored green (resp. blue). Therefore, there are at least \(2^{8m}\cdot 2^{n+5m}\) different proper \(3\)-colorings of \(G_{n,m}\), in which vertex \(v_{0}\) obtains color red.

(\(\Rightarrow \)) Suppose first that \(\phi \) is satisfiable, and let \(\tau \) be a satisfying truth assignment of \(\phi \). Given this truth assignment \( \tau \), we construct a proper \(3\)-coloring \(\chi _{\phi }\) of \(H_{\phi }\) as follows. First assign to \(v_{0}\) the color red in \(\chi _{\phi }\). By construction, this coloring \(\chi _{\phi }\) will be one of the above \( 2^{8m}\cdot 2^{n+5m}\) proper \(3\)-colorings of \(G_{n,m}\). That is, for every \( i\in \{1,2,\ldots ,n+5m\}\), either all vertices of row \(\ell _{i}\) are red and all vertices of row \(\ell _{i}^{\prime }\) are green or blue in \(\chi _{\phi }\), or vice versa. For every \(i\in \{1,2,\ldots ,n+5m\}\), if the vertices of row \(\ell _{i}\) (resp. of row \(\ell _{i}^{\prime }\)) are red in \( \chi _{\phi }\), then we call row \(\ell _{i}\) (resp. row \(\ell _{i}^{\prime }\) ) a red line. Otherwise, if the vertices of row \(\ell _{i}\) (resp. of row \(\ell _{i}^{\prime }\)) are not red in \(\chi _{\phi }\), then we call row \( \ell _{i}\) (resp. row \(\ell _{i}^{\prime }\)) a white line. Furthermore, for every vertex \(u_{i,j}\) (resp. \(w_{i,j}\)) of a white line \( \ell _{i}\) (resp. of a white line \(\ell _{i}^{\prime }\)), the color of \( u_{i,j}\) (resp. of \(w_{i,j}\)) in \(\chi _{\phi }\) is uniquely determined by the color of its neighbor \(v_{j}\) in \(\chi _{\phi }\). That is, if \(v_{j}\) is blue then \(u_{i,j}\) (resp. \(w_{i,j}\)) is green in \(\chi _{\phi }\). Otherwise, if \(v_{j}\) is green then \(u_{i,j}\) (resp. \(w_{i,j}\)) is blue in \( \chi _{\phi }\).

Let \(x_{i}\) be an arbitrary variable in \(\phi \), where \(1\le i\le n\). If \( x_{i}=0\) in \(\tau \), we define row \(\ell _{i}\) to be a red line and row \( \ell _{i}^{\prime }\) to be a white line in \(\chi _{\phi }\), respectively. Otherwise, if \(x_{i}=1\) in \(\tau \), we define row \(\ell _{i}^{\prime }\) to be a red line and row \(\ell _{i}\) to be a white line in \(\chi _{\phi }\), respectively. Consider an arbitrary clause \(\alpha _{k}=(l_{k,1}\vee l_{k,2}\vee l_{k,3})\) of \(\phi \), where \(l_{k,p}\in \{x_{i_{k,p}},\overline{ x_{i_{k,p}}}\}\) for \(p\in \{1,2,3\}\). Furthermore consider the copy of the gadget of Fig. 3c that is associated to clause \( \alpha _{k}\) in \(H_{\phi }\). Recall by the construction of \(H_{\phi }\) that the literals \(l_{k,1}\), \(l_{k,2}\), and \(l_{k,3}\) correspond to the vertices \( g_{k,1}\), \(g_{k,2}\), and \(g_{k,3}\) of this gadget, respectively. Since \(\tau \) is a satisfying assignment of \(\phi \), at least one of the literals \( l_{k,1}\), \(l_{k,2}\), and \(l_{k,3}\) is true in \(\tau \). Therefore at least one of the vertices \(g_{k,1}\), \(g_{k,2}\), and \(g_{k,3}\) belongs to a white line in \(\chi _{\phi }\), i.e. at least one of them is green or blue in \(\chi _{\phi }\). If one (resp. two) of the vertices \(g_{k,1},g_{k,2},g_{k,3}\) belongs (resp. belong) to a red line of \(\chi _{\phi }\), then we color the other two (resp. the other one) green in \(\chi _{\phi }\). Otherwise, if all three of the vertices \(g_{k,1}\), \(g_{k,2}\), and \(g_{k,3}\) belong to a white line in \(\chi _{\phi }\), then we color \(g_{k,1},g_{k,2}\) green and vertex \( g_{k,3}\) blue in \(\chi _{\phi }\). For every \(p\in \{1,2,3\}\), if we color vertex \(g_{k,p}\) green (resp. blue) in \(\chi _{\phi }\), then we color its neighbor \(v_{8k+1-p}\) blue (resp. green) in \(\chi _{\phi }\), cf. the construction of the graph \(H_{\phi }\). Otherwise, if we color vertex \( g_{k,p} \) red in \(\chi _{\phi }\), then we color its neighbor \(v_{8k+1-p}\) either blue or green in \(\chi _{\phi }\) (both choices lead to a proper \(3\)-coloring of \(H_{\phi }\)).

Once we have colored the vertices \(g_{k,1},g_{k,2},g_{k,3}\) with two colors in total, we extend the coloring of these three vertices to a proper \(3\)-coloring \(\chi _{k}\) of the gadget associated to clause \(\alpha _{k}\) (cf. Observation 3). Let \(p\in \{4,5,6,7,8\}\). If \( g_{k,p} \) is colored green (resp. blue) in \(\chi _{k}\), then we color its neighbor \(v_{8k+1-p}\) blue (resp. green) in \(\chi _{\phi }\), and we define row \(\ell _{n+5k+4-p}\) to be a white line and row \(\ell _{n+5k+4-p}^{\prime }\) to be a red line in \(\chi _{\phi }\), respectively. Otherwise, if \(g_{k,p}\) is colored red in \(\chi _{k}\), then we define row \(\ell _{n+5k+4-p}\) to be a red line and row \( \ell _{n+5k+4-p}^{\prime }\) to be a white line in \(\chi _{\phi }\), respectively. Furthermore, in this case we color the neighbor \(v_{8k+1-p}\) of \(g_{k,p}\) either blue or green \(\chi _{\phi }\) (both choices lead to a proper \(3\) -coloring of \(H_{\phi }\)). After performing the above coloring operations for every clause \(\alpha _{k}\), where \(1\le k\le m\), we obtain a well defined coloring \(\chi _{\phi }\) of all vertices of \(H_{\phi }\). Note that in this coloring \(\chi _{\phi }\), all copies of the gadget of Fig. 3c are properly colored with \(3\) colors. Furthermore, by construction this coloring \(\chi _{\phi }\) is also a proper \(3\)-coloring of \(G_{n,m}\). Therefore \(\chi _{\phi }\) is a proper \(3\)-coloring of \(H_{\phi }\).

(\(\Leftarrow \)) Suppose now that \(H_{\phi }\) is \(3\)-colorable and let \(\chi _{\phi }\) be a proper \(3\)-coloring of \(H_{\phi }\). Assume without loss of generality that vertex \(v_{0}\) is colored red in \(\chi _{\phi }\). We will construct a satisfying assignment \(\tau \) of \(\phi \). Consider an index \( i\in \{1,2,\ldots ,n+5m\}\) and the rows \(\ell _{i}\) and \(\ell _{i}^{\prime }\) of the matrix. Suppose that \(\ell _{i}\) has at least one vertex \(u_{i,j_{1}}\) that is colored red and at least one vertex \(u_{i,j_{2}}\) that is colored blue in \(\chi _{\phi }\). Then clearly all vertices of \(\ell _{i}^{\prime }\), except possibly of \(w_{i,j_{1}}\) and \(w_{i,j_{2}}\), are colored green in \( \chi _{\phi }\), since they are adjacent to both \(u_{i,j_{1}}\) and \( u_{i,j_{2}}\). Therefore all vertices of \(\{v_{1},v_{2},\ldots ,v_{8m}\}{\setminus } \{v_{j_{1}},v_{j_{2}}\}\) are colored blue in \(\chi _{\phi }\). Thus, all vertices of \((U\cup W){\setminus } (U_{j_{1}}\cup U_{j_{2}}\cup W_{j_{1}}\cup W_{j_{2}})\) are colored either green or red in \(\chi _{\phi }\) . However there exists at least one copy of the gadget of Fig. 3c on these vertices, by the construction of \(H_{\phi } \). That is, this gadget has a proper coloring (induced by \(\chi _{\phi }\)) with the colors green and red. This is a contradiction by Observation 2. Thus, there exists no row \(\ell _{i}\) with at least one vertex colored red and another one colored blue in \(\chi _{\phi }\) . Similarly we can prove that there exists no row \(\ell _{i}\) (resp. \(\ell _{i}^{\prime }\)) with at least one vertex colored red and another one colored blue or green in \(\chi _{\phi }\). That is, if at least one vertex of a row \(\ell _{i}\) (resp. \(\ell _{i}^{\prime }\)) is colored red in \(\chi _{\phi }\), then all vertices of \(\ell _{i}\) (resp. \(\ell _{i}^{\prime }\)) are colored red in \(\chi _{\phi }\).

We will now prove that for any \(i\in \{1,2,\ldots ,n+5m\}\), at least one vertex of \(\ell _{i}\) or at least one vertex of \(\ell _{i}^{\prime }\) is red in \(\chi _{\phi }\). Suppose otherwise that every vertex of the rows \(\ell _{i}\) and \(\ell _{i}^{\prime }\) is colored either green or blue in \(\chi _{\phi }\). Then, since the vertices of \(\ell _{i}\) and of \(\ell _{i}^{\prime }\) induce a connected bipartite graph, it follows that all vertices of \(\ell _{i}\) are colored green and all vertices of \(\ell _{i}^{\prime }\) are colored blue in \(\chi _{\phi }\), or vice versa. Thus, in particular, for every \(j=1,2,\ldots ,8m\), vertex \(v_{j}\) is adjacent to one blue and to one green vertex (one from \(\ell _{i}\) and the other one from \(\ell _{i}^{\prime }\)). Thus, since \(\chi _{\phi }\) is a proper \(3\)-coloring of \(H_{\phi }\), it follows that \(v_{j}\) is colored red in \(\chi _{\phi }\). This is a contradiction, since \(v_{0}\in N(v_{j})\) and \(v_{0}\) is colored red in \(\chi _{\phi }\) by assumption. Therefore, for any \(i\in \{1,2,\ldots ,n+5m\}\), at least one vertex of \(\ell _{i}\) or at least one vertex of \(\ell _{i}^{\prime }\) is colored red in \(\chi _{\phi }\).

Summarizing, for every \({i\in \{1,2,\ldots ,n+5m\}}\), either all vertices of the row \(\ell _{i}\) or all vertices of the row \(\ell _{i}^{\prime }\) are colored red in \(\chi _{\phi }\). We define now the truth assignment \(\tau \) of \(\phi \) as follows. For every \({i\in \{1,2,\ldots ,n+5m\}}\), we set \({ x_{i}=0}\) in \(\tau \) if all vertices of \(\ell _{i}\) are colored red in \(\chi _{\phi }\); otherwise, if all vertices of \(\ell _{i}^{\prime }\) are colored red in \(\chi _{\phi }\), then we set \({x_{i}=1}\) in \(\tau \). We will prove that \(\tau \) is a satisfying assignment of \(\phi \). Consider a clause \( \alpha _{k}=(l_{k,1}\vee l_{k,2}\vee l_{k,3})\) of \(\phi \), where \(l_{k,p}\in \{x_{i_{k,p}},\overline{x_{i_{k,p}}}\}\) for \(p\in \{1,2,3\}\). By the construction of the graph \(H_{\phi }\), this clause corresponds to a copy of the gadget of Fig. 3c in \(H_{\phi }\). Thus, since \(\chi _{\phi }\) is a proper \(3\)-coloring of \(H_{\phi }\) by assumption, the vertices of this gadget are colored with three colors by Observation 2. Furthermore, not all three vertices \( g_{k,1},g_{k,2},g_{k,3}\) have the same color in \(\chi _{\phi }\) by Observation 3. Moreover, note by the construction of \(H_{\phi }\) and by the definition of the truth assignment \(\tau \), that \( l_{k,p}=0\) in \(\tau \) if and only if vertex \(g_{k,p}\) is colored red in \( \chi _{\phi }\), where \(p\in \{1,2,3\}\). Thus, since the vertices \( g_{k,1},g_{k,2},g_{k,3}\) are not all red in \(\chi _{\phi }\), it follows that the literals \(l_{k,1},l_{k,2},l_{k,3}\) of clause \(\alpha _{k}\) are not all false in \(\tau \). Therefore \(\alpha _{k}\) is satisfied by \(\tau \), and thus \( \tau \) is a satisfying truth assignment of \(\phi \). This completes the proof of the theorem.\(\square \)

The next theorem follows by Lemma 4 and Theorem 7.

Theorem 8

The \(3\)-coloring problem is NP-complete on irreducible and triangle-free graphs with diameter \(3\) and radius \(2\).

4.3 Time Complexity Lower Bounds and General NP-Completeness Results

In this section we present our three different amplification techniques of the reduction of Theorem 7. In particular, using these three amplifications we extend for every \({\varepsilon \in [0,1) }\) the result of Theorem 8 (by providing both NP-completeness and time complexity lower bounds) to irreducible triangle-free graphs with diameter \(3\) and radius \(2\) and minimum degree \({ \delta =\varTheta (n^{\varepsilon })}\). We use our first amplification technique in Theorems 9 and 11, our second one in Theorems 10 and 13, and our third one in Theorem 12.

Theorem 9

Let \({G=(V,E)}\) be an irreducible and triangle-free graph with diameter \(3\) and radius \(2\). If the minimum degree of \(G\) is \({\delta (G)=\varTheta (|V|^{\varepsilon })}\), where \({ \varepsilon \in [\frac{1}{2},1)}\), then it is NP-complete to decide whether \(G\) is \(3\)-colorable.

Proof

Let \(\phi \) be a boolean formula with \(n\) variables and \(m\) clauses. Using the reduction of Sect. 4.2, we construct from the formula \(\phi \) the irreducible and triangle-free graph \(H_{\phi }=(V_{\phi },E_{\phi })\) where \(H_{\phi }\) has diameter \(3\) and radius \(2\). Furthermore \(|V_{\phi }|=\varTheta (nm)\) by the construction of \(H_{\phi }\). Then, \(\phi \) is satisfiable if and only if \(H_{\phi }\) is \(3\)-colorable, by Theorem 7.

Let now \({\varepsilon \in [\frac{1}{2},1)}\). Define \(\varepsilon _{0}= \frac{\varepsilon }{1-\varepsilon }\) and \(k_{0}=m^{\varepsilon _{0}}\). Since \({\varepsilon \in [\frac{1}{2},1)}\) by assumption, it follows that \( \varepsilon _{0}\ge 1\). We construct now from the graph \(H_{\phi }\) the irreducible graph \(H_{1}(\phi ,\varepsilon )\) with diameter \(3\) and radius \(2 \), as follows. First we add \(8m\) new vertices \(v_{0,1},v_{0,2},\ldots ,v_{0,8m}\). For every vertex \(v_{j}\) in \(H_{\phi }\), where \(j\in \{1,2,\ldots ,8m\}\), we remove \(v_{j}\) and introduce \(2k_{0}\) new vertices \( A_{j}=\{v_{j,1}^{\prime },v_{j,2}^{\prime },\ldots ,v_{j,k_{0}}^{\prime }\}\) and \(B_{j}=\{v_{j,1}^{\prime \prime },v_{j,2}^{\prime \prime },\ldots ,v_{j,k_{0}}^{\prime \prime }\}\). The vertices of \(A_{j}\) and of \(B_{j}\) induce two independent sets in \(H_{1}(\phi ,\varepsilon )\). We then add between the vertices of \(A_{j}\) and of \(B_{j}\) all possible edges, except those of \(\{v_{j,p}^{\prime }v_{j,p}^{\prime \prime }:1\le p\le k_{0}\}\). That is, we add \(k_{0}^{2}-k_{0}\) edges between the vertices of \(A_{j}\) and \( B_{j}\), such that they induce a complete bipartite graph without a perfect matching between \(A_{j}\) and \(B_{j}\). Furthermore we add all \(k_{0}\) edges between \(v_{0}\) and the vertices of \(A_{j}\). Moreover we add all \( 2(n+5m)\cdot k_{0}\) edges between the \(2(n+5m)\) vertices of \(U_{j}\cup W_{j}\) (i.e. the \(j\)th column of the matrix arrangement of the vertices of \(U\cup V\)) and the \(k_{0}\) vertices of \(A_{j}\). Finally we add all \(k_{0}\) edges between \(v_{0,j}\) and the vertices of \(B_{j}\), as well as all \((8m-1)k_{0}\) edges between \(v_{0,j}\) and the vertices of \(A_{j^{\prime }}\), where \( j^{\prime }\in \{1,2,\ldots ,8m\}{\setminus } \{j\}\). Denote the resulting graph by \(H_{1}(\phi ,\varepsilon )\). The replacement of vertex \(v_{j}\) by the vertex sets \(A_{j}\) and \(B_{j}\) in \(H_{1}(\phi ,\varepsilon )\) is illustrated in Fig. 4.

Observe that, by this construction, for every \(j\in \{1,2,\ldots ,8m\}\), all neighbors of vertex \(v_{j}\) in the graph \(H_{\phi }\) are included in the neighborhood of every vertex \(v_{j,p}^{\prime }\) of \(A_{j}\) in the graph \( H_{1}(\phi ,\varepsilon )\), where \(1\le p\le k_{0}\). In particular, \( H_{\phi }\) is an induced subgraph of \(H_{1}(\phi ,\varepsilon )\): if we remove from \(H_{1}(\phi ,\varepsilon )\) the vertices of \((\{v_{0,j}\} \cup B_{j}\cup A_{j}){\setminus } \{v_{j,1}^{\prime }\}\), for every \(j\in \{1,2,\ldots ,8m\}\), we obtain a graph isomorphic to \(H_{\phi }\), where \(v_{j,1}^{\prime }\) of \( H_{1}(\phi ,\varepsilon )\) corresponds to vertex \(v_{j}\) of \(H_{\phi }\), for every \(j\in \{1,2,\ldots ,8m\}\). Note that, similarly to \(H_{\phi }\), the graph \(H_{1}(\phi , \varepsilon )\) has radius \(2\), since \(d(v_{0},u)\le 2\) in \(H_{1}(\phi ,\varepsilon )\) for every vertex \(u\) of \(H_{1}(\phi , \varepsilon )-\{v_{0}\}\).

We now prove that \(H_{1}(\phi ,\varepsilon )\) has diameter \(3\). First note that the distance between any two vertices of \(\cup _{j=1}^{8m}A_{j}\) is at most \(2\), since they all have \(v_{0}\) as common neighbor. Consider two arbitrary vertices \(a\in A_{j}\) and \(b\in B_{j^{\prime }}\), where \( j,j^{\prime }\in \{1,2,\ldots ,8m\}\). If \(j=j^{\prime }\) then either \(a\) and \(b\) are adjacent or there exists another vertex \(a^{\prime }\in A_{j}{\setminus } \{a\}\) such that \(a\) and \(b\) are connected with the path \( (b,a^{\prime },v_{0},a)\) of length \(3\). If \(j\ne j^{\prime }\) then \(a\) and \( b\) have \(v_{0,j}\) as a common neighbor, i.e. their distance is \(2\). Consider now two vertices \(b\in B_{j}\) and \(b^{\prime }\in B_{j^{\prime }}\). If \( j=j^{\prime }\) then \(b\) and \(b^{\prime }\) have \(v_{0,j}\) as a common neighbor, i.e. their distance is \(2\). If \(j\ne j^{\prime }\) then there exists at least one vertex \(a^{\prime }\in A_{j^{\prime }}\) such that \(b\) and \(b^{\prime }\) are connected with the path \((b,v_{0,j},a^{\prime },b^{\prime })\) of length \(3\). That is, the distance between any two vertices of \(\cup _{j=1}^{8m}A_{j}\cup _{j=1}^{8m}B_{j}\) is at most \(3\).

Consider an arbitrary vertex \(a\in \cup _{j=1}^{8m}A_{j}\) and an arbitrary vertex \(u_{i,j}\in U\) (resp. \(w_{i,j}\in W\)). If \(a\) and \(u_{i,j}\) (resp. \( w_{i,j}\)) are not adjacent in \(H_{1}(\phi ,\varepsilon )\), there exists the path \((a,v_{0},v_{j,1}^{\prime },u_{i,j})\) (resp. the path \( (a,v_{0},v_{j,1}^{\prime },w_{i,j})\)) of length \(3\) between \(a\) and \(u_{i,j}\) (resp. \(w_{i,j}\)). Consider an arbitrary vertex \(b^{\prime }\in B_{j^{\prime }}\) and an arbitrary vertex \(u_{i,j}\in U\) (resp. \(w_{i,j}\in W\)). If \( j=j^{\prime }\) then \(b^{\prime }\) and \(u_{i,j}\) (resp. \(w_{i,j}\)) have at least one common neighbor \(a^{\prime }\in A_{j^{\prime }}\), i.e. their distance is \(2\). If \(j\ne j^{\prime }\) then \(b^{\prime }\) and \(u_{i,j}\) (resp. \(w_{i,j}\)) are connected with the path \((b^{\prime },v_{0,j^{\prime }},v_{j,1}^{\prime },u_{i,j})\) (resp. the path \((b^{\prime },v_{0,j^{\prime }},v_{j,1}^{\prime },w_{i,j})\)) of length \(3\). That is, the distance between any vertex of \(\cup _{j=1}^{8m}A_{j}\cup _{j=1}^{8m}B_{j}\) and any vertex of \(U\cup W\) in \(H_{1}(\phi ,\varepsilon )\) is at most \(3\).

Fig. 4
figure 4

a The vertex \(v_{j}\) with its neighbors \(N(v_{j})=\{v_{0}\}\cup U_{j}\cup W_{j}\) in the graph \(H_{\phi }\) and b the vertex sets \( A_{j}\) and \(B_{j}\) that replace vertex \(v_{j}\) in the graph \(H_{1}( \phi ,\varepsilon )\); here \(j^{\prime }\) is an arbitrary index from \(\{1,2,\ldots ,8m\}{\setminus } \{j\}\)

Consider now an arbitrary vertex \(v_{0,j}\). This vertex has every vertex of \( A_{j^{\prime }}\), where \(j^{\prime }\in \{1,2,\ldots ,8m\}{\setminus } \{j\}\), as common neighbors with \(v_{0}\), i.e. \(d(v_{0,j},v_{0})=2\). Furthermore, for every \(j^{\prime }\in \{1,2,\ldots ,8m\}{\setminus } \{j\}\), there exists the path \((v_{0,j},v_{j,2}^{\prime \prime },v_{j,1}^{\prime },v_{0,j^{\prime }})\) of length \(3\) between the vertices \(v_{0,j}\) and \(v_{0,j^{\prime }}\). Note that, by construction of \(H_{1}(\phi ,\varepsilon )\), the distance between \(v_{0,j}\) and every vertex of \(\cup _{j=1}^{8m}A_{j}\cup _{j=1}^{8m}B_{j}\) is at most \(2\). Thus, since every vertex of \(U\cup W\) is adjacent to at least one vertex of \(\cup _{j=1}^{8m}A_{j}\), it follows that the distance between \(v_{0,j}\) and every vertex of \(U\cup W\) is at most \(3\). Finally, since \(H_{\phi }\) is an induced subgraph of \(H_{1}(\phi , \varepsilon )\), it follows by Lemma 2 that also \( d(z,z^{\prime })\le 3\) in \(H_{1}(\phi ,\varepsilon )\), for every pair of vertices \(z,z^{\prime }\in U\cup W\). Therefore \(H_{1}(\phi , \varepsilon )\) has diameter \(3\).

Recall now that for every \(j\in \{1,2,\ldots ,8m\}\), vertex \(v_{j}\) of \( H_{\phi }\) has been replaced by the vertices of \(A_{j}\cup B_{j}\) in \( H_{1}(\phi ,\varepsilon )\). Furthermore, recall that the vertices of \( A_{j}\cup B_{j}\) induce in \(H_{1}(\phi ,\varepsilon )\) a complete bipartite graph without a perfect matching between \(A_{j}\) and \(B_{j}\). Therefore there exists no pair of sibling vertices in \(A_{j}\cup B_{j}\), for every \( j\in \{1,2,\ldots ,8m\}\). Similarly there exists no pair of sibling vertices among \(\{v_{0},v_{0,1},v_{0,2},\ldots ,v_{0,8m}\}\). Furthermore it can be easily checked that \(H_{1}(\phi ,\varepsilon )\) has no triangles, and thus it has no diamonds. Thus, since \(H_{\phi }\) is irreducible by Lemma 4, it follows that \(H_{1}(\phi , \varepsilon )\) is irreducible as well.

We now prove that \(H_{1}(\phi ,\varepsilon )\) is \(3\)-colorable if and only if \(H_{\phi }\) is \(3\)-colorable. Suppose first that \(H_{1}(\phi ,\varepsilon )\) is \(3\)-colorable. Then, since \(H_{\phi }\) is an induced subgraph of \( H_{1}(\phi ,\varepsilon )\), it follows immediately that \(H_{\phi }\) is also \( 3\)-colorable. Now suppose that \(H_{\phi }\) is \(3\)-colorable, and let \(\chi \) be a proper \(3\)-coloring of \(H_{\phi }\). Assume without loss of generality that \(v_{0}\) is colored red in \(\chi \). We will extend \(\chi \) into a proper \(3\)-coloring of \(H_{1}(\phi ,\varepsilon )\) as follows. First we color all vertices \(\{v_{0,1},v_{0,2},\ldots ,v_{0,8m}\}\) red. Consider the vertex \( v_{j}\) of \(H_{\phi }\), where \(1\le j\le 8m\). Since \(v_{0}\) is colored red in \(\chi \), it follows that \(v_{j}\) is colored either blue or green in \(\chi \). If \(v_{j}\) is colored green in \(\chi \), then we color in \(H_{1}(\phi ,\varepsilon )\) all vertices of \(A_{j}\) green and all vertices of \(B_{j}\) blue. Otherwise, if \(v_{j}\) is colored blue in \(\chi \), then we color in \( H_{1}(\phi ,\varepsilon )\) all vertices of \(A_{j}\) blue and all vertices of \( B_{j}\) green. It is now straightforward to check that the resulting \(3\)-coloring of \(H_{1}(\phi ,\varepsilon )\) is proper, i.e. that \(H_{1}(\phi ,\varepsilon )\) is \(3\)-colorable. That is, \(H_{1}(\phi ,\varepsilon )\) is \(3\) -colorable if and only if \(H_{\phi }\) is \(3\)-colorable. Therefore Theorem 7 implies that the formula \(\phi \) is satisfiable if and only if \(H_{1}(\phi ,\varepsilon )\) is \(3\)-colorable.

By construction, the graph \(H_{1}(\phi ,\varepsilon )\) has \(N={2({n+5m} )8m+8m\cdot 2k_{0}+8m+1}\) vertices, where \(k_{0}=m^{\varepsilon _{0}}\). Thus, since \(m=\varOmega (n)\) and \(\varepsilon _{0}\ge 1\), it follows that \( N=\varTheta (m^{1+\varepsilon _{0}})\). Therefore \(m=\varTheta (N^{\frac{1}{ 1+\varepsilon _{0}}})\), where \(N\) is the number of vertices in \(H_{1}(\phi ,\varepsilon )\). Furthermore, the degree of each of the vertices \( \{v_{0},v_{0,1},v_{0,2},\ldots ,v_{0,8m}\}\) in \(H_{1}(\phi ,\varepsilon )\) is \({\varTheta (m\cdot k_{0})=\varTheta (m^{1+\varepsilon _{0}})}\), the degree of every vertex \(v_{j,p}^{\prime }\) in \(H_{1}(\phi ,\varepsilon )\) is \({\varTheta (n+m+k_{0})=\varTheta (m^{\varepsilon _{0}})}\), the degree of every vertex \( v_{j,p}^{\prime \prime }\) in \(H_{1}(\phi ,\varepsilon )\) is \(\varTheta (k_{0})=\varTheta (m^{\varepsilon _{0}})\), and the degree of every vertex \( u_{i,j}\) (resp. \(w_{i,j}\)) in \(H_{1}(\phi ,\varepsilon )\) is \(\varTheta (m+k_{0})=\varTheta (m^{\varepsilon _{0}})\). Therefore the minimum degree of \( H_{1}(\phi ,\varepsilon )\) is \(\delta =\varTheta (m^{\varepsilon _{0}})\). Thus, since \({m=\varTheta (N^{\frac{1}{1+\varepsilon _{0}}})}\), it follows that \( \delta =\varTheta (N^{\frac{\varepsilon _{0}}{1+\varepsilon _{0}}})\), i.e. \( \delta =\varTheta (N^{\varepsilon })\).

Summarizing, for every \({\varepsilon \in [\frac{1}{2},1)}\) and for every formula \(\phi \) with \(n\) variables and \(m\) clauses, we can construct in polynomial time a graph \(H_{1}(\phi ,\varepsilon )\) with \({N=\varTheta (m^{1+\varepsilon _{0}})}\) (i.e. \(N={\varTheta (m^{\frac{1}{1-\varepsilon }})}\)) vertices and minimum degree \(\delta =\varTheta (m^{\varepsilon _{0}})\) (i.e. \( {\delta ={\varTheta (N^{\varepsilon })}}\)), such that \(H_{1}(\phi ,\varepsilon ) \) is \(3\)-colorable if and only if \(\phi \) is satisfiable. Moreover, the constructed graph \(H_{1}(\phi ,\varepsilon )\) is irreducible and triangle-free, and it has diameter \(3\) and radius \(2\). This completes the proof of the theorem.\(\square \)

In the next theorem we provide an amplification of the reduction of Theorem 7 to the case of graphs with minimum degree \({ \delta =\varTheta (|V|^{\varepsilon })}\), where \({\varepsilon \in [0, \frac{1}{2})}\).

Theorem 10

Let \({G=(V,E)}\) be an irreducible and triangle-free graph with diameter \(3\) and radius \(2\). If the minimum degree of \(G\) is \({\delta (G)=\varTheta (|V|^{\varepsilon })}\), where \({ \varepsilon \in [0,\frac{1}{2})}\), then it is NP-complete to decide whether \(G\) is \(3\)-colorable.

Proof

Let \(G_{1}=(V_{1},E_{1})\) be an arbitrary irreducible and triangle-free graph with diameter \(3\) and radius \(2\), such that \(G_{1}\) has \(n\) vertices and minimum degree \(\delta (G_{1})=\varTheta (\sqrt{n})\). Note that such a graph \(G_{1}\) exists by the construction of \(H_{\phi }\) in Sect. 4.2 (see also Theorems 7 and 9). For simplicity, we arbitrarily enumerate the vertices of \(G_{1}\) as \(v_{1},v_{2},\ldots ,v_{n}\) . Let \({\varepsilon \in [0,\frac{1}{2})}\). Define \(\varepsilon _{0}= \frac{\varepsilon }{1-\varepsilon }\) and \(k_{0}=n^{\varepsilon _{0}}\). Since \({\varepsilon \in [0,\frac{1}{2})}\) by assumption, it follows that \( \varepsilon _{0}\in [0,1)\). We now construct from the graph \(G_{1}\) the irreducible graph \(G_{2}(\varepsilon )\) with diameter \(3\) and radius \(2\) as follows. First we introduce \(n+1\) new vertices \(v_{0},v_{0,1},v_{0,2}, \ldots ,v_{0,n}\). For every \(i\in \{1,2,\ldots ,n\}\), we add \(2k_{0}\) new vertices \(A_{i}=\{v_{i,1}^{\prime },v_{i,2}^{\prime },\ldots ,v_{i,k_{0}}^{\prime }\}\) and \(B_{i}=\{v_{i,1}^{\prime \prime },v_{i,2}^{\prime \prime },\ldots ,v_{i,k_{0}}^{\prime \prime }\}\). The vertices of \(A_{i}\) and of \(B_{i}\) induce two independent sets in \( G_{2}(\varepsilon )\). We then add between the vertices of \(A_{i}\) and of \( B_{i}\) all possible edges, except those of \(\{v_{i,\ell }^{\prime }v_{i,\ell }^{\prime \prime }:1\le \ell \le k_{0}\}\). That is, we add \(k_{0}^{2}-k_{0} \) edges between the vertices of \(A_{i}\) and \(B_{i}\), such that they induce a complete bipartite graph without a perfect matching between \(A_{i}\) and \( B_{i}\). Moreover we add all \(k_{0}\) edges between \(v_{i}\) and the vertices of \(A_{i}\), as well as all \(k_{0}\) edges between \(v_{0}\) and the vertices of \(A_{i}\). Finally we add all \(k_{0}\) edges between \(v_{0,i}\) and the vertices of \(B_{i}\), as well as all \((n-1)k_{0}\) edges between \(v_{0,i}\) and the vertices of \(A_{i^{\prime }}\), where \(i^{\prime }\in \{1,2,\ldots ,n\}{\setminus } \{i\}\). Denote the resulting graph by \(G_{2}(\varepsilon )\).

Observe that, by construction, \(G_{1}\) is an induced subgraph of \( G_{2}(\varepsilon )\). Furthermore, \(G_{2}(\varepsilon )\) has \(N=n+n\cdot 2k_{0}+n+1\) vertices, and thus \(N=\varTheta (n^{1+\varepsilon _{0}})\). Therefore \(n=\varTheta (N^{\frac{1}{1+\varepsilon _{0}}})\), where \(N\) is the number of vertices in \(G_{2}(\varepsilon )\). Furthermore, the degree of each of the vertices \(\{v_{0}, v_{0,1},v_{0,2},\ldots ,v_{0,n}\}\) in \(G_{2}(\varepsilon ) \) is \({\varTheta (n\cdot k_{0})=\varTheta (n^{1+\varepsilon _{0}})}\), the degree of every vertex \(v_{i,\ell }^{\prime }\) in \(G_{2}(\varepsilon )\) is \({\varTheta (n+k_{0})=\varTheta (n)}\), the degree of every vertex \(v_{i,\ell }^{\prime \prime }\) in \(G_{2}(\varepsilon )\) is \({\varTheta (k_{0})=\varTheta (n} ^{\varepsilon _{0}}{)}\), and the degree of every vertex \(v_{i}\in V_{1}\) in \( G_{2}(\varepsilon )\) is at least \(\delta (G_{1})+k_{0}=\varTheta (\sqrt{n}+n{ ^{\varepsilon _{0}}})\). Therefore, for every \(\varepsilon _{0}\in [0,1)\), the minimum degree of \(G_{2}(\varepsilon )\) is \(\delta =\varTheta ({ n^{\varepsilon _{0}}})\). Thus, since \(n=\varTheta (N^{\frac{1}{1+\varepsilon _{0}}})\), it follows that \(\delta =\varTheta (N^{\frac{\varepsilon _{0}}{ 1+\varepsilon _{0}}})\), i.e. \(\delta =\varTheta (N^{\varepsilon })\). Note that the graph \(G_{2}(\varepsilon )\) has radius \(2\), since \( d(v_{0},u)\le 2\) in \(G_{2}(\varepsilon )\) for every vertex \(u\) of \( G_{2}(\varepsilon )-\{v_{0}\}\).

We now prove that \(G_{2}(\varepsilon )\) has diameter \(3\). First note that the distance between any two vertices of \( \cup _{i=1}^{n}A_{i}\) is at most \(2\), since they all have \(v_{0}\) as common neighbor. Consider two arbitrary vertices \(a\in A_{i}\) and \(b\in B_{i^{\prime }}\), where \(i,i^{\prime }\in \{1,2,\ldots ,n\}\). If \( i=i^{\prime }\) then either \(a\) and \(b\) are adjacent or there exists another vertex \(a^{\prime }\in A_{i}{\setminus } \{a\}\) such that \(a\) and \(b\) are connected with the path \((b,a^{\prime },v_{0},a)\) of length \(3\). If \(i\ne i^{\prime }\) then \(a\) and \(b\) have \(v_{0,i}\) as a common neighbor, i.e. their distance is \(2\). Consider now two vertices \(b\in B_{i}\) and \(b^{\prime }\in B_{i^{\prime }}\). If \(i=i^{\prime }\) then \(b\) and \(b^{\prime }\) have \( v_{0,i}\) as a common neighbor, i.e. their distance is \(2\). If \(i\ne i^{\prime }\) then there exists at least one vertex \(a^{\prime }\in A_{i^{\prime }}\) such that \(b\) and \(b^{\prime }\) are connected with the path \((b,v_{0,i},a^{\prime },b^{\prime })\) of length \(3\). That is, the distance between any two vertices of \(\cup _{i=1}^{n}A_{i}\cup _{i=1}^{n}B_{i}\) is at most \(3\).

Consider an arbitrary vertex \(v_{i}\in V_{1}\) and an arbitrary vertex \(a\in A_{i}\). If \(i=i^{\prime }\) then \(v_{i}\) is adjacent with \(a\) in \( G_{2}(\varepsilon )\). Otherwise, if \(i\ne i^{\prime }\), there exists the path \((a,v_{0},v_{i,1}^{\prime },v_{i})\) of length \(3\) between \(a\) and \(v_{i} \). Consider an arbitrary vertex \(v_{i}\in V_{1}\) and an arbitrary vertex \( b^{\prime }\in B_{i^{\prime }}\). If \(i=i^{\prime }\) then \(b^{\prime }\) and \( v_{i}\) have at least one common neighbor \(a^{\prime }\in A_{i^{\prime }}\), i.e. their distance is \(2\). If \(i\ne i^{\prime }\) then \(b^{\prime }\) and \( v_{i}\) are connected with the path \((b^{\prime },v_{0,i^{\prime }},v_{i,1}^{\prime },v_{i})\) of length \(3\). That is, the distance between any vertex of \(\cup _{i=1}^{n}A_{i}\cup _{i=1}^{n}B_{i}\) and any vertex of \( V_{1}\) in \(G_{2}(\varepsilon )\) is at most \(3\).

Consider now an arbitrary vertex \(v_{0,i}\). Similarly to the proof of Theorem 9, \(v_{0,i}\) has every vertex of \(A_{i^{\prime }}\) as a common neighbor with \(v_{0}\), where \( i^{\prime }\in \{1,2,\ldots ,n\}{\setminus } \{i\}\). That is, \( d(v_{0,i},v_{0})=2\). Furthermore, for every \(i^{\prime }\in \{1,2,\ldots ,n\}{\setminus } \{i\}\), there exists the path \((v_{0,i},v_{i,2}^{\prime \prime },v_{i,1}^{\prime },v_{0,i^{\prime }})\) of length \(3\) between the vertices \( v_{0,i}\) and \(v_{0,i^{\prime }}\). Note that, by construction of \( G_{2}(\varepsilon )\), the distance between \(v_{0,i}\) and every vertex of \( \cup _{i=1}^{n}A_{i}\cup _{i=1}^{n}B_{i}\) is at most \(2\). Thus, since every vertex of \(V_{1}\) is adjacent to at least one vertex of \(\cup _{i=1}^{n}A_{i} \), it follows that the distance between \(v_{0,i}\) and every vertex of \(V_{1}\) is at most \(3\). Finally, since \(G_{1}\) is an induced subgraph of \( G_{2}(\varepsilon )\) and \(G_{1}\) has diameter \(3\) by assumption, it follows that also \(d(z,z^{\prime })\le 3\) in \(G_{2}(\varepsilon )\) for every pair of vertices \(z,z^{\prime }\in V_{1}\). Therefore \(G_{2}(\varepsilon )\) has diameter \(3\).

Recall that for every \(i\in \{1,2,\ldots ,n\}\) the vertices of \(A_{i}\cup B_{i}\) induce in \(G_{2}(\varepsilon )\) a complete bipartite graph without a perfect matching between \(A_{i}\) and \(B_{i}\). Therefore there exists no pair of sibling vertices in \(A_{i}\cup B_{i}\), for every \(i\in \{1,2,\ldots ,n\}\). Similarly there exists no pair of sibling vertices among \(\{v_{0},v_{0,1},v_{0,2},\ldots ,v_{0,n}\}\). Furthermore it can be easily checked that \(G_{2}(\varepsilon )\) has no triangles, and thus it has no diamonds. Thus, since \(G_{1}\) is irreducible by assumption, it follows that \( G_{2}(\varepsilon )\) is irreducible as well.

We now prove that \(G_{2}(\varepsilon )\) is \(3\)-colorable if and only if \( G_{1}\) is \(3\)-colorable. If \(G_{2}(\varepsilon )\) is \(3\)-colorable, then clearly \(G_{1}\) is also \(3\)-colorable, since \(G_{1}\) is an induced subgraph of \(G_{2}(\varepsilon )\). Now suppose that \(G_{1}\) is \(3\)-colorable, and let \(\chi \) be a proper \(3\)-coloring of \(G_{1}\) that uses the colors red, blue, and green. We will extend \(\chi \) into a proper \(3\)-coloring \(\chi ^{\prime } \) of \(G_{2}(\varepsilon )\) as follows. Consider the vertex \(v_{i}\in V_{1}\), where \(1\le i\le n\). If \(v_{i}\) is colored red or blue in \(\chi \), then we color all vertices of \(A_{i}\) green and all vertices of \(B_{i}\) blue in \( \chi ^{\prime }\). Otherwise, if \(v_{i}\) is colored green in \(\chi \), then we color all vertices of \(A_{i}\) blue and all vertices of \(B_{i}\) green in \( \chi ^{\prime }\). Finally, we color all vertices \(\{v_{0},v_{0,1},v_{0,2}, \ldots ,v_{0,n}\}\) red in \(\chi ^{\prime }\). It is now straightforward to check that the resulting \(3\)-coloring \(\chi ^{\prime }\) of \( G_{2}(\varepsilon )\) is proper, i.e. that \(G_{2}(\varepsilon )\) is \(3\)-colorable. That is, \(G_{2}(\varepsilon )\) is \(3\)-colorable if and only if \( G_{1}\) is \(3\)-colorable.

Summarizing, for every irreducible graph \(G_{1}\) with diameter \(3\) and radius \(2\), such that \(G_{1}\) has \(n\) vertices and minimum degree \(\delta (G_{1})=\varTheta (\sqrt{n})\), we can construct in polynomial time a graph \( G_{2}(\varepsilon )\) with \({N=\varTheta (n^{1+\varepsilon _{0}})}\) (i.e. \(N={ \varTheta (n^{\frac{1}{1-\varepsilon }})}\)) vertices and minimum degree \({ \delta ={\varTheta (N^{\varepsilon })}}\), such that \(G_{2}(\varepsilon )\) is \(3\)-colorable if and only if \(G_{1}\) is \(3\)-colorable. Moreover, the constructed graph \(G_{2}(\varepsilon )\) is irreducible and has diameter \(3\) and radius \(2\). This completes the proof of the theorem, since it is NP-complete to decide whether \(G_{1}\) is \(3\)-colorable by Theorem 9.\(\square \)

Therefore, Theorems 9 and 10 imply that, for every \( \varepsilon \in [0,1)\), the \(3\)-coloring problem remains NP-complete for irreducible and triangle-free graphs \(G=(V,E)\) with diameter \(3\) and radius \(2\), where the minimum degree \({\delta (G)}\) is \({\varTheta (|V|^{\varepsilon })}\). However, Theorems 9 and 10 do not provide any information about how efficiently (although not polynomially, assuming P\( \ne \)NP) we can decide \(3\)-coloring on such graphs. We provide in the next three theorems subexponential lower bounds for the time complexity of \(3\)-coloring on irreducible and triangle-free graphs with diameter \(3\) and radius \(2\). Moreover, the lower bounds provided in Theorem 11 are asymptotically almost tight, due to the algorithm of Theorem 6.

Theorem 11

Let \(\varepsilon \in [\frac{1}{2},1)\). Assuming ETH, there exists no algorithm with running time \(2^{o\left( \frac{N}{ \delta }\right) }=2^{o\left( N^{1-\varepsilon }\right) }\) for \(3\)-coloring on irreducible and triangle-free graphs \(G\) with diameter \(3\), radius \(2\), and \(N\) vertices, where the minimum degree of \(G\) is \(\delta (G)=\varTheta (N^{\varepsilon })\).

Proof

Let \(\varepsilon \in [\frac{1}{2},1)\) and define \(\varepsilon _{0}= \frac{\varepsilon }{1-\varepsilon }\). In the reduction of Theorem 9, given the value of \( \varepsilon \) and a boolean formula \(\phi \) with \(n\) variables and \(m\) clauses, we constructed a graph \(H_{1}(\phi ,\varepsilon )\) with \({N=\varTheta (m^{1+\varepsilon _{0}})}\) vertices and minimum degree \(\delta =\varTheta (m^{\varepsilon _{0}})\). Therefore \(\delta =\varTheta (N^{\frac{\varepsilon _{0} }{1+\varepsilon _{0}}})\), i.e. \(\delta =\varTheta (N^{\varepsilon })\). Furthermore the graph \(H_{1}(\phi ,\varepsilon )\) is by construction irreducible and triangle-free, and it has diameter \(3\) and radius \(2\). Moreover \(\phi \) is satisfiable if and only if \(H_{1}(\phi ,\varepsilon )\) is \(3\)-colorable by Theorem 9.

Suppose now that there exists an algorithm \(\mathcal {A}\) that, given an irreducible triangle-free graph \(G\) with \(N\) vertices, diameter \(3\), radius \( 2\), and minimum degree \(\delta =\varTheta (N^{\varepsilon })\) for some \( \varepsilon \in [\frac{1}{2},1)\), decides \(3\)-coloring on \(G\) in time \(2^{o\left( \frac{N}{\delta }\right) }\). Then \(\mathcal {A}\) decides \(3\)-coloring on input \(G=H_{1}(\phi ,\varepsilon )\) in time \(2^{o\left( \frac{N}{\delta }\right) }=2^{o(m)}\). However, since the formula \(\phi \) is satisfiable if and only if \(H_{1}(\phi ,\varepsilon )\) is \(3\)-colorable, algorithm \(\mathcal {A}\) can be used to decide the \(3\)SAT problem in time \(2^{o(m)}\), where \(m\) is the number of clauses in the given boolean formula \(\phi \). Thus \(\mathcal {A}\) can decide \( 3\)SAT in time \(2^{o(m)}\). This is a contradiction by Theorem 1, assuming ETH. This completes the proof of the theorem. \(\square \)

Theorem 12

Let \({\varepsilon \in [\frac{1}{3},} \frac{1}{2}{)}\). Assuming ETH, there exists no algorithm with running time \({ 2^{o(\delta )}=2^{o\left( N^{\varepsilon }\right) }}\) for \(3\)-coloring on irreducible and triangle-free graphs \(G\) with diameter \(3\), radius \(2\), and \(N\) vertices, where the minimum degree of \(G\) is \(\delta (G)=\varTheta (N^{\varepsilon })\).

Proof

We provide for the purposes of the proof an amplification of the reduction of Theorem 7. In Sect. 4.2, given a boolean formula \(\phi \) with \(n\) variables and \(m\) clauses, we constructed the graph \(H_{\phi }\), which is irreducible and triangle-free by Lemma 4. By its construction in Sect. 4.2, the graph \(H_{\phi }\) has \({\varTheta (m^{2})}\) vertices. Furthermore, the degree of vertex \(v_{0}\) in \(H_{\phi }\) is \({\varTheta (m)}\). The degree of every vertex \(v_{j}\) in \(H_{\phi }\) is \({\varTheta (n+m)=\varTheta (m)}\), where \(j\in \{1,2,\ldots ,8m\}\). Finally, the degree of every vertex \( u_{i,j}\) (resp. \(w_{i,j}\)) in \(H_{\phi }\) is \(\varTheta (m)\), where \(i\in \{1,2,\ldots ,n+5m\}\) and \(j\in \{1,2,\ldots ,8m\}\). Therefore the minimum degree of \(H_{\phi }\) is \(\delta =\varTheta (m)\).

Let \({\varepsilon \in [\frac{1}{3},}\frac{1}{2}{)}\) and define \( \varepsilon _{0}=\frac{1}{\varepsilon }-2\). Note that \(\varepsilon _{0}\in (0,1]\), since \({\varepsilon \in [\frac{1}{3},}\frac{1}{2}{)}\). We construct now from \(H_{\phi }\) a graph \(H_{2}(\phi ,\varepsilon )\) as follows. Consider the rows \(\ell _{i}\) and \(\ell _{i}^{\prime }\) of the matrix arrangement of the vertices \(U\cup W\) of \(H_{\phi }\), where \(i\in \{1,2,\ldots ,n+5m\}\). For every \(i\in \{1,2,\ldots ,n+5m\}\), we extend row \( \ell _{i}\) by new \((m^{1+\varepsilon _{0}}-8m)\) vertices \( \{u_{i,8m+1},u_{i,8m+2},\ldots ,u_{i,m^{1+\varepsilon _{0}}}\}\). Denote the resulting row of the matrix with the \(m^{1+\varepsilon _{0}}\) vertices \( \{u_{i,1},u_{i,2},\ldots ,u_{i,m^{1+\varepsilon _{0}}}\}\) by \(\widehat{\ell _{i}}\). Similarly, we extend row \(\ell _{i}^{\prime }\) by new \( (m^{1+\varepsilon _{0}}-8m)\) vertices \(\{w_{i,8m+1},w_{i,8m+2},\ldots ,w_{i,m^{1+\varepsilon _{0}}}\}\). Denote the resulting row of the matrix with the \(m^{1+\varepsilon _{0}}\) vertices \(\{w_{i,1},w_{i,2},\ldots ,w_{i,m^{1+\varepsilon _{0}}}\}\) by \(\widehat{\ell _{i}^{\prime }}\). Furthermore, add all necessary edges between vertices of \(\widehat{\ell _{i}} \) and of \(\widehat{\ell _{i}^{\prime }}\), such that they induce a complete bipartite graph without a perfect matching. For simplicity of notation, denote by \(U^{\prime }={ \{u_{i,j}:1\le i\le n+5m,1\le j\le m^{1+\varepsilon _{0}}\}}\) and \({W} ^{\prime }{=\{w_{i,j}:1\le i\le n+5m,1\le j\le m^{1+\varepsilon _{0}}\}}\) the vertex sets that extend the sets \(U\) and \(W\), respectively. Moreover, similarly to the notation of Sect. 4.2, denote \( U_{j}^{\prime }=\{u_{1,j},u_{2,j},\ldots ,u_{n+5m,j}\}\) and \(W_{j}^{\prime }=\{w_{1,j},w_{2,j},\ldots ,w_{n+5m,j}\}\), for every \(j\in \{1,2,\ldots ,m^{1+\varepsilon _{0}}\}\). Then, the vertices of \(U_{j}^{\prime }\cup W_{j}^{\prime }\) contain the vertices of the \(j\)th column in the (updated) matrix arrangement of the vertices of \(U^{\prime }\cup W^{\prime }\). Similarly to the construction of the graph \(H_{\phi }\) (cf. Sect. 4.2), we add for every \(j\in \{8m+1,8m+2,\ldots ,m^{1+\varepsilon _{0}}\}\) a vertex \(v_{j}\) that is adjacent to \( U_{j}^{\prime }\cup W_{j}^{\prime }\cup \{v_{0}\}\). Denote the resulting graph by \({H_{2}(\phi ,\varepsilon )}\).

Now, following exactly the same argumentation as in the proof of Lemma 4 and Theorem 7, we can prove that: (a) \(H_{2}(\phi ,\varepsilon )\) has diameter \(3\) and radius \(2\), (b) \( H_{2}(\phi ,\varepsilon )\) is irreducible and triangle-free, and (c) the formula \(\phi \) is satisfiable if and only if \(H_{2}(\phi ,\varepsilon )\) is \(3\)-colorable.

By the above construction, the graph \(H_{2}(\phi ,\varepsilon )\) has \( N=2(n+5m)\cdot m^{1+\varepsilon _{0}}+m^{1+\varepsilon _{0}}+1\) vertices. Thus, since \(m=\varOmega (n)\), it follows that \(N=\varTheta (m^{2+\varepsilon _{0}})\). Furthermore, the degree of vertex \(v_{0}\) in \(H_{2}(\phi ,\varepsilon )\) is \({\varTheta (m^{1+\varepsilon _{0}})}\). The degree of every vertex \(v_{j}\) in \(H_{2}(\phi ,\varepsilon )\) is \({\varTheta (n+m)=\varTheta (m)}\) , where \(j\in \{1,2,\ldots ,{m^{1+\varepsilon _{0}}}\}\). Finally, the degree of every vertex \(u_{i,j}\) (resp. \(w_{i,j}\)) in \(H_{2}(\phi ,\varepsilon )\) is \(\varTheta ({m^{1+\varepsilon _{0}}})\), where \(i\in \{1,2,\ldots ,n+5m\}\) and \(j\in \{1,2,\ldots ,{m^{1+\varepsilon _{0}}}\}\). Thus the minimum degree of \(H_{2}(\phi ,\varepsilon )\) is \(\delta =\varTheta (m)\). Therefore, since \( N=\varTheta (m^{2+\varepsilon _{0}})\), it follows that \(\delta =\varTheta (N^{ \frac{1}{2+\varepsilon _{0}}})=\varTheta (N^{\varepsilon })\), where \(N\) is the number of vertices in the graph \(H_{2}(\phi ,\varepsilon )\).

Suppose now that there exists an algorithm \(\mathcal {A}\) that, given an irreducible triangle-free graph \(G\) with \(N\) vertices, diameter \(3\), radius \( 2\), and minimum degree \(\delta =\varTheta (N^{\varepsilon })\) for some \( \varepsilon \in {[\frac{1}{3},}\frac{1}{2}{)}\), decides \(3\)-coloring on \(G\) in time \(2^{o(\delta )}\). Then \(\mathcal {A}\) decides \(3\)-coloring on input \( G=H_{2}(\phi ,\varepsilon )\) in time \(2^{o(\delta )}=2^{o(m)}\). However, since the formula \(\phi \) is satisfiable if and only if \(H_{2}(\phi ,\varepsilon )\) is \(3\)-colorable, algorithm \(\mathcal {A}\) can be used to decide the \(3\)SAT problem in time \(2^{o(m)}\), where \(m\) is the number of clauses in the given boolean formula \(\phi \). Therefore \(\mathcal {A}\) can decide \(3\)SAT in time \(2^{o(m)}\). This is a contradiction by Theorem 1, assuming ETH. This completes the proof of the theorem. \(\square \)

Theorem 13

Let \({\varepsilon \in [0,\frac{1}{3})}\). Assuming ETH, there exists no algorithm with running time \({2^{o\left( \sqrt{ \frac{N}{\delta }}\right) }=2^{o\left( N^{\left( \frac{1-\varepsilon }{2}\right) }\right) }}\) for \(3\)-coloring on irreducible and triangle-free graphs \(G\) with diameter \(3\), radius \(2\), and \(N\) vertices, where the minimum degree of \(G\) is \(\delta (G)=\varTheta (N^{\varepsilon })\).

Proof

Let \(\varepsilon \in [0,\frac{1}{3})\) and define \(\varepsilon _{0}= \frac{\varepsilon }{1-\varepsilon }\). In the reduction of Theorem 10, given the value of \( \varepsilon \) and an irreducible graph \(G_{1}\) with diameter \(3\) and radius \( 2\) such that \(G_{1}\) has \(n\) vertices and minimum degree \({\delta (G_{1})=\varTheta (\sqrt{n})}\), we constructed an irreducible graph \( G_{2}(\varepsilon )\) with \({N=\varTheta (n^{1+\varepsilon _{0}})}\) vertices and minimum degree \({\delta =\varTheta (n^{\varepsilon _{0}})}\). Therefore \(\delta =\varTheta (N^{\frac{\varepsilon _{0}}{1+\varepsilon _{0}}})\), i.e. \(\delta =\varTheta (N^{\varepsilon })\). Furthermore the graph \({G_{2}(\varepsilon )}\) has by construction diameter \(3\) and radius \(2\). Moreover \(G_{1}\) is \(3\)-colorable if and only if \(G_{2}(\varepsilon )\) is \(3\)-colorable by Theorem 10.

Suppose now that there exists an algorithm \(\mathcal {A}\) that, given an irreducible triangle-free graph \(G\) with \(N\) vertices, diameter \(3\), radius \( 2\), and minimum degree \(\delta =\varTheta (N^{\varepsilon })\) for some \( \varepsilon \in [0,\frac{1}{3})\), decides \(3\)-coloring on \(G\) in time \(2^{o\left( \sqrt{\frac{N}{\delta }}\right) }\). Then \(\mathcal {A}\) decides \(3\)-coloring on input \(G=G_{2}(\varepsilon )\) in time \(2^{o\left( \sqrt{\frac{N}{\delta }} \right) }=2^{o(\sqrt{n})}\). However, since \(G_{1}\) is \(3\)-colorable if and only if \( G_{2}(\varepsilon )\) is \(3\)-colorable, algorithm \(\mathcal {A}\) can be used to decide \(3\)-coloring of \(G_{1}\) in time \(2^{o(\sqrt{n})}\), where \(n\) is the number of vertices in the given graph \(G_{1}\). This is a contradiction by Theorem 11, assuming ETH. This completes the proof of the theorem.\(\square \)

5 Concluding Remarks

In this paper we investigated graphs with small diameter, i.e. with diameter at most \(2\), and at most \(3\). For graphs with diameter at most \(2\), we provided the first subexponential algorithm for \(3\)-coloring, with complexity \(2^{O(\sqrt{n\log n})}\). This time complexity is asymptotically the same as the currently best known complexity for the graph isomorphism (GI) problem [4]. Thus, as the \(3\)-coloring problem on graphs with diameter \(2\) has been neither proved to be polynomially solvable nor to be NP-complete, it would be worthwhile to investigate whether this problem is polynomially reducible to/from the GI problem. Furthermore we presented a subclass of graphs with diameter \(2\) that admits a polynomial algorithm for \(3\)-coloring. An interesting open problem for further research is to establish the time complexity of \(3\)-coloring on arbitrary graphs with diameter \(2\). Moreover, the complexity of \(3\)-coloring remains open also for triangle-free graphs of diameter \(2\), or equivalently, on maximal triangle-free graphs.

For graphs with diameter at most \(3\), we established the complexity of \(3\)-coloring, even for triangle-free graphs, which has been an open problem. Namely we proved that for every \({\varepsilon \in [0,1)}\), \( 3 \)-coloring is NP-complete on triangle-free graphs of diameter \(3\) and radius \(2\) with \(n\) vertices and minimum degree \(\delta =\varTheta (n^{\varepsilon })\). Moreover, assuming the ETH, we provided three different amplification techniques of our hardness results, in order to obtain for every \({\varepsilon \in [0,1)}\) subexponential asymptotic lower bounds for the complexity of \(3\)-coloring on triangle-free graphs with diameter \(3\), radius \(2\), and minimum degree \({ \delta =\varTheta (n^{\varepsilon })}\). Finally, we provided a \(3\)-coloring algorithm with running time \({2^{O\left( \min \{\delta \varDelta ,\ \frac{n}{\delta } \log \delta \}\right) }}\) for arbitrary graphs with diameter \(3\), where \(n\) is the number of vertices and \(\delta \) (resp. \(\varDelta \)) is the minimum (resp. maximum) degree of the input graph. Due to our lower bounds, the running time of this algorithm is asymptotically almost tight, when the minimum degree if the input graph is \(\delta =\varTheta (n^{\varepsilon })\), where \(\varepsilon \in [\frac{1}{2},1)\). An interesting problem for further research is to find asymptotically matching lower bounds for the complexity of \(3\)-coloring on graphs with diameter \(3\), for all values of minimum degree \(\delta \).