Characterization of classes of graphs with large general position number

Getting inspired by the famous no-three-in-line problem and by the general position subset selection problem from discrete geometry, the same is introduced into graph theory as follows. A set $S$ of vertices in a graph $G$ is a general position set if no element of $S$ lies on a geodesic between any two other elements of $S$. The cardinality of a largest general position set is the general position number ${\rm gp}(G)$ of $G.$ In \cite{ullas-2016} graphs $G$ of order $n$ with ${\rm gp}(G)$ $\in \{2, n, n-1\}$ were characterized. In this paper, we characterize the classes of all connected graphs of order $n\geq 4$ with the general position number $n-2.$


Introduction
The general position problem in graphs was introduced by P. Manuel and S. Klavžar [4] as a natural extension of the well known century old Dudeney's no-three-in-line problem and the general position subset selection problem from discrete geometry [2,3,6]. The general position problem in graph theory was introduced in [4] as follows. A set S of vertices in a graph G is a general position set if no element of S lies on a geodesic between any two other elements of S. A largest general position set is called a gp-set and its size is the general position number (gp-number, in short), gp(G), of G.
The same concept was in use two years earlier in [7] under the name geodetic irredundant sets. The concept was defined in a different method, see the preliminaries below. In [7] it is proved that for a connected graph of order n, the complete graph of order n is the only graph with the largest general position number n; and gp(G) = n − 1 if and only if G = K 1 + j m j K j with m j ≥ 2 or G = K n − {e 1 , e 2 , . . . , e k } with 1 ≤ k ≤ n − 2, where e i 's all are edges in K n which are incident to a common vertex v. In [4], certain general upper and lower bounds on the gp-number are proved. In the same paper it is proved that the general position problem is NP-complete for arbitarary graphs. The gp-number for a large class of subgraphs of the infinite grid graph, for the infinite diagonal grid, and for Beneš networks were obtained in the subsequent paper [5]. Anand et al. [1] gives a characterization of general position sets in arbitrary graphs. As a consequence, the gp-number of graphs of diameter 2, cographs, graphs with at least one universal vertex, bipartite graphs and their complements were obtained. Subsequently, gpnumber for the complements of trees, of grids, and of hypercubes were deduced in [1]. Recently, in [8] a sharp lower bound on the gp-number is proved for Cartesian products of graphs. In the same paper the gp-number for joins of graphs, coronas over graphs, and line graphs of complete graphs are determined. Recent developments on general position number can be seen in [9].

Preliminaries
Graphs used in this paper are finite, simple and undirected. The distance d G (u, v) between u and v is the minimum length of an u, v-path. An u, v-path of minimum length is also called an u, v-geodesic. The maximum distance between all pairs of vertices of G is the diameter, diam(G), of G.
between vertices u and v of a graph G is the set of vertices that lie on some u, v-geodesic We may simplify the above notation by omitting the index G whenever G is clear from the context. Let η(G) be the maximum order of an induced complete multipartite subgraph of the complement of G. Finally, for n ∈ N we will use the notation [n] = {1, . . . , n}.
In this paper, we make use of the following results.
Theorem 2.1 [7] Let G be a connected graph of order n and diameter d. Then gp(G) ≤ n − d + 1.
We recall the characterization of general position sets from [1], for which we need some additional information. Let G be a connected graph, S ⊆ V (G), and be the distance between a vertex from S i and a vertex from S j . Finally, we say that

