1 Introduction

Throughout this article, we consider simple graphs. Let G be a graph with vertex set V(G) and edge set E(G). If two vertices u and v are adjacent in G, we denote it by \(u\sim v\). An independent set in G is a set of pairwise non-adjacent vertices in it. An independent set with cardinality m is called an m-independent set. Let \(i_m=i_m(G)\) be the number of m-independent sets in G. The independence polynomial of G (Gutman and Harary, [9]) is defined as \(I_G(z)=i_0 + i_1 z + i_2 z^2+\cdots +i_\alpha z^{\alpha }\), where \(\alpha =\alpha (G)\) is the cardinality of a largest independent set. The number \(\alpha \) is called the independence number of the graph G. Indeed, more than one independent set with cardinality \(\alpha \) are possible. Note that, for any graph G, \(i_0=1\), \(i_1\) is the number of vertices in G and \(i_{\alpha } \ne 0\). The reduced independence polynomial of G is defined as \(i_1 z + i_2 z^2+\cdots +i_\alpha z^{\alpha }\) and is denoted by \(\mathbf{f}_G(z)\). The roots of independence polynomials have been studied by many researchers. In [6], Brown et al. have found a family of graphs for which the roots of independence polynomials are dense in \((-\infty , 0]\). Further, classes of graphs have been constructed with roots of their independence polynomials dense in \({\mathbb {C}}\). It has been proved in [7] that the roots of the independence polynomials of clawfree graphs are real. It is also known that the root of an independence polynomial with the smallest modulus is a negative real number [8]. Another important aspect is to characterize nonisomorphic graphs with the same independence polynomial. Any two such graphs are called independence equivalent. In [10], Zhang has constructed the independence equivalent graphs for general simple graphs and also mentioned some properties concerning the independence polynomial of paths and cycles.

Let \(G \cup H\) denote the disjoint union of two graphs G and H. It is known [1, 9] that \(I_{G\cup H}(z)=I_G(z)I_H(z)\). Given two graphs G and H, the lexicographic product (or composition) of G with H, denoted by G[H], is defined as the graph with vertex set \(V(G[H])=V(G) \times V(H)\). Two vertices (uv) and \((u^{\prime }, v^{\prime })\) in V(G[H]) are adjacent in G[H] if and only if either \(u\sim u^{\prime }\) in G, or \(u=u^{\prime }\) and \(v\sim v^{\prime }\) in H. This amounts to replacing each vertex of G with a copy of H and joining two vertices of two different copies according to the adjacency of vertices of G. The k-times lexicographic product of a graph G with itself is denoted by \(G^k\). The set of roots of \(I_{G^k}\) is finite and hence a compact subset of the complex plane \({\mathbb {C}}\) for each k. The sequence of roots of \(I_{G^k}\) is known to converge as k tends to \(\infty \), with respect to the Hausdorff metric defined on the set of all compact subsets of \({\mathbb {C}}\). The limiting set is usually a fractal and is referred by Brown et al. [5] as the independence attractor of the concerned graph. Let it be denoted by \({\mathcal {A}}(G)\). Similarly, the independence fractal of a graph G is defined as the limiting set of the set of roots of the reduced independence polynomial \(\mathbf{f}_{G^k}\) as k tends to \(\infty \). It is denoted by F(G). The Julia set of a polynomial P, denoted by \({\mathcal {J}}(P)\), is the boundary of the set of all points z such that its forward orbit \(\{z,P(z),P^{2}(z),\cdots \}\) is bounded. Though a number of equivalent definitions of Julia set of a polynomial are available in the literature, the one we have just stated is sufficient for the purpose. The following result has been established in [5].

Theorem 1.1

For every graph G, \(F(G) ={\mathcal {J}}(\mathbf{f}_G)\).

This is a nontrivial and important link between the iterative behavior of the reduced independence polynomial and the limit set of roots of \(\mathbf{f}_{G^k}\). In [5], Brown et al. have also established a connection between the independence attractor and the independence fractal of a nonempty (with at least one edge) graph. More specifically, it is proved that \({\mathcal {A}}(G)=F(G)\) whenever \(-1\) is either not a root of \(I_G(z)\) or is a simple root of \(I_G(z)\). In all other cases, \({\mathcal {A}}(G)\supset F(G)\) and is the closure of \(\bigcup _{k \ge 1} \mathbf{f}_{G}^{-k}(-1)\). Independence fractals of paths, cycles, wheels and certain trees are investigated by Alikhani and Peng [1].

Independence fractals of connected graphs are not necessarily connected (with respect to the standard topology of the extended complex plane). In fact, for every graph G with independence number at least 2, the independence fractal of \(G[K_n]\) is disconnected for sufficiently large n (see [5]), where \(K_n\) is the complete graph on n vertices. Note that, \(G[K_n]\) is connected if and only if G is connected. The independence fractals of connected graphs can also be connected. This follows from Theorem 3.4 which is proved in the current article. On the other hand, the independence fractal of \(mK_n\), m disjoint copies of \(K_n\) is connected when \(n=2\) and m is even (whereas it is totally disconnected for all other natural numbers m and n) [5]. In view of all these possibilities, characterizing all graphs with connected independence fractals seems to be nontrivial. Exploiting the Mandelbrot set, Brown et al. [5] completely settle this issue for graphs with independence number 2. They state that the methods shall not work for graphs with higher independence numbers. We deal with graphs with independence number 3. All such graphs whose independence fractal is a line segment, one of the simplest possible connected independence fractals, are described.

Some preliminary ideas including Mantel’s theorem are presented in Sect. 2. The general form of a cubic polynomial that qualifies to be the independence polynomial of a graph with independence number 3 and whose independence fractal is a line segment is found to be \(I^k (z)=1+ 9 z+ 6k z^2 +k^2 z\) for \(k=1, 2, 3, 4, 5\) (Theorem 2.2). The case \(k=5\) is actually not possible (Theorem 3.1 and Theorem 4.1), and the aforesaid line segment indeed turns out to be \([-\frac{4}{k}, 0]\) for \(k=1, 2, 3, 4\). The proof exploits a connection to the well-known Chebyshev polynomials. The last case \(k=4\) is possible only when G is disconnected. Further, it is proved that the independence fractal of such a graph coincides with its independence attractor (Theorem 2.1). These are the contents of Sect. 2. Connected graphs whose independence fractal is a line segment are found in Sect. 3. It is shown that there are no connected graphs whose independence polynomial is \(I^5(z)\) (Theorem 3.1) or \(I^4(z)\) (Theorem 3.2). For \(k=3, 2\), we are able to show existence in terms of particular types of examples. For \(k=2\), an algorithm is provided to construct all such graphs. It is shown that there are exactly 17 connected graphs for \(k=1\) (Theorem 3.4). Section 4 determines all the 13 disconnected graphs (Theorem 4.1). The independence polynomials of such graphs are found to be either \(I^2(z)\) or \(I^4(z)\).

Given a vertex v in G, the open neighborhood of v, denoted by N(v), is the set of all vertices of G that are adjacent to v. Note that v is not in the open neighborhood of itself. The degree of v, denoted by d(v), is the number of edges incident on v. This is precisely the cardinality of N(v). The closed neighborhood of v, denoted by N[v], is the union of N(v) and \(\{v\}\). A vertex v of a graph is called a pendant vertex if \(d(v)=1\). For a set S, the cardinality of S is denoted by |S|.

2 Preliminaries

A graph which does not contain a \(K_3\) as a subgraph is known as a triangle free graph. The total number of edges in a triangle free graph is going to be useful and we present a well-known result on it, the Mantel’s theorem [4]. For a real number x, the floor function \( {\lfloor }x{\rfloor }\) denotes the largest integer not exceeding x.

2.1 Mantel’s Theorem (1907)

If a simple graph with \(n \ge 2\) vertices is triangle free, then it has at most \(\frac{n^2}{4}\) edges. Such a graph has exactly \( \left\lfloor {\frac{n^2}{4}}\right\rfloor \) edges if and only if it is a complete bipartite graph \(K_{n_1, n_2}\), where \(n_1, n_2\) are as follows:

(i):

if n is even, then \(n_1=n_2= \frac{n}{2}\),

(ii):

if n is odd, then \(n_1=\frac{n+1}{2}\) and \(n_2 =\frac{n-1}{2}\).

The Chebyshev polynomial of degree d is defined recursively as

$$\begin{aligned} T_{d+1}(z)=2z T_d (z)-T_{d-1}(z), \end{aligned}$$

where \(T_0 (z)=1\) and \(T_1 (z)=z\). For example, \(T_2 (z)=2 z^2 -1\) and \(T_3 (z)=4 z^3 - 3 z\). An important aspect of these polynomials is demonstrated by the following well-known result. A proof can be found in [2]. A subset E of \({\mathbb {C}}\cup \{\infty \}\) is called completely invariant under a polynomial P if \(P(E)\subseteq E\) and \(P^{-1}(E)\subseteq E\).

Theorem 2.1

Suppose that T is a polynomial (with complex coefficients) of degree d, where \( d \ge 2\). Then, the interval \([-1,1]\) is completely invariant under T if and only if T is \(T_d\) or \(-T_d\).

The Chebyshev polynomial of third degree is of interest to us. Let \(\pm T_3\) denote \(T_3\) or \(-T_3\). Following lemma determines all possible cubic reduced independence polynomials whose independence fractal is a line segment.

Theorem 2.2

The independence fractal of a graph with independence number 3 is a line segment if and only if the reduced independence polynomial of the graph is \(9 z+6 k z^2+k^2 z^3\) for some \(k\in \{1,2,3,4,5\}\).

Proof

Let G be a graph with \(\alpha (G)=3\) and \(\mathbf{f}_G(z)=i_1 z + i_2 z^2 +i_3 z^3\). If the independence fractal F(G) is a line segment L, then the Julia set of \(\mathbf{f}_G\) is L by Theorem 1.1. It follows from Theorem 3.2.4 of [2] that L is completely invariant under \(\mathbf{f}_G\), that is, \(\mathbf{f}_G(L) \subseteq L\) and \(\mathbf{f}_G^{-1}(L) \subseteq L\).

Let the midpoint, length and the angle of inclination with the positive real axis of L be denoted by \(z_0\), l and \(\theta \), respectively. Then, \(\phi (z)=az+b \) maps \([-1,1]\) onto L, where \(a=\frac{l}{2}e^{i\theta }\) and \(b=z_0\). Thus, \(\phi ^{-1}( \mathbf{f}_G(\phi ))\) is a cubic polynomial which keeps \([-1,1]\) completely invariant. Now, it follows from Theorem 2.1 that \(\phi ^{-1}( \mathbf{f}_G(\phi )) = \pm T_3 \). The coefficients of \(\mathbf{f}_G\) remain to be determined for completing the proof.