The characterization
In the following, we characterize all connected graphs G of order n ≥ 4 with the gpnumber n − 2. Since the complete graph K n is the only connected graph of order n with the gp-number n, by Theorem 2.1, we need to consider only graphs with diameter 2 or 3. First, we introduce four families of graphs with the diameter 3; and four families of graphs with the diameter 2.
Let F 1 be the collection of all graphs obtained from the cycle C : Graphs from the family F 1 are presented in Figure 1.
Let F 2 be the collection of all graphs obtained from the path P 2 : x, y and complete graphs K n 1 , K n 2 , . . . , K nr (r ≥ 1), K m 1 , K m 2 , . . . , K ms (s ≥ 1) and K l 1 , K l 2 , . . . , K lt (possibly complete graphs of this kind may be empty), by joining both x and y to all vertices of K l 1 , K l 2 , . . . , K lt ; joining x to all vertices of K n 1 , K n 2 , . . . , K nr ; and joining y to all vertices of K m 1 , K m 2 , . . . , K ms . Graphs from the family F 2 are presented in Figure 2. Trees with diameter 3 are called double stars and they belong to the class F 2 .   Let F 3 be the collection of all graphs obtained from the path P 4 : u, x, y, v and a complete graph K r (r ≥ 1) by joining both u and x to all vertices of K r and joining y to a subset S of vertices of V (K r ) (possibly S may be empty or S = V (K r )). Graphs from the family F 3 are presented in Figure 3.
Let F 4 be the collection of all graphs obtained from the path P 3 : x, y, v and complete graphs K q , K n 1 , K n 2 , . . . , K nr (r ≥ 1), K m 1 , K m 2 , . . . , K ms (s ≥ 1) by joining x to all vertices of K n 1 , K n 2 , . . . , K nr ; joining x and v to all vertices of K m 1 , K m 2 , . . . , K ms ; joining x and y to all vertices of K q . Graphs from the family F 4 are presented in Figure 4.
Next, we introduce four families of graphs with diameter 2. Let F 5 be the collection of all graphs obtained from the complete graph K n−2 (n ≥ 5) by adding two new vertices u and v, joining u to all vertices of non-empty subset S of V (K n−2 ) of size at most n − 3; and joining v to all vertices of non-empty subset T of V (K n−2 ) of size at most n − 3. The set S must intersect with the set T so that, the diameter of each graph from the family F 5 is 2. Graphs from the family F 5 are presented in Figure 5.
Let F 6 be the collection of all graphs obtained from the family F 5 by adding the edge uv. Moreover; in this case, the set S may be disjoint with the set T. Graphs from the family F 6 are presented in Figure 6. Let F 7 be the collection of all graphs obtained from the complete graphs K n 1 , K n 2 , . . . , K nr (r ≥ 2) by adding two new vertices x and y, joining x to a non-empty subset S i of V (K n i ) for all i ∈ [r]; and y to a non-empty subset T i of V (K n i ) for all i ∈ [r] (the edges are in a way that for any u ∈ V (K n i ) and v ∈ V (K n j ) with i = j must have a common neighbor). Moreover, for some i ∈ [r]; the set S i must intersect with the set T i so that, the diameter of each graph from the family F 7 is 2. Graphs from   Figure 7. It is clear that both C 4 and C 5 belong to class F 7 .
Let F 8 the collection of all graphs obtained from the family F 7 by adding the edge xy. In this case, the set S i may be disjoint with the set T i for all i ∈ [r]. Graphs from the family F 8 are presented in Figure 8.
Proof. First, suppose that G is a connected graph of order n with gp(G) = n − 2.
Then it follows from Theorem 2.1 that diam(G) is either 2 or 3. We consider the following two cases. Case 1: diam(G) = 3. If G is a tree, then G is a double star and hence it belongs to F 2 . So, assume that G has cycles. Let girth(G) denotes the length of a shortest cycle in G.
Let C be any shortest cycle in G. Then it is clear that C is an isometric subgraph of G. This shows that if S is a general position set in G, then S ∩ V (C) is a general position set in C. Hence it follows from Theorem 2.2 that any general position set of G contains at most three vertices from the cycle C. Now, since gp(G) = n − 2, we have that the length of C is at most 5 and so girth(G) ≤ 5.
Next, we claim that there is no connected graph of order n with girth(G) = 5 and gp(G) = n−2. For, assume the contrary that there is a connected graph of order n with girth(G) = 5 and gp(G) = n − 2. Let C : u 1 , u 2 , u 3 , u 4 , u 5 , u 1 be a shortest cycle of length 5 in G. Since girth(G) = 5, it follows that the vertices from N (u i ) are independent for all i ∈ [5]. Also, as above we have that any general position set of G has at most three vertices from the cycle C. Let S be a general position set in G. Since gp(G) = n − 2, we have that S = V (G) \ {u i , u j }. If u i and u j are sucessive vertices in C, then it follows that the induced subgraph of S has a P 3 , which is impossible. Hence without loss of generality, we may assume that i = 1 and j = 3. So S = V (G) \ {u 1 , u 3 }. Now, since u 2 , u 4 , u 5 ∈ S and N (u i ) is independent, by Theorem 2.3, it follows that deg(u i ) ≤ 3 for i = 2, 4, 5. Now we claim that deg(u 2 ) = deg(u 4 ) = deg(u 5 ) = 2. Otherwise, we may assume that deg(u 2 ) = 3 and let x be the neighbour of u 2 different from u 1 and u 3 . Since girth(G) = 5, it follows that x is not adjacent with the remaining vertices of C. Now, since u 2 , u 5 , x ∈ S, by Theorem 2.3, d(u 5 , x) = d(u 5 , u 2 ) = 2. Let P : u 5 , y, x be a u 5 , x-geodesic of length 2. Then it is clear that y / ∈ V (C) and so y ∈ S. This leads to the fact that induced subgraph of S has a P 3 , impossible in a general position set. Hence deg( But gp(C 5 ) = 3 = n − 2 and diam(G) = diam(C 5 ) = 2. Hence there is no connected graph of order n with diam(G) = 3, girth(G) = 5 and gp(G) = n−2. Hence girth(G) is at most 4. Now, assume that girth(G) = 4 and let C : u 1 , u 2 , u 3 , u 4 , u 1 be a shortest cycle of length 4 in G. Since diam(G) = 3, we have that G C 4 . Now, we may assume that u 1 ∈ V (C) be a vertex such that deg(u 1 ) ≥ 3 and let x be a neighbour of u 1 such that x / ∈ V (C). Since S is a general position set and |S| = n − 2, we have that S contains exactly 2 vertices from C. We claim that u 1 / ∈ S. For otherwise assume that u 1 ∈ S. Since |S| = n − 2 and x, u 1 ∈ S, it follows from Theorem 2.3 that u 2 , u 4 / ∈ S and u 3 ∈ S. This shows that the path x, u 1 , u 2 , u 3 must be a x, u 3 -geodesic (otherwise, since |S| = n − 2, S contains an induced P 3 . Hence d(x, u 3 ) = d(u 1 , u 3 ), which is impossible in a general position set. Hence u 1 / ∈ S. Now, we claim that u 1 is the unique vertex in C with degree at least 3. Assume the contrary that there exists u j ∈ C with j = 1 and deg(u j ) ≥ 3. Then as above we have that u j / ∈ S. Now, if u i and u j are adjacent vertices in C, then we can assume that j = 2. It follows from the fact that S is a general position set of size n − 2, d(u 3 , x) = 3 and u 3 , u 4 , u 1 , x is a geodesic in G, where x is a neighbour of u 1 such that x / ∈ V (C). This shows that the vertices x, u 4 , u 3 , x lie on a common geodesic, a contradiction. Similarly if u 1 and u j are non adjacent vertices in C then u j = u 3 and u 2 , u 4 belong to S. Moreover, as above S is a general position set of size n − 2, we have that x, y ∈ S and d(x, y) = 4, where x ∈ N (u 1 ) \ V (C) and y ∈ N (u 3 ) \ V (C), which is impossible. Thus u 1 is the unique vertex in C with deg(u 1 ) ≥ 3. Also, since girth(G) = 4, we have that N (u 1 ) induces an independent set. Hence the graph belongs to F 1 . Now, consider girth(G) = 3 and diam(G) = 3. Let P : u, x, y, v be a u, vshortest path in G of length 3. Then S contains atmost 2 vertices from V (P ). Since |S| = n − 2, we have that S contains exactly two vertices from V (P ). We consider the following four cases. Subcase 1.1: u, v ∈ S. Then x, y / ∈ S. Moreover, S = V (G) \ {x, y}. Now, let z be any neighbour of u. Since S is a general position set of size n − 2, it follows that I[z, v] ⊆ V (P ). This shows that d(z, v) ≤ 3. If d(z, v) = 2, then z must be adjacent with y and so u, z, y, v is a u − v geodesic, which contradicts the fact that S is a general position set. Hence d(z, v) = 3 and since I[z, v] ⊆ V (P ), we have that z is adjacent with x but it is not adjacent with y. Similarly, we have that any neighbour of v is adjacent with y but non-adjacent with x. Now, assume that z be any vertex in G such that z / ∈ V (P ) and z is non-adjacent with both u and v. Then as in the previous case, we have that I[z, v] ⊆ V (P ). Also, we have d(z, v) ∈ {2, 3} and d(z, u) ∈ {2, 3}. Hence it follows that z is adjacent to x or y or both. Also, by Theorem 2.3, we have that the components of S are in-transitive distance-constant cliques. Hence the graph reduces to the class F 2 . Subcase 1.2: u, x ∈ S. Then y, v / ∈ S and S = V (G) \ {y, v}. Now, let z be any vertex in G such that z / ∈ V (P ). Then, we have that I[z, u] ⊆ V (P ). Moreover, by Theorem 2.3, d(z, u) = d(z, x). If d(z, x) = 2, then I[z, x] ⊆ V (P ), we have that z is adjacent to y. But in this case d(z, u) cannot be equal to 2. Similarly, if d(z, x) = 3 then z is adjacent with v but not y. Then it is clear that d(z, u) = 3. Hence it follows that d(z, u) = d(z, x) = 1. Again by Theorem 2.3, V (G) \ {y, v} induces a clique.