Since \(i_3 \ne 0\), it follows that \(i_2 \ne 0\) and \(i_1 \ne 0\). Further, \(\pm T_3(z)=\frac{\mathbf{f}_G(az+b)-b}{a} \). Differentiating both sides once and putting \(z=0\), we get that \(\mathbf{f}_G'(b)=3\) or \(-3\). Similarly, it follows by differentiating both sides twice and putting \(z=0\) that \(\mathbf{f}_G''(b)=0\). This means that,

$$\begin{aligned} i_1 +2i_2 b+3i_3 b^2=\pm 3 \text{ and } b=\frac{-i_2}{3i_3}\ne 0. \end{aligned}$$

Thus, we have

$$\begin{aligned} i_1 -\frac{i_2 ^{2}}{3 i_3}=\pm 3. \end{aligned}$$
(1)

Since the constant term in the Chebyshev polynomial of degree 3 is 0, it follows that \(\mathbf{f}_G(b)=b\). In other words, \(i_1 b+i_2 b^2 +i_3 b^3=b\). Since \(b \ne 0\), we get \(i_1 +i_2 b +i_3 b^2=1\), which after putting the value of b gives that

$$\begin{aligned} \frac{i_2 ^2}{3 i_3} =\frac{3 (i_1 -1)}{2}. \end{aligned}$$
(2)

Putting this in Equation (1), it is seen that \( i_{1} = -3 \) or 9. Clearly, the first possibility cannot be true giving that \( i_1 = 9\). Thus, the graph G must have 9 vertices and it follows from Equation (2) that \(i_2^2=36 i_3\). Since \(i_2 \le \left( {\begin{array}{c}9\\ 2\end{array}}\right) =36\), \(i_3 \le 36\). Further, \(i_2=36 \) would mean \(i_3=36\). But, in this case G has no edge giving that \(i_3 = \left( {\begin{array}{c}9\\ 3\end{array}}\right) = 84\) which is a contradiction. Therefore, \(i_2 < 36\). Since \(i_3\) needs to be a perfect square of an integer and is smaller than 36, \(i_3 \in \{1, 4, 9, 16, 25\}\) and the corresponding values of \(i_2\) will be 6, 12, 18, 24 and 30, respectively. Hence, \(\mathbf{f}_G(z)=\mathbf{f}^k_G(z):=9 z+6 k z^2+k^2 z^3\) for some \(k\in \{1,2,3,4,5\}\).

Conversely, if \(\mathbf{f}_G(z)=\mathbf{f}^k_G(z)\) for some \(k\in \{1,2,3,4,5\}\), then \(\mathbf{f}^k_G(z)\) is conjugate to \(T_3 (z)=4z^3-3z\) via \(\phi _k(z)=\frac{2}{k}(z-1)\). More precisely, \(T_3 (z)=\phi _{k}^{-1}{} \mathbf{f}^k_G(\phi _k (z))\) for all z and for all \(k\in \{1,2,3,4,5\}\). The proof now follows from Theorem 2.1. \(\square \)

It is important to note that the Julia set of each \(\mathbf{f}^k_G(z)=9 z+6kz^2 +k^2 z^3\) is a line segment. Indeed, the Julia set of \(\mathbf{f}^k_G\) is \(\phi _{k}([-1,1])\) which is nothing but \([-\frac{4}{k},0]\). Further, the independence fractals coincide with the independence attractors as given below.

Corollary 2.1

If the independence fractal of a graph with independence number 3 is a line segment, then its independence attractor and independence fractal coincide.

Proof

Let \(\mathbf{f}^k_G\) be the reduced independence polynomial of a graph G, with independence number 3 and let \(I^k_G(z)=1+\mathbf{f}^k_G(z)\) be its independence polynomial. Then, \(I^k_G(-1)=-8+6 k-k^2=0\) only when \(k=2\) or 4. Since \({I^k_G}'(-1)=-3~\text{ or }~9\) for these k’s, \(-1\) is a simple root of \(I^k_G(z)\). Thus, the point \(-1\) is either not a root or a simple root of \(I^k_G\) for \(k=1, 2, 3, 4, 5\). It now follows from the previous Theorem and Remark 2 of [5] that the independence attractor and the independence fractal coincide whenever the later is a line segment for a graph with independence number 3. \(\square \)

3 Connected Graphs

This section is devoted to determine connected graphs whose independence fractals are line segments. It is seen in the previous section that any graph whose independence fractal is a line segment must have \(\mathbf{f}^k_G(z)\) as its reduced independence polynomial for some \(k \in \{1,2,3,4,5\}\). Note that all such graphs are with 9 vertices.

3.1 No Graphs When \(k=5\) and 4

The following theorem deals with the case \(k=5\).

Theorem 3.1

There is no connected graph whose independence polynomial is \(1+ 9z + 30 z^2 +25 z^3\).

Proof

Suppose that there is a connected graph G whose independence polynomial is \(1+ 9z +30 z^2 +25 z^3\). Since G is connected and has 9 vertices, G has at least 8 edges. However, since \(i_2=30\), G has 6 edges. This is a contradiction, and the proof completes. \(\square \)

A subgraph of a graph G induced by a subset S of V(G) is a graph with vertex set S and with the edges of G whose end vertices are in S. We denote the complement graph of G by \(G^c\). For a vertex v of a graph G, let \(B_{3[v]}(G)\) denote the set of all 3-independent sets in G containing v and \(i_{3[v]}(G)=|B_{3[v]}(G)|.\) In order to deal with the case \(k=4\), the following lemma is needed.

Lemma 3.1

If G is a connected graph and \(I_G(z)=1+ 9z + 24 z^2 +16 z^3\), then G does not have any pendant vertex.

Proof

Suppose that G has a pendant vertex. Let it be \(v_1\) and \(v_1 \sim v_2\). If H is the subgraph of G induced by \(V(G) \setminus \{v_1, v_2\}\), then H has seven vertices and does not have any 3-independent set. Therefore, \(H^c\) has seven vertices and does not contain any triangle. By Mantel’s theorem, \(H^c\) has at most 12 edges. In other words, H has at least \(\left( {\begin{array}{c}7\\ 2\end{array}}\right) -12=9\) edges. Since G is connected, there is an edge in G joining \(v_2\) with a vertex of H. In other words, \(d(v_2) \ge 2\). Since \(12= |E(G)|=|E(H)|+d(v_2)\), \(d(v_2) \le 3\).

If \(d(v_2) = 3\), then it follows from the Mantel’s theorem (applied to \(H^c\)) that H has exactly 9 edges and \(H=K_{4,3}^c\). In other words, H is the disjoint union of \(K_4 \) and \(K_3\). In this case, since G is connected, \(v_2\) is adjacent to a vertex of \(K_3\) as well as to a vertex of \(K_4\). Consequently, \(i_{3[v_1]}(G)=12\) and \(i_{3[v_2]}(G)=6\). However, the total number of 3-independent sets in G is 16.

If \(d(v_2)=2\), then the subgraph H induced by \(V(G) \setminus \{v_1, v_2\} \) must have 10 edges. Thus, \(i_{3[v_1]}(G)= i_{2}(H)=\left( {\begin{array}{c}7\\ 2\end{array}}\right) -10=11\). Further, \(i_{3[v_2]}(G)\) is the number of 2-independent sets in the subgraph induced by \(V(H) \setminus \{v_3\}\), where \(v_2 \sim v_3\). This number is at least \(\left( {\begin{array}{c}6\\ 2\end{array}}\right) -9=6\) which gives that \(i_3(G)= i_{3[v_1]}(G)+i_{3[v_2]}(G)\ge 17\). This is a contradiction proving that G does not have any pendant vertex. \(\square \)

For two non-adjacent vertices uv of a graph G, let N(uv) denote the set of all vertices of G which are adjacent either to u or to v and \(N[u,v]=N(u,v)\cup \{u,v\}\). Also, let \(i_{3[u,v]}(G)\) denote the number of 3-independent sets in G containing u and v.

Theorem 3.2

There is no connected graph whose independence polynomial is \(1+ 9z + 24 z^2 +16 z^3\).

Proof

If G is a connected graph such that \(I_G(z)=1+ 9z + 24 z^2 +16 z^3\), then it has 9 vertices, 12 edges, \( i_3(G)=16\) and there are no 4-independent set in G. By Lemma 3.1, there is no pendant vertex in G. Since

$$\begin{aligned} \sum _{v\in V(G)}d(v)=2|E(G)|=24 \end{aligned}$$

and \(|V(G)|=9\), there must be at least three vertices of degree 2 in G. If these three vertices are mutually adjacent, then G becomes disconnected. Therefore, at least two of them are non-adjacent. Suppose that \(u,v\in V(G)\) such that \(u\not \sim v\) and \(d(u)=d(v)=2\).

Let \(u_1, u_2 \in N(u)\) and \(H_u\) be the subgraph of G induced by \(V(G)\setminus N[u]\). Now, \(H_u\) has 6 vertices and \(i_3(H_u) = 0\). Applying Mantel’s theorem to the complement of \(H_u\), it is found that \(H_u\) has at least \(\left( {\begin{array}{c}6\\ 2\end{array}}\right) -9=6\) edges. Since G is connected and is without any pendant vertex, \(|E(H_u)| \in \{6,7,8\}\). Similarly, it can be seen that \(|E(H_v)| \in \{6,7,8\}\), where \(H_v\) is the subgraph G induced by \(V(G)\setminus N[v]\). The number of elements in the set \(N(u)\cap N(v)\) can only be 0, 1 or 2. The proof will be complete by obtaining contradictions in each of these cases.

Case 1:

Suppose that \(|N(u)\cap N(v)|=0\). Then, there is a triangle with vertices in \(V(G)\setminus N[u,v]\). Let the vertices of this triangle be \(w_1, w_2\) and \( w_3\). Further, this triangle is a subgraph of \(H_u\) as well as of \(H_v\) and \(\{w_1, w_2, w_3 \} = H_u \cap H_v\). Since \(|E(G)|=12\), the sum of edges in \(H_u\) and \(H_v\) is 15. In view of the discussion in the previous paragraph, one of \(H_v\) and \(H_u\) has 8 edges and the other has 7 edges. Without loss of generality suppose that \(|E(H_u)|=8\) and \(|E(H_v)|=7\). In other words, \(i_{3[u]}(G)=15-8=7\) and \(i_{3[v]}(G)=15-7=8\). Since there are exactly three 3-independent sets containing both u and v (namely, \(\{u, w_1, v\}, \{u, w_2, v\}\) and \(\{u, w_3, v\}\)), \(|B_{3[u] }\cup B_{3[v]}|=12\). Let \(V_{u,v}\) denote \(V(G) \setminus \{u, v\}\). Since \( i_3(G)=16\), the number of 3-independent sets in \(V_{u,v}\) is exactly 4, that is,

$$\begin{aligned} i_3(G)-i_{3[u]}(G)-i_{3[v]}(G)+i_{3[u,v]}(G)=4. \end{aligned}$$
(3)

Further, \(|E(H_v)|=7\). There is an edge joining a vertex from \(\{u_1, u_2\}\) and a vertex from \(\{w_1, w_2, w_3\}\). Without loss of generality, assume that \(u_1 \sim w_1\). If the other edge of \(H_v\) is not between \(u_1, u_2\) then it will be between \(u_2\) and one of \(w_1, w_2, w_3\) which will lead to a 4-independent set containing \(v, u_1, u_2 \) and the \(w_i\) which is neither adjacent to \(u_1\) nor to \(u_2\). Thus, \(u_1 \sim u_2\).

Suppose that \(v_1, v_2 \in N(v)\). Note that G has no 4-independent set. So, if \(v_1 \not \sim v_2\) then, each \(w_i\) is adjacent either to \(v_1\) or to \(v_2\). Since \(|E(H_u)|=8\), one of \(v_i\), say \(v_1\) is adjacent to two vertices of \(\{w_1, w_2, w_3\}\), say to \(w_1\) and to \(w_2\) and then \(v_2\) will be adjacent to \(w_3\). Thus, \(v_1 \sim w_1, v_1 \sim w_2\), \(v_2 \sim w_3\) and the graph is as given in Fig. 1a. The 3-independent sets in \(V_{u,v}\) are

$$\begin{aligned}&\{v_1, w_3, u_1\}, \{v_1, w_3, u_2\}, \{v_2, w_1, u_2\}, \{v_2, w_2, u_1\}, \{v_2, w_2, u_2\}, \\&\quad \{v_1, v_2, u_1\}, \{v_1, v_2, u_2\}. \end{aligned}$$

However, this contradicts (3).

Suppose that \(v_1 \sim v_2\). If both \(v_1, v_2\) are adjacent to \(w_1\), then any one of \(\{u_1, u_2\}\), one of \(\{w_2, w_3\}\) and one of \(\{v_1, v_2\}\) form a 3-independent set in \(V_{u,v}\), and there are 8 such choices. This gives that the number of 3-independent sets in \(V_{u,v}\) is 8 which is not true in view of (3). If both \(v_1, v_2\) are adjacent to \(w_i, i \ne 1\), then it can be observed that the number of 3-independent sets in \(V_{u,v}\) is 6, which again contradicts (3).

Let \(v_1\) and \( v_2\) be adjacent to two different vertices of \(\{w_1,w_2 ,w_3\}\) and the other \(w_j\) be adjacent neither to \(v_1\) nor to \(v_2\). If \(j =1\) then, without loss of generality assume that \(v_1 \sim w_2\) and \(v_2 \sim w_3\). The resulting graph is shown in Fig. 1e, and there are six 3-independent sets in \(V_{u,v}\), namely, \( \{ u_1, w_2, v_2\}, \{ u_1, w_3, v_1\}, \{ u_2, w_1, v_1\}, \{ u_2, w_1, v_2\}, \{ u_2, w_2, v_2\}\) and \(\{ u_2, w_3, v_1\}.\) However, this is not possible by (3). If \(j \ne 1\) then, assume without loss of generality that \(v_1 \sim w_1\) and \(v_2 \sim w_3\) and the graph is given in Fig. 1d. Now, the 3-independent sets in \(V_{u,v}\) are

$$\begin{aligned}&\{ u_1, w_2, v_1\}, \{ u_1, w_2, v_2\}, \{ u_1, w_3, v_1\}, \{ u_2, w_1, v_2\}, \{ u_2, w_2, v_1\}, \\&\quad \{ u_2, w_2, v_2\}, \{ u_2, w_3, v_1\}, \end{aligned}$$

which contradicts (3).

Now, consider the case when exactly one \(v_i\), say \(v_1\) is adjacent to two vertices of \(\{w_1, w_2, w_3\}\). Then, one \(w_k\) is not adjacent to \(v_1\). If \(k=2\), then the graph is given in Fig. 1b. For each \(i, j \in \{1,2\}\), \( \{u_i, w_2, v_j\} \) is a 3-independent set in \(V_{u,v}\). In view of (3), there are no other 3-independent set in \(V_{u,v}\). But \( \{ u_1, w_3, v_2\}\) is such a set and (3) is contradicted. Similar contradiction shall arise for \(k=3\). If \(k=1\), then \(v_1 \sim w_2\) and \(v_1 \sim w_3\) and the graph is given in Fig. 1c. All the 3-independent sets in \(V_{u,v}\) are \(\{ u_1, w_2, v_2\}, \{ u_1, w_3, v_2\}, \{ u_2, w_1, v_1\}, \{ u_2, w_1, v_2\}, \{ u_2, w_2, v_2\}\) and \(\{ u_2, w_3, v_2\},\) which contradicts (3).

Case 2:

If \(N(u) \cap N(v)\) is singleton, then \(V(G) \setminus N[u,v]\) has four vertices \(\{w_1, w_2, w_3, w_4\}\). Since G has no 4-independent set, each pair of these vertices must be adjacent in G. Let \(v_1 \in N(u) \cap N(v)\). Further, suppose that \(u_1\sim u\), \(u_1\ne v_1\) and \(v_2\sim v\), \(v_2\ne v_1\).

Let \(v_1 \not \sim u_1\). If \(u_1 \sim v_2\), then one of \(w_i\)’s is adjacent to a vertex from \(\{v_1,v_2,u_1\}\). Each of these 12 choices gives rise to the same graph, up to isomorphism. Without loss of generality, assume that \(w_1 \sim v_2\) and the graph is as given in Fig. 2a. But in this case, \(i_{3[u,v]}(G)=4, i_{3[u,v_2]}(G)=3, i_{3[v,u_1]}(G)=4,i_{3[v_1,v_2]}(G)=3\) and \(i_{3[u_1,v_1]}(G)=4\). This gives that \(i_3(G) \ge 18\), a contradiction to the fact that \(i_3(G)=16\). If \(u_1\not \sim v_2\), then it is adjacent to one of the \(w_i\)’s giving rise to a 4-independent set containing \(u_1,v_1\) and \(v_2\).

If \(v_1\sim u_1\), then the graph is as given in Fig. 2b. We have \(i_{3[u,v]}(G)=4, i_{3[u,v_2]}(G)=3, i_{3[u_1,v]}(G)=4, i_{3[u_1,v_2]}(G)=3\) and \(i_{3[v_1,v_2]}(G)=3\). In other words, \(i_3(G) \ge 17\), which is a contradiction to \(i_3(G)=16\).

Case 3:

Let \(N(u) \cap N(v)\) have two elements. Then, each pair of vertices in \(V(G) \setminus N[u,v]\) must be adjacent in order to avoid a 4-independent set containing uv. Thus, there is a \(K_5\) on \(V(G) \setminus N[u,v]\). However, this gives that G has at least 14 edges contradicting \(|E(G)|=12\).

\(\square \)

Fig. 1
figure 1

Some possible graphs when \(|N(u)\cap N(v)|=0\)

Fig. 2
figure 2

Possible graphs when \(|N(u) \bigcap N(v)|=1\)

3.2 Graphs Exist When \(k=3\) and 2

The case \(k=3\) is different from earlier situations in the sense that there do exist connected graphs whose independence polynomial is \(1+ 9z +18 z^2 +9 z^3\). Though there are many such graphs (computationally found to be 2601 using maple), we are providing here examples showing that the vertices can have all possible degrees.

Consider the graphs in Fig. 3. All are with independence polynomial \(1+ 9z +18 z^2 +9 z^3.\) Further, observe that there are vertices with degrees 3, 4 and 5 in the first graph, the second graph has a vertex with degree 8 and also has a vertex with degree 2, the third graph has a vertex with degree 7 as well as a vertex with degree 1, and the fourth graph has a vertex with degree 6. Hence, for each \(1 \le j \le 8\) there is a connected graph with a vertex of degree j whose independence polynomial is \(1+ 9z +18 z^2 +9 z^3\).

Fig. 3
figure 3

Some graphs with independence polynomial \(1+ 9z +18 z^2 +9 z^3\)

Note that the second graph has vertex with maximum degree, that is, 8. It can be shown that there are exactly four such graphs. To prove this, we need to know the graphs whose independence polynomial is \(1+nz+18 z^2+9 z^3\) for \(n=7, 8\). The following two lemmas deal with this.

Lemma 3.2

There is no graph whose independence polynomial is \(1+7z+18 z^2+9 z^3\).

Proof

If there is a graph H with independence polynomial \(1+7z+18 z^2+9 z^3\), then it has 7 vertices and 3 edges. Thus, it is disconnected.

Since the independence number of H is 3, it has at most three components. Let it have 3 components \(H_1, H_2\) and \(H_3\). Then, the independence polynomial of each component is linear. Suppose that \(I_{H_i}(z)=1+n_i z\) for \( i=1, 2, 3\). Since \(I_{H}(z)=I_{H_1}(z)I_{H_2}(z)I_{H_3}(z)\), we have

$$\begin{aligned} n_1 +n_2+n_3=7,\;\; n_1n_2n_3=9 \text{ and } n_1n_2+n_2n_3+n_1n_3=18. \end{aligned}$$

The possible values for \((n_1, n_2, n_3)\) satisfying the first two equations are \((3,3,1), (1,3,3),\) and (3, 1, 3). But, none of these satisfies the third equation.

If H has two components, then the independence polynomial of one component is linear and that of the other is quadratic. Let these polynomials be \(1+n_1 z\) and \(1+n_2 z+mz^2\). Then, \(n_1 m=9, n_1 +n_2=7\) and \(n_1n_2+m=18\). The possible values of \((n_1, n_2, m)\) satisfying the first two equations are (1, 6, 9) and (3, 4, 3). However, none of these satisfies the third equation proving that there is no graph whose independence polynomial is \(1+7z+18 z^2+9 z^3\). \(\square \)

Lemma 3.3

If there is a connected graph whose independence polynomial is \(1+8z+18 z^2+9 z^3\), then the following are true.

  1. (i)

    It has no pendant vertex.

  2. (ii)

    The degree of every vertex is either 2 or 3 and the number of vertices with degree 3 is four which is same as the number of vertices with degree 2.

  3. (iii)

    There are two adjacent vertices \(v_1\) and \(v_2\) such that \(d(v_1)=d(v_2)=2\) and they are with a common neighbor.

Consequently, there is exactly one such graph.

Proof

Let H be a connected graph whose independence polynomial is \(1+8z+18 z^2+9 z^3\).

  1. (i)

    Suppose that H has a pendant vertex u and that is adjacent to \(u_1\). Then, there are \(10-d(u_1)\) edges connecting the vertices of \(V(H) \setminus \{u, u_1\}\). Hence, the number of 2-independent sets of H not containing \(u_1\) and u is \(\left( {\begin{array}{c}6\\ 2\end{array}}\right) -(10-d(u_1))=5+d(u_1)\). Since every 3-independent set contains either u or \(u_1\), we have \(i_{3[u]}(H)=5+d(u_1)\) and \(i_{3[u_1]}(H)=4-d(u_1)\). Therefore, \(d(u_1)\le 4\).

    If \(d(u_1) = 4\), then \(i_{3[u]}(H)=9\) and \(i_{3[u_1]}(H)=0\), which means that the three vertices of \(V(H) \setminus N[u_1]\) are mutually adjacent. Now, each 3-independent set of H consists of one of these three vertices, u and a vertex from \(N(u_1) \setminus \{u\}\). In this case, no vertex of \(N(u_1) \setminus \{u\} \) is adjacent to any vertex in \(V(H) \setminus N[u_1]\). But this means that H is not connected, contrary to the assumption.

    If \(d(u_1) = 3\), then \(i_{3[u_1]}(H)=1\) and each pair of vertices in \(V(H) \setminus N[u_1]\), except one are adjacent. Let \(N(u_1) \setminus \{u\} =\{u_2, u_3\}\). If \(u_2 \sim u_3\), then one of these along with the two non-adjacent vertices of \(V(H) \setminus N[u_1]\) forms a 3-independent set. If \(u_2 \not \sim u_3\), then \(u_2, u_3\) and one vertex from \(V(H) \setminus \{N[u_2,u_3]\cup \{u\}\}\) (which contains at least two elements) forms a 3-independent set. In both the situations, there is a 3-independent set not containing u, and hence a 4-independent set containing u. This cannot be true.

    If \(d(u_1) = 2\), let \(N(u_1)=\{u,v\}\). Then, \(i_{3[u_1]}(H)=2\) and each pair of vertices in \(V(H) \setminus N[u_1]\), except two pairs are adjacent. This leads to a disconnected graph which is not true. Clearly, \(d(u_1)=1\) would mean a disconnected graph. Therefore, the graph H has no pendant vertex.

  2. (ii)

    Recall that H has 8 vertices and 10 edges. Since \(d(v)\ge 2\) for each \(v\in V(H)\), H cannot have any vertex with degree 7. Further, if H has a vertex v with degree 6, then all other vertices have degree two. Note that \(|V(H) \setminus N[v]|=1\) and the vertex in \(V(H) \setminus N[v]\) is adjacent to 2 vertices of N(v). Thus, there are only 2 edges between the six vertices of N(v) leading to a 4-independent set in N(v), which is not possible.

    If H has a vertex v with degree 5, then there are 6 vertices of degree 2 each and one vertex of degree 3. Further, it is seen that the two vertices of \(V(H) \setminus N[v]\) are adjacent. (Otherwise, there would be at least 4 edges incident to these 2 vertices and hence there will be at most one edge between the five vertices of N(v). This leads to a 4-independent set in N(v).) Let \(v\sim v_i, i=1,2,3,4,5\) and the 2 vertices in \(V(H) \setminus N[v]\) are \(u_1\) and \(u_2\). To avoid a 4-independent set in H, there must be two edges between the 5 vertices in N(v) with distinct end vertices. Let \(v_1\sim v_2\) and \(v_3\sim v_4\). Further, \(v_5\) must be adjacent to either \(u_1\) or \(u_2\) as \(d(v_5)\ge 2\). If \(v_5\) is adjacent to exactly one of them, say \(u_1\), then the remaining edge in H must connect \(u_2\) with one of \(v_1,v_2,v_3,v_4\), say \(v_1\) (all four cases are same). In that case, \(u_2,v_2,v_3,v_5\) will give a 4-independent set. If \(v_5\) is adjacent to both \(u_1\) and \(u_2\), then \(i_3(H)=12\), which is not possible.

    Now, if H has a vertex v with degree 4, then there is an edge between two vertices of \(V(H) \setminus N[v]\) in order to avoid a 4-independent set in H. Suppose that \(V(H) \setminus N[v] =\{u_1, u_2, u_3 \}\) and \(u_1 \sim u_2\). For the same reason, there should be an edge between two vertices, say \(v_1, v_2\) of N(v). Let the other two vertices of N(v) be denoted by \(v_3, v_4\).

    If \(u_1, u_2\) and \(u_3\) are mutually adjacent, then at least one of \(\{u_1, u_2, u_3\}\), say \(u_1\) is not adjacent to any vertex of N(v) in order to ensure \(E(H)=10\). Then in order to avoid 4-independent set in H there must be an edge between \(v_3\) and \(v_4\). Since H is connected, the remaining edge must be between one vertex of \(\{u_2, u_3\}\) and one vertex of N(v) leading to \(i_3(H)=10\), which is not true.

    If \(u_1 \sim u_2\), \(u_1 \sim u_3\) and \(u_2\not \sim u_3\), then there is a 4-independent set whenever \(u_2\) and \(u_3\) are incident to a single vertex of N(v). If \(u_2\) and \(u_3\) are incident to different vertices of N(v), then it can be seen that the resulting graph has either a 4-independent set or more than nine 3-independent sets, none of which is true. In fact, if \(u_2\sim v_1\) and \(u_3 \sim v_2\) then recall that \(v_1\sim v_2\). In this case, the remaining edge is between \(v_3\) and \(v_4\) and \(i_3(H)=11\). If \(u_2\sim v_3\) and \(u_3 \sim v_4\), then in order to avoid a 4-independent set (containing \(v_3,v_4, u_1\) and one of \(v_1\) or \(v_2\)) \(v_3\) should be adjacent to \(v_4\). Then, as observed in the previous case \(i_3(H)=11\). If \(u_2\) is adjacent to one of \(v_1, v_2\) and \(u_3\) is adjacent to one of \(v_3, v_4\), then for the same reason as above \(v_3\) must be adjacent to \(v_4\). Then, without loss of generality assume that \(u_2\sim v_2\) and \(u_3\sim v_4\). Now, \(v_3,u_2,u_3,v_1\) form a 4-independent set contrary to our assumption.

    If \(u_1 \sim u_2\), \(u_1 \not \sim u_3\) and \(u_2\not \sim u_3\), then \(u_1\) is adjacent to some vertex of N(v) and \(u_2\) is adjacent to some vertex of N(v). Further, another two edges are incident to \(u_3\). Consequently, the edge between \(v_1\) and \(v_2\) is the only remaining edge.

    Now, if \(N(u_3)= \{v_1, v_2\}\), then \(u_2 \sim v_3 \) and \(u_1 \sim v_4\) giving that \(i_3(H) = 11\).

    Suppose that \(N(u_3)= \{v_3, v_4\}\). If \(u_1 \sim v_1\) and \(u_2 \sim v_2\) (or in the other way), there will be a 4-independent set \(\{v_3, v_4, v_1, u_2\}\). If \(u_1 \sim v_1\) and \(u_2 \sim v_1\), then also we get a 4-independent set. If \(u_1\) is adjacent to one of \(v_1\) or \(v_2\) and \(u_2\) is adjacent to one of \(v_3\) or \(v_4\), then in each case we will get a 4-independent set. If both \(u_1\) and \(u_2\) are adjacent to one vertex of \(v_3\) or \(v_4\) (not both), then \(i_3(H)=12\). If \(u_1 \sim v_3\) and \(u_2 \sim v_4\) (or in the other way), then also \(i_3(H)=12\).

    If \(N(u_3)= \{v_2, v_3\}\), then \(v_4\) is adjacent to one of \(u_1, u_2\). If \(v_4 \sim u_1\), then \(u_2\) is adjacent to a vertex of N(v). If \(u_2\sim v_1\), then \(\{v_2, v_3, v_4, u_2\}\) is a 4-independent set. If \(u_2\sim v_2\), then \(\{v_1, v_3, v_4, u_2\}\) is a 4-independent set. If \(u_2\sim v_3\), then \(\{v_1, u_3, v_4, u_2\}\) is a 4-independent set. If \(u_2\sim v_4\), then \(i_3(H)=11\). The other case when \(N(u_3)=\{v_1,v_3\},\{v1,v_4\}, \{v_2,v_4\}\) leads to contradiction in a similar way.

    Thus, \(d(v)=2\) or 3 for each \(v\in V(H)\). Since \(\sum d(v)=20\), the number of vertices with degree 3 is exactly four and each of the other four vertices has degree 2.

  3. (iii)

    Consider the four vertices of H with degree 2 each. Since, there is no 4-independent set in H, there is an edge between two of them, say \(v_1\) and \(v_2\). Let \(v_2 \sim v_3\) and \(v_1 \sim v_4\). We need to show that \(v_3=v_4\).

    On the contrary, suppose that \(v_3 \ne v_4\). If \(d(v_3)=d(v_4)=2\), then \(v_3 \not \sim v_4\) (because H is connected). If \(v_3\) and \(v_4\) are adjacent to the same vertex, say \(v_5\), then each pair of vertices in \(V(H)\setminus \{v_1, v_2, v_3, v_4, v_5\}\) is adjacent and \(d(v_5)\) must be 4, contrary to (ii). If \(v_3\) and \(v_4\) are adjacent to two different vertices, say to \(v_5\) and \(v_6\), respectively, then there are 5 edges between the vertices of \(V(H)\setminus \{v_1,v_2,v_3,v_4\}\). In fact, each pair of this set are adjacent except \(v_5, v_6\). But in that case, the graph is as given in Fig. 4a and \(i_3(H)=10\), a contradiction.

    Suppose that one of \(v_3\) or \(v_4\), say \(v_3\) has degree 3. Now, if \(v_3 \sim v_4\) and \(d(v_4)=3\), then \(|N(v_3) \cap N(v_4)|=1\) or 0. The first case leads to the graph Fig. 4b since the three vertices of \(V(H) \setminus (N[v_3] \cup \{v_1\})\) are mutually adjacent. This graph has 10 independent sets with cardinality 3 each, a contradiction. In the second case, using the same argument it is found that \(|E(H)|=10\), which cannot be true. If \(v_3 \sim v_4\) and \(d(v_4)=2\) then \(v_5\), the vertex in \(N(v_3)\) and different from both \(v_2, v_4\), must have degree 3 leading to the graph given in Fig. 4c. This graph has a 4-independent set, a contradiction.

    Now suppose that \(v_3 \not \sim v_4\). Let \(N(v_3)\setminus \{v_2\}=\{v_5,v_6\}\) and the other two vertices be \(v_7\) and \(v_8\). Since \(v_1 \not \sim v_3\), we must have \(v_7 \sim v_8\). Let \(d(v_4)=2\). If \(v_4\) is adjacent to \(v_5\) (or \(v_6\)), then \(v_6, v_7, v_8\) (\(v_5, v_7, v_8\), respectively) have to be mutually adjacent in order to avoid a 4-independent set containing \(v_2, v_4\). This gives the graph given in Fig. 4d for which \(i_3(H)=11\), a contradiction. If \(v_4\) is adjacent to \(v_7\) (or \(v_8\)) then the vertices \(v_5, v_6, v_8\) (or \(v_5, v_6, v_7\), respectively) are mutually adjacent, leading to the graph as given in Fig. 4e for which \(i_3(H)=10\), a contradiction. Considering \(d(v_4)=3\), it is observed that without loss of generality \(N(v_4) \setminus \{v_1\}\) is \(\{v_5, v_6\}, \{v_7, v_8\}\) or \(\{v_5, v_7\}\). The first and the second situations give rise to graphs Fig. 4f and g, respectively, for each of which \(i_3(H)=10\), a contradiction. In the third case, both \(v_2\) and \(v_4\) are non-adjacent to each of \(v_6\) and \(v_8\), giving that \(v_6 \sim v_8\). Also, \(v_1 \not \sim v_3\) gives that \(v_7 \sim v_8\). Now, \(v_5 \sim v_6, v_5 \sim v_7, v_5 \sim v_8,\) or \( v_6 \sim v_7\) leading to graphs Fig. 4h–j, respectively, the first two situations leading to the same graph. But each of these graphs has at least ten 3-independent sets, contrary to the fact.

    This proves that \(d(v_1)=d(v_2)=2\), and these are adjacent to a common vertex. In other words, \(v_3 =v_4\).

Fig. 4
figure 4

Graphs used in the proof of Lemma 3.3 (ii)

It is now clear that \(d(v_3)=3\). Let \(N(v_3)\setminus \{v_1, v_2\}=\{v_4\}\). If \(d(v_4)=3\), then \(v_4\) is adjacent to both \(v_5\) and \(v_6\) implying \(v_7 \sim v_8\). If \(v_5 \not \sim v_6\), then there is only one graph as given by Fig. 4k for which \(i_3(H)=10\), a contradiction. If \(v_5 \sim v_6\), then the graph is as given in Fig. 4b for which \(i_3(H)=10\). Thus, \(d(v_4)=2\) and consequently, the vertex adjacent to \(v_4\), say \(v_5\) and different from \(v_3\) has degree 3. Hence, there is exactly one graph whose independence polynomial is \(1+8z+18 z^2+9 z^3\), which is given in Fig. 5. \(\square \)

Fig. 5
figure 5

The graph with independence polynomial \(1+8z+18 z^2+9 z^3\)

Theorem 3.3

There are exactly 4 connected graphs with independence polynomial \(1+ 9z +18 z^2 +9 z^3\) and having a vertex of degree 8.

Proof

Let G be a graph whose independence polynomial is \(1+ 9z +18 z^2 +9 z^3\). Then, it has 9 vertices and 18 edges. Let n be the number of vertices of degree 8 in G. Then, the sum of degrees of all vertices is at least \(8n+(9-n)n\), which is bigger than 36 whenever \(n \ge 3\). If \(n=2\), then the subgraph of G induced by the vertices with degree less than 8 must have three edges, seven vertices and nine 3-independent sets. In other words, its independence polynomial is \(1+ 7 z+18 z^2 + 9 z^3\). However, this is not possible by Lemma 3.2. Therefore, G can have at most one vertex with degree 8.

Let u be a vertex of G with degree 8. The subgraph H induced by all the vertices of G except u has 8 vertices and 10 edges. Since there is no independent set in G containing u, each 3-independent set of G is a 3-independent set of H and vice versa. This gives \(i_3(H)=9\). Further, H has 8 vertices, 10 edges and no 4-independent set. In other words, \(I_{H}(z)=1+8z+18z^2+9z^3\).

Suppose that H is disconnected. If it has three components with \(n_1, n_2\) and \( n_3\) vertices, then the independence polynomial of each component is linear and their product is \(1+8 z+ 18 z^2 +9 z^3\). Comparing the coefficients, it is found that \(n_1 +n_2+n_3=8\) and \(n_1 n_2 n_3=9\). However, no such natural numbers \(n_1, n_2, n_3\) exist proving that H cannot have three components. Let H have two components \(H_1, H_2\) with independence polynomials \(I_{H_1}\) and \(I_{H_2}\) respectively. Since their product is a cubic polynomial, one is linear and the other is a quadratic polynomial. Let \(I_{H_1}(z)=1+n_1 z\) and \(I_{H_2}(z)=1+n_2 z +mz^2\) for some \(n_1, n_2, m \in {\mathbb {N}}\). Comparing the coefficients of their product with those of \(I_{H}(z)\), it is found that \(n_1 +n_2=8,\; n_1 n_2+m=18\) and \(n_1m=9\). Therefore, \(n_1=3=m \) and \(n_2=5\), and the graph \(H_1\) is \(K_3\), \(H_2\) has 5 vertices and 7 edges. Since the total degree of all vertices of \(H_2\) is 14, there is a vertex v of \(H_2\) with degree one or two. Letting \(d(v)=1\), it is seen that none of the six edges of \(H_2\) is incident to v. Since there are 4 other vertices, these are mutually adjacent. Thus, \(H_2\) contains \(K_4\) as a subgraph, one vertex of which is joined to v. Therefore, G is the fourth graph of Fig. 6. Now, suppose that \(d(v)=2\) and \(v_1, v_2\) are adjacent to v. Then, there are five edges between the vertices of \(V(H_2) \setminus \{v\}\). In other words, exactly one edge is missing from the complete graph on the 4 vertices of \(V(H_2) \setminus \{v\}\). This edge (to be missed) must be incident on one of \(v_1, v_2\), else there would be a 3-independent set in \(H_2\) contrary to the situation. If this edge is taken between \(v_1\) and \(v_2\), then we get G as the second graph given in Fig. 6. If this edge is not between \(v_1\) and \(v_2\), then we get the third graph of Fig. 6.

If H is connected, then it follows from Lemma 3.3 that there is exactly one graph. The resulting graph G is the first one in Fig. 6. \(\square \)

Fig. 6
figure 6

Graphs with a vertex of maximum degree when \(k=3\)

Fig. 7
figure 7

All the graphs in \({\mathcal {T}}_3\)

For \(k=2\), connected graphs do exist (computationally, the number of all such graphs is found to be 902). Instead of finding all these graphs, we give an algorithm to generate them. Let \({\mathcal {T}}_3\) be the set of all graphs with exactly 3 triangles such that each vertex as well as each edge of the graph is part of a triangle. It is easy to observe that \({\mathcal {T}}_3\) contains exactly 9 nonisomorphic graphs \(T_1,T_2,\ldots , T_9\) (see Fig. 7 for an easy understanding). We give an algorithm which will generate all connected graphs whose independence polynomial is \(1+ 9z +12 z^2 +4 z^3\), taking inputs from \({\mathcal {T}}_3\).

The algorithm will first generate a graph with 9 vertices, 12 edges, 4 triangles, no \(K_4\) as its subgraph and such that each of its vertices has degree strictly less than 8. The complement of such a graph G has 9 vertices, 12 independent sets with cardinality 2, 4 independent sets with cardinality 3 and no 4-independent set. Further, it is connected. (If it is disconnected, then it has a component with k vertices, where \(2\le k\le 7\). Then, G can have at most \(\left( {\begin{array}{c}k\\ 2\end{array}}\right) \)+ \(\left( {\begin{array}{c}9-k\\ 2\end{array}}\right) =k^2-9k+36\le 22\) number of edges for \(2\le k\le 7\), leading to a contradiction). Let us define the following three properties of a graph:

\(P_1:\):

the graph does not contain a \(K_4\) as its subgraph,

\(P_2:\):

the graph does not contain more than four triangles,

\(P_3:\):

the graph does not contain a vertex of degree 8.

3.3 Algorithm

For \(H \in {\mathcal {T}}_3\), if \(|V(H)|<9\) then consider a new graph \(H'\) by adding \(9-|V(H)|\) number of isolated vertices to H. Then, add a triangle in one of the following ways such that the resulting graph has properties \(P_1\), \(P_2\) and \(P_3\). Note that, for each such \(H'\) at least one of the following can be executed.

  1. 1.

    By inserting a single edge: Consider two non-adjacent vertices uv of \(H'\) such that \(N(u) \bigcap N(v) \ne \emptyset \) and insert an edge between them.

  2. 2.

    By inserting two edges: Consider two adjacent vertices uv of \(H'\) and a vertex w such that \(u \not \sim w\) and \(v \not \sim w\). Then insert two edges, one between u and w, and the other between v and w.

  3. 3.

    By inserting three edges: Consider three mutually non-adjacent vertices uvw of \(H'\) and join the three edges between them.

If the graph obtained by applying any one of the above three steps has less than 12 edges, then insert additional edges so that the resulting graph, say \(H''\), has 12 edges and it satisfies \(P_1\), \(P_2\) and \(P_3\).

Now, the complement of \(H''\) is connected and it has 9 vertices, 24 edges and the number of 3-independent sets is 4, as desired. The detailed algorithm is provided in Sect. 5 (Appendix).

The following example demonstrates that for each \(1 \le j \le 8\), there is connected graph with a vertex of degree j whose independence polynomial is \(1+ 9z +12 z^2 +4 z^3\).

Example 3.1

Consider the four graphs in Fig. 8. The complement of each graph is connected and is with independence polynomial \(1+ 9z +12 z^2 +4 z^3\).

Observe that the graphs in Fig. 8a and b have been obtained from \(T_4\in {\mathcal {T}}_3\), first by adding 3 isolated vertices, then adding one triangle by inserting 3 edges, and then adding another edge. Similarly, the graph in Fig. 8d has been obtained from \(T_9\in {\mathcal {T}}_3\), first by adding 2 isolated vertices, then adding one triangle by inserting 2 edges, and then adding another edge. The graph in Fig. 8c has been obtained from \(T_9\in {\mathcal {T}}_3\), first by adding 2 isolated vertices, then adding one triangle by inserting 3 edges.

Further, there are vertices of degree 3, 4, 5, 6, 7 in the complement of the graph in Fig. 8a. The complement of the graph in Fig. 8b has a vertex with degree 8. The complement of the graph given in Fig. 8c has a vertex with degree 2 whereas that of Fig. 8d has a pendant vertex.

Fig. 8
figure 8

Some examples of complementary graphs when \(k=2\)

3.4 All Graphs When \(k=1\)

Here, we consider the last case \(k=1\) and find all possible connected graphs whose independence polynomial is \(1+9 z+6 z^2+z^3\). Let \(P_n\) denote the path on n vertices.

Theorem 3.4

There are exactly 17 connected graphs whose independence polynomial is \(1+9 z+6 z^2+z^3\).

Proof

Let G be a connected graph with independence polynomial \(1+9 z+6 z^2+z^3\). Then, clearly G has 9 vertices and 30 edges. Since there is exactly one 3-independent set, G can be obtained by deleting three edges (but no vertex) of a triangle from \(K_9\) (denoted by \(K_9 \setminus K_3\)), followed by deleting 3 suitable edges.

In order to find all connected graphs with \(1+9 z+6 z^2+z^3\) as independence polynomial, it is sufficient to count the total number of different ways to delete three suitable edges from \(K_9 \setminus K_3\). Let \(v_1,v_2\) and \(v_3\) be the vertices of \(K_3\). We say an edge of \(K_9 \setminus K_3\) is interior if it is not incident on any vertex of \(\{v_1, v_2, v_3\}\). Note that there are exactly 15 interior edges and they form a \(K_6\). To obtain G, one may delete three interior edges, three non-interior edges, or at least one interior and one non-interior edge. Thus, we have the following three cases.

  1. Case 1

    (Three interior edges): Note that a complete graph on three vertices cannot be deleted from \(K_9 \setminus K_3\) since this will give rise to another 3-independent set in G in addition to \(\{v_1,v_2,v_3\}\). There are only two non-complete connected graphs with three edges, namely star on four vertices (that with one vertex which has degree 3) and \(P_4\). These two graphs (along with the triangle) are given in Fig. 9(A) and 9(B). There are only two disconnected graphs with three edges, namely \(3K_2\) and \(P_3 \cup K_2\). These are given in Fig. 9(C) and 9(D). Deletion of each of these four graphs from \(K_9 \setminus K_3\) gives a desired graph, and the resulting graphs are not isomorphic. Therefore, the total number of nonisomorphic connected graphs obtained by deleting any three interior edges from \(K_9 \setminus K_3\) is 4.

  2. Case 2

    (Three non-interior edges): If the three non-interior edges to be deleted are adjacent to \(v_1\), then the resulting graph is a desired one, as given in Fig. 9(E). If all the three non-interior edges to be deleted are chosen to be adjacent either to \(v_2\) or to \(v_3\) then the resulting graphs will be isomorphic to the earlier one.

    If the two of the non-interior edges to be deleted are incident to \(v_i \in \{v_1, v_2, v_3\}\) and the other is incident to \(v_j, j \ne i\), then a desired graph is obtained, as given in Fig. 9(F). Lastly, if each of the three non-interior edges to be deleted is adjacent to different \(v_i\)’s, \(i \in \{1,2,3\} \), then the graph is given in Fig. 9(G) which is not isomorphic to any other graph already obtained. Therefore, the total number of nonisomorphic connected graphs obtained by deleting three non-interior edges from \(K_9 \setminus K_3\) is 3.

  3. Case 3

    (At least one interior and at least one non-interior edge): Depending on the number of interior edges to be removed, we have two cases.

    • Subcase-A (Two interior edges and one non-interior edge): Let the 3 edges to be removed be incident to a common vertex. Then, this vertex is different from \(v_1,v_2\) and \( v_3\). The subgraph with these edges, which are to be removed, must be a star with three edges. This is as given in Fig. 10(A).

      The only other connected subgraph that is to be removed from \(K_9 \setminus K_3\), to give a desired graph is \(P_3\), where the two interior edges have a common vertex and the other vertex (upon which one of these edges is incident) is adjacent to one of \(\{v_1,v_2,v_3\}\), as given in Fig. 10(B). Therefore, there are two nonisomorphic graphs obtained in this case, where the subgraph to be removed is connected.

      If one interior edge and one non-interior edge have a common vertex, say v, then the third edge is neither incident to v nor to the other end vertex of the interior edge (otherwise, we get a graph already found in Fig. 10(A) and Fig. 10(B)). In this case, we get a single desired graph as given in Fig. 10(C).

      Let the non-interior edge have no common end vertex with any of the two interior edges. Depending on whether the two interior edges share a common vertex or not, we get two nonisomorphic graphs, as given in Fig. 10(D) and (E).

      Therefore, exactly 5 nonisomorphic graphs can be obtained by deleting two interior and one non-interior edges from \(K_9 \setminus K_3\).

    • Subcase-B (Two non-interior edges and one interior edge): Choose two non-interior edges incident upon a single \(v_i, i \in \{1,2,3\}\). Let uv be the vertices adjacent to \(v_i\). Then, the third edge, which must be interior, can be chosen in two ways: (i) it is incident either to u or to v (both leading to the same graph), or (ii) it is incident neither to u nor to v, as given in Fig. 10(F) and (G), respectively. Note that the edge joining u and v cannot be deleted as it will lead to another 3-independent set different from \(\{v_1,v_2,v_3\}\). Thus, two such nonisomorphic graphs are obtained in this situation.

      Choose the two non-interior edges incident upon different vertices \(v_i,v_j \in \{v_1, v_2, v_3\}\). These two edges cannot be incident to a single vertex of \(K_6\) because then a 3-independent set, different from \(\{v_1,v_2,v_3\}\) will arise leading to a contradiction. Let the two non-interior edges are incident upon u and v. The third edge to be deleted can be the one joining u and v giving rise to the graph given in Fig. 10(H), can be incident to u but not to v (that incident to v but not to u will give an isomorphic graph), as given in Fig. 10(I) or can be incident neither to u nor to v leading to the graph given in Fig. 10(J). This gives rise to 3 nonisomorphic graphs.

Fig. 9
figure 9

Case I and II

Fig. 10
figure 10

Case III

There are 4, 3 and 10 graphs in Cases 1, 2 and 3, respectively. Hence, there are exactly 17 connected graphs up to isomorphism whose independence polynomial is \(1+9 z+6 z^2+z^3\). \(\square \)

4 Disconnected Graphs

In this section, we characterize all disconnected graphs whose independence polynomial is a line segment. The following special graphs are needed. By \(C_n\), we denote a cycle on n vertices and T denotes the graph on 5 vertices obtained from \(P_4\) by attaching a pendant to a vertex of degree 2. A kite graph is a connected graph on 5 vertices which is obtained from \(K_4\) by deleting one edge and then attaching a new pendant vertex to one vertex of degree 2. A house graph is a connected graph on 5 vertices which is obtained by joining two non-adjacent vertices of \(C_5\) by an edge. A butterfly graph is a connected graph on 5 vertices which is obtained by attaching two copies of \(K_3\) at a vertex (see Fig. 11).

Fig. 11
figure 11

Kite, House, Butterfly and T graphs

We need the following lemma to prove the main result of this section.

Lemma 4.1

There is no connected graph whose independence polynomial is \(1+8 z+16 z^2\).

Proof

Let G be a graph whose independence polynomial is \(1+8z+16z^2\). Then, \(G^c\) has 8 vertices, 16 edges and it does not contain any triangle. By Mantel’s theorem, \(G^c\) is the complete bipartite graph \(K_{4,4}\). In other words, G is the disjoint union of two copies of \(K_4\) and hence is disconnected completing the proof. \(\square \)

The following theorem proves that there are exactly 13 disconnected graphs up to isomorphism whose independence fractal is a line segment.

Theorem 4.1

Let G be a disconnected graph with independence number 3. Its independence fractal is a line segment if and only if it is one of the following:

  1. 1.

    \(K_4 \cup K_4 \cup K_1\)

  2. 2.

    \(K_1 \cup (K_8 \setminus C_4)\)

  3. 3.

    \(K_1 \cup (K_8 \setminus P_5)\)

  4. 4.

    \(K_1 \cup (K_8 \setminus T)\)

  5. 5.

    \(K_1 \cup (K_8 \setminus K_{1,4})\)

  6. 6.

    \(K_1 \cup (K_8 \setminus (P_3\cup P_3))\)

  7. 7.

    \(K_1 \cup (K_8 \setminus (P_2 \cup P_4))\)

  8. 8.

    \(K_1 \cup (K_8 \setminus (P_2 \cup K_{1,3}))\)

  9. 9.

    \(K_1 \cup (K_8 \setminus (2 K_2 \cup P_3))\)

  10. 10.

    \(K_1 \cup (K_8 \setminus 4 K_2)\)

  11. 11.

    \(K_4 \cup K\), where K is the kite graph

  12. 12.

    \(K_4 \cup H\), where H is the house graph

  13. 13.

    \(K_4 \cup B\), where B is the butterfly graph

Proof

The independence fractal of a graph G with independence number 3 is a line segment if and only if its independence polynomial is \(1+9z+6kz^2+k^2z^3\) for some \( k=1,2,3,4,5\) by Theorem 2.2. The degree of the independence polynomial of a graph with m components is at least m. Therefore, G has two or three connected components whenever G is disconnected. Recall that the independence polynomial of a disconnected graph is the product of the independence polynomials of each connected component of the graph.

If G has 3 components \(G_1, G_2\) and \(G_3\), and \(G_i\) has \(n_i\) vertices for \(i=1,2,3\), then the independence polynomial of each \(G_i\) must be linear and \(I_G (z)=(1+n_1 z)(1+n_2 z)(1+n_3 z)=1+(n_1+n_2+n_3)z+(n_1 n_2+n_2 n_3+n_1 n_3)z^2+ n_1 n_2 n_3 z^3\). Since, \(I_G (z)=1+9z+6kz^2+k^2z^3\), every set of possible values of \(n_1, n_2\) and \(n_3\) must satisfy \( n_1 n_2n_3=k^2\), \(n_1+n_2+n_3=9\) and \(n_1 n_2+n_2 n_3+n_1 n_3= 6 k\) for some k. For \(k=1,2,3,5\), this is clearly not possible. For \(k=4\), the possible values of \((n_1, n_2,n_3)\) satisfying the first two equations are (4, 4, 1) (or one of its permutations). This also satisfies the third equation. Therefore, \(I_{G_1}(z)=I_{G_2}(z)=1+ 4z\) and \(I_{G_3}(z)=1+z\) and consequently, \(G_1=G_2= K_4\) and \(G_3=K_1\). The resulting graph is \(K_4 \cup K_4 \cup K_1\), as given in (1) of the statement of this theorem.

If G has two components \(G_1\) and \( G_2\) with \(n_1\) and \(n_2\) vertices, respectively, then one of them, say \(G_1\) has independence number one and the other, \(G_2\) has independence number two. Let \(I_{G_1} (z)=1+n_1 z\) and \(I_{G_2} (z)=1+ n_2 z +m z^2\). Then, \(I_G (z)=1+(n_1 +n_2)z + (n_1 n_2+m)z^2 + mn_1 z^3\). The ordered pair \((mn_1, n_1 n_2+m )\) can take the values only from the set \(\{ (1, 6), (4, 12), (9, 18), (16, 24), (25, 30)\}\).

Table 1 Possible values of \(m,n_1\) and \(n_2\)

The possible values of \(m, n_1, n_2\) are given in Table 1. Therefore, the possible independence polynomials of G are \(Q_1= (1+ z)(1+ 8 z+4 z^2)\), \(Q_2= (1+ 4z)(1+ 5 z+4 z^2)\) or \(Q_3= (1+ z)(1+ 8 z+16 z^2)\). By Lemma 4.1, there is no connected graph whose independence polynomial is \(1+ 8 z+16 z^2 \). Therefore, \(Q_3\) cannot be the independence polynomial of any graph satisfying the assumption of this theorem and with exactly two components. In order to determine all graphs with two components whose independence fractals are line segments, all connected graphs whose independence polynomial is either \(1+ 8 z+4 z^2\) or \(1+ 5 z+4 z^2\) need to be characterized.

Let \(G_2\) be a connected graph such that \(I_{G_2} (z)= 1+ 8 z+4 z^2\). Then, \(G_2\) can be obtained by deleting 4 edges (but no vertices) from \(K_8\) in such a way that the resulting graph has no 3-independent set. Let H be the subgraph of \(K_8\) having these 4 edges and along with their end vertices. We shall show that there are 9 such nonisomophic subgraphs which will mean that there are exactly 9 nonisomophic graphs with independence polynomial \(1+ 8 z+4 z^2\). Note that such a subgraph has no isolated vertex and does not contain any \(K_n\) with \(n\ge 3\). In particular, it is triangle free.

Thus, if H is connected, it cannot have a single pendant vertex. It is \(C_4\) whenever it has no pendant vertex. This is as given in (2). If it has 2 pendant vertices, then it is \(P_5\), as given in (3). It is T or \(K_{1,4}\) whenever it has 3 or 4 pendant vertices, respectively. This is as given in (4) and (5) of this theorem. Clearly, it cannot have 5 or more pendant vertices.

If H is disconnected with two components, then there are two possibilities; each component has two edges, or one has three and the other has one edge. The first case implies \(H=P_3\cup P_3\) giving (6) whereas \(H=P_2 \cup {\hat{H}}\) in the second case where \({\hat{H}}\) is a connected triangle free graph with three edges. It follows that \({\hat{H}}\) is \(P_4\) or \(K_{1,3}\), giving (7) and (8) of this theorem, respectively.

If H has three components, then it is \(2 K_2 \cup P_3\) as given in (9) of the theorem. If H has four components then it must be \(4 K_2\). This is (10) of this theorem.

Let \(G_2\) be a connected graph such that \(I_{G_2}(z)= 1+ 5 z+4 z^2\). Since \(G_2\) can be obtained by deleting four edges from \(K_5\). It has 6 edges. Further, if each vertex of \(G_2\) has degree at least 3, then the sum of degrees of all vertices will be at least 15. This means that \(G_2\) has at least 7 edges, contrary to the fact. Therefore, \(G_2\) has a vertex with degree one or two. Let \(v_1\) be a vertex of \(G_2\) with degree \(d(v_1)\le 2\).

If \(d(v_1)=1\), then the vertex adjacent to \(v_1\), say \(v_2\) has degree at least two. None of the other three vertices is adjacent to \(v_1\). Hence, there is an edge between each pair of these three vertices (in order to avoid a 3-independent set). Each of the other two edges joins \(v_2\) and one of \(\{v_3, v_4,v_5\}\). Thus, \(G_2\) is a kite graph, as given in (11) of the statement of this theorem.

For \(d(v_1)=2\), let \(v_2\) and \( v_3\) be adjacent to \(v_1\). There is an edge between \(v_4\) and \(v_5\) since each of these is not adjacent to \(v_1\). Since \(G_2\) is connected, there is an edge between a vertex from \( \{v_2, v_3\}\) and another from \(\{v_4, v_5\}\). Let \(v_2 \sim v_4\), without loss of generality. The other choices do not give rise to any different graph. If \(v_2\) is adjacent to \(v_3\), then the sixth edge joins \(v_3, v_4\) or \(v_3, v_5\) or \(v_2, v_5\). The first case (where \(v_3 \sim v_4\)) gives a kite graph. The second situation (when \(v_3 \sim v_5\)) gives rise to a house graph, (12) of the statement of this theorem, whereas the third possibility means that \(G_2\) is the butterfly graph, (13) of the statement of this theorem. If \(v_2\) is not adjacent to \(v_3\) then \(v_5\) is adjacent to one of \(\{v_2, v_3\}\). This is to avoid any 3-independent set containing \(v_2, v_3\). Then, either \(v_5\sim v_2\) or \(v_5 \sim v_3\). If \(v_5 \sim v_2\), then \(v_3 \sim v_5\) or \(v_3 \sim v_4\), both imply that \(G_2\) is the house graph. If \(v_3 \sim v_5\), then \(v_3 \sim v_4\) or \(v_2 \sim v_5\), again both imply that \(G_2\) is the house graph.

The converse is trivial. \(\square \)