Many Triangles with Few Edges

Extremal problems concerning the number of independent sets or complete subgraphs in a graph have been well studied in recent years. Cutler and Radcliffe proved that among graphs with $n$ vertices and maximum degree at most $r$, where $n = a(r+1)+b$ and $0 \le b \le r$, $aK_{r+1}\cup K_b$ has the maximum number of complete subgraphs, answering a question of Galvin. Gan, Loh, and Sudakov conjectured that $aK_{r+1}\cup K_b$ also maximizes the number of complete subgraphs $K_t$ for each fixed size $t \ge 3$, and proved this for $a = 1$. Cutler and Radcliffe proved this conjecture for $r \le 6$. We investigate a variant of this problem where we fix the number of edges instead of the number of vertices. We prove that $aK_{r+1}\cup \mathcal{C}(b)$, where $\mathcal{C}(b)$ is the colex graph on $b$ edges, maximizes the number of triangles among graphs with $m$ edges and any fixed maximum degree $r\le 8$, where $m = a \binom{r+1}{2} + b$ and $0 \le b<\binom{r+1}{2}$.


Introduction
The problem of determining which graphs contain the largest number of complete subgraphs of size t has a long history. One can think of it as starting with the Kruskal-Katona Theorem concerning the shadows of uniform hypergraphs.
Theorem 1 (Kruskal [11], Katona [10]). Suppose that 1 ≤ ℓ ≤ t. If H ⊆ [n] t has size N , and we define then ∂ (ℓ) H is at least as large as ∂ (ℓ) C, where C ⊆ [n] t consists of the first N t-sets in colexicographic (or colex) order, and moreover ∂ (ℓ) C is an initial segment of ℓ-sets in the colex order. This immediately implies, by taking ℓ = 2 and H to be the set of complete subgraphs of size t in G, that any graph containing N complete subgraphs of size t must have at least ∂ (2) C edges, where C consists of the first N t-sets in colex order. This in turn implies an upper bound on the number of copies of K t in a graph on m edges. Similarly, since the optimal graphs are the same for all t, the colex graph C(m), whose edges are the first m pairs in colex order, has the largest number of complete subgraphs among all graphs with m edges.
These results have been extended in a number of directions, usually by restricting the class of graphs considered. If we write k(G) for the number of complete subgraphs in a graph G, k t (G) for the number of complete subgraphs of size t, and K t (G) for the set of complete subgraphs of size t, we wish to find upper bounds on k(G) and k t (G) over the class of graphs satisfying some constraints. One example is the following result due to Zykov [14] (see also [3,8,12,13]), which bounds the number of complete subgraphs in graphs with bounded clique number, ω(G).
We first state the rainbow Kruskal-Katona theorem.
Theorem 6 (Frankl, Füredi, and Kalai [4]). Suppose that 1 ≤ ℓ ≤ t. If H ⊆ N t has size N , and moreover H is ω-partite-i.e., we can partition N into ω subsets such that no set in H contains more than one element from each part-then ∂ (ℓ) H is at least as large as ∂ (ℓ) C, where C consists of the first N t-sets in R ω in colex order, and moreover ∂ (ℓ) C is an initial segment of Rω ℓ in colex order.
Frohmader's result exploits this theorem to extend its conclusion to flag complexes-set systems defined by the set of complete subgraphs in a graph.
Corollary 8. If G is a graph with m edges having ω(G) ≤ ω then for all t ≥ 2 we have k t (G) ≤ k t (R ω (m)), where R ω (m) is the graph whose edges are the first m 2-sets in R ω in colex order.
Proof. Define C to be the first k t (G) t-sets from R ω in colex order, and set m ′ = |∂ (2) C|.

1.2.
Results and Notation. We conjecture the following.
Conjecture 9. For any t ≥ 3, if G is a graph with m edges and maximum degree at most r, then where m = a r+1 2 + b and 0 ≤ b < r+1 2 . Conjecture 9 is the exact analogue of Conjecture 4: we build as many K r+1 's as we can, and then use our remaining resources optimally. Let's define f t (m, r) = max{k t (G) : G has m edges and ∆(G) ≤ r}.
First note that the conjecture is easily seen to be true asymptotically.
and moreover for fixed t and r, Proof. For the first bound, note that if G is a graph on m edges with ∆(G) ≤ r then the endpoints of an edge e of G have at most r −1 common neighbors, and complete subgraphs of size t in G containing e correspond to K t−2 's in this set of common neighbors. There are at most r−1 t−2 such K t−2 's, so, counting pairs (e, K) with e an edge of G and K ∈ K t (G) containing e, we have Thus where the final inequality comes from considering the graph that is the disjoint union of m ( r+1 2 ) copies of K r+1 and a matching to make the edge count up to m.
We were not able to show that it is sufficient to prove Conjecture 9 only for t = 3. Our main result is that the conjecture is true for triangles (t = 3) for r ≤ 8.
Main Theorem. If G is a graph with m edges and maximum degree at most r for any fixed r ≤ 8, then where m = a r+1 2 +b and 0 ≤ b < r+1 2 . That is, the graphs with the maximum number of triangles consist of as many disjoint copies of K r+1 as possible, with the remaining edges formed into a colex graph.
Most of our graph theory notation is standard; see for instance Bollobás [1] for a reference. In particular we will write (as we have done above) G ∪ H for the disjoint union of G and H, and also nG for the disjoint union of n copies of G.
We write G(m, r) for the set of graphs G with m edges and having ∆(G) ≤ r. In this class it will be handy to single out the connected ones; we write G C (m, r) for these.
In Section 2 we prove some general results saying that in proving the conjecture we may restrict our attention to connected graphs that achieve maximum degree r. In Section 3 we introduce an approach parallel to the folding technique in [2], and in Section 4 we discuss how this restricts the class of potentially extremal graphs. In Section 5 we give constraints on the extremal graphs in terms of their degree multisets. Finally, in Section 6, we combine these two approaches to prove the main theorem.

Disconnected graphs and graphs with small maximum degree
In this section, we prove two results that hold for all r and allow us to restrict our attention to connected graphs with maximum degree equal to r. Both are corollaries of the following lemma concerning colex graphs. The colex graph C(b) consists of a complete graph of size c, where c 2 ≤ b < c+1 2 , and then potentially one more vertex, joined to d vertices of the K c , where d = b − c 2 . Given this structure it is often useful to think of b as written in the form b = c 2 + d where 0 ≤ d < c. We abbreviate this fact as b = [c, d], and write C(c, d) for C([c, d]). It is easy to check that We in fact also allow d = c: we have [c, c] = [c + 1, 0], and the above formula for k 3 still applies.
Thus, the number of triangles in the conjectured extremal graph, which we denote by g 3 (m, r), can be written as where m = a r+1 We split into cases depending on the values of the d i .
Without loss of generality, Case 11.2: Exactly one of d 1 , d 2 is zero.
Without loss of generality, c 1 ≥ c 2 .
Subcase 11.2.1: so we may assume that it is d 1 that is zero. We compare G to the graph Note first that there are enough edges to do this because c 2 ≥ d 2 + 1 ≥ 2, and d 2 ≥ 1, so if c 2 = 2 then b 2 = 2, and if c 2 ≥ 3 then b 2 > c 2 2 ≥ c 2 . To prove the second equality above we have Note that in the representation C(c 1 , Subcase 11.2.2: d 2 = 0 and d 1 ≥ c 2 We compare G to the graph To prove the second equality, we have Otherwise, c 2 ≥ 3, so c 2 2 ≥ c 2 , and we compare G to To prove the second equality, we have This move yields a net gain of Corollary 12. If the Main Theorem holds for numbers of edges up through m − 1, and G ∈ G(m, r) is not connected, then k 3 (G) ≤ g 3 (m, r).
By the Main Theorem for smaller values of m, In all other cases, by Lemma 11 we have .
, and the Main Theorem holds for maximum degree at most r − 1 and for numbers of edges up through m − 1, then ∆(G) = r.
Proof. The statement is trivial for r = 2, so assume r ≥ 3. Suppose ∆(G) ≤ r − 1, so G ∈ G(m, r − 1). By the Main Theorem for r − 1, we have since f 3 is a superadditive function of m.

Edge Weights, Clusters, and Folding
In this section we introduce a 'folding' operation that acts on a graph containing a large subset of vertices with as many common neighbors as is possible. To this end we define the weight of a pair of vertices to be the number of common neighbors they have: w(xy) = |N (x)∩N (y)| for any x, y ∈ V (G). In particular if xy is an edge this is the number of triangles containing that edge. If xy is a non-edge this is the number of triangles we would gain by adding that pair as an edge. The maximum possible weight of an edge xy is w(xy) = r − 1, which occurs exactly when d(x) = d(y) = r and N [x] = N [y]. (Note that a non-edge can have weight r. If x ∼ y, d(x) = d(y) = r, and N (x) = N (y), then x and y have r common neighbors, but we cannot add the edge xy to complete r triangles as x and y already have the maximum degree.) Definition 14. An edge xy ∈ E(G) is called tight if w(xy) = r − 1. A complete subgraph in G, all of whose edges are tight, is called a tight clique, and a maximal tight clique is called a cluster.
For any cluster T , let S T = v∈T N (v), the set of common neighbors of T . For v ∈ T , every other vertex x ∈ T has r − 1 neighbors in common with v. They must be the same common neighbors for each If G contains a cluster of size r+1, then it contains a copy of K r+1 , and it is disconnected. What we'll investigate is the situation in which there is a cluster T with |T | < r + 1, and try to understand the edges missing from We will consistently write t for |T |, S for S T , s for |S T |, R for R T , and B for B T . We refer to R as the red graph and the edges of B as blue edges. We will also define a, b, c, and d from m and r by m = a r+1 The following simple bound on the weight of a blue edge will aid in determining effects of local moves.
Lemma 15. Each blue edge has weight at most s − 2.
Proof. Let xy be a blue edge with x ∈ S. We will separately count the possible common neighbors z in and out of S. There are at most s − 1− d R (x) neighbors z of x that are in S. For z / ∈ S, xz is also a blue edge, and d B (x) ≤ d R (x) to maintain d G (x) ≤ r. The maximum number of such z's then is d R (x)−1. In total, xy is in at most s−1−d R (x)+d R (x)−1 = s−2 triangles.
We will often find it useful to delete all the blue edges from a cluster and add all the red edges. We call this operation folding: Definition 16. For G ∈ G(m, r) with a cluster T and e(B) ≥ e(R), we define a new graph G T ∈ G(m, r) by converting T ∪ S T into a complete subgraph (of size r + 1) and deleting all the edges in B T . In other words, we define the folding of G at T by The graph G T contains a K r+1 , has maximum degree at most r, and has at most m edges since e(B) ≥ e(R). If we can show that e(B) ≥ e(R) and k 3 (G T ) ≥ k 3 (G), then by induction on m,

Excluded Red Graphs R
In this section we identify several graphs that cannot occur as R in an extremal graph G because folding (when e(B) ≥ e(R)) or another local move (when e(B) < e(R)) would increase the number of triangles. Our first step toward identifying when folding increases the number of triangles in G will be to give an upper bound on the number of blue triangles, or triangles containing two blue edges. We will use a compression argument, in which we determine which configuration of blue edges is least helpful to us.
Definition 17. For vertices x ∼ y and N (x) ⊆ N (y), the compression of G from x to y, denoted G x→y , is the graph obtained from G by deleting all edges between x and N (x) \ N (y) and adding all edges from y to N (x) \ N (y).
We define an auxiliary function to use in the compression argument.
We will use compressions to maximize the following function and bound the number of blue triangles.
Definition 19. For a graph H and a bipartite graph B with bipartition (V (H), Y ), we define This function counts the number of blue triangles when applied to the situation where H is the red graph R T and e∈E(B T ) e \ S T induces a complete subgraph. Thus it serves as an upper bound on the number of blue triangles for a given red graph. Proof. For all v ∈ V (H), we have d B (v) = d Bx→y (v) and therefore v∈V (H) . H is fixed, and x is the only vertex of Y that loses neighbors, so any decrease in v∈Y |{i, j ∈ V (H) : i = j, iv, jv ∈ E(B), xy / ∈ E(H)}| would be from the x term: pairs i, j ∈ H that are neighbors of x and not adjacent in H. If i, j ∈ N (y), then the edges ix and jx remain after the compression, so the pair i, j is still counted in the x term of the summation. If one or both of i, j / ∈ N (y), then the pair i, j is counted in the y term of the summation after the compression but not before, compensating for the loss in the x term.
Let ℓ := |N (x) \ N (y)| > 0. Then Bipartite threshold graphs can be defined in different ways, but the following lemma gives the characterization we will use. Corollary 24. For a given red graph R, the number of blue triangles at R is at most There are two types of blue triangles.
(1) One vertex in R and two blue edges at that vertex: There are at most v∈R triangles of this type. (2) Two adjacent vertices in S (non-adjacent in R) and one blue edge at each of these vertices to the same third vertex outside S: There are triangles of this type. The total number of blue triangles at R is exactly ψ R (B), which by Lemma 23 is maximized by some bipartite threshold blue graph B. The definition of R and ∆(G) ≤ r imply d B (v) ≤ d R (v) for all v ∈ R. Adding edges can only increase the number of blue triangles, so we may assume that d B (v) = d R (v) for all v ∈ R. These blue degrees in R completely determine the graph B because the neighborhoods of vertices in Y are nested. Any vertex i ∈ R has d R (i) neighbors in Y , and a pair i, j ∈ R has min(d R (i), d R (j)) common neighbors in Y .
Having given an upper bound on the number of blue triangles, we turn our attention to a lower bound on the number of red triangles gained from folding G at T .
Definition 25. For a graph R with s vertices, we define Lemma 26. If G has a cluster T with e(B) ≥ e(R), then k 3 (G T ) − k 3 (G) ≥ Q(R).
Proof. We will bound k 3 (G T ) − k 3 (G) by counting the triangles gained and lost by folding at T . Three types of triangles are gained by folding.
(1) One red edge and one vertex in T : There are te(R) triangles of this type.
(2) One or two red edges, and all vertices in S: Each triangle of this type contains exactly two unordered pairs of an incident edge and non-edge, and each such pair occurs in a triangle of this type. By counting these pairs and dividing by two, we find there are 1 Thus the total number of triangles gained from folding is The total number of triangles lost from folding is at most by Corollary 24.
The net gain from folding, k 3 (G T ) − k 3 (G), is at least Lemma 27. If s ≤ r+2 2 , then Q(R) ≥ 0, with equality if and only if R = E s . Proof. Note Q(E s ) = 0. We will show that E s is the unique minimizer of Q(R). If R has an edge xy, then deleting it would strictly decrease Q(R). We will consider the net change in Q(R) term by term. The change in the (r + 1 − s)e(R) term is −(r + 1 − s) since we are losing one edge. The change in the r). Proof. As G is connected, there is at least one blue edge. Case 28.1: 0 < e(B) < e(R) We will delete all of the blue edges and add e(B) of the red edges, which will maintain the number of edges and the bound on the maximum degree. The loss from deleting the blue edges is at most (s − 2)e(B) by Lemma 15. The gain from the red edges is at least te(B), as each red edge has t common neighbors in T . Therefore the net gain is at least By Lemmas 26 and 27, since δ(R) ≥ 1, folding G at T strictly increases the number of triangles, so G is not extremal.
Proof. Any red graph has δ(R) ≥ 1, so R = s 2 K 2 . Case 29.1: 0 < e(B) < e(R) There is a red edge that is not incident to any blue edges. Add that red edge, and delete a blue edge. The blue edge is in at most s − 2 triangles by Lemma 15. The red edge has weight r − 1. The net gain in number of triangles is at least r − 1 − (s − 2) = r + 1 − s ≥ 1, so k 3 (G) < f 3 (m, r).
Proof. Any red graph has δ(R) ≥ 1. Let k be the number of vertices with red degree 2, so s − k is the number of vertices with red degree 1. By the degree sum formula, 2e(R) = 2k + (s − k) = s + k.
For t ≥ 2, each term of this last expression is non-negative, and st/2 > 0, so Q(R) > 0. For t = 1, with equality only when all vertices of R have red degree 2 and there are no triangles, i.e. R is a disjoint union of non-triangle cycles.
Proof. There is at least one blue edge because G is connected. By Lemma 30, Q(R) > 0, so if e(B) ≥ e(R), then k 3 (G) < f 3 (m, r). Now suppose 0 < e(B) < e(R). We will show that there is a red edge that is incident to at most one blue edge. The average number of blue edges at a given red edge is 1 e(R) Thus there is a red edge xy incident to at most one blue edge. The vertices x and y may each have one other neighbor in R. The remaining r + 1 − 2 − 2 = r − 3 vertices in the cluster are neighbors of both x and y in G, so xy has weight at least r − 3. The blue edge has weight at most s − 2 by Lemma 15. Deleting the blue edge (or any blue edge, if there is none at xy) and adding the red edge xy yields a net gain of at least r − 3 − (s − 2) = r − s − 1 = t − 2 ≥ 0 triangles since t ≥ 2, a weak increase that reduces the number of red edges. By induction on the number of red edges, we are done. (The base case e(R) = 1 is done by Lemma 29.) Theorem 32. If G ∈ G C (m, r) for r ≥ 3 has a cluster with e(R) ∈ {1, 2}, then k 3 (G) < f 3 (m, r).
Proof. If e(R) = 1, then R = K 2 , and by Lemma 29 we're done. If e(R) = 2, then R = 2K 2 or R = P 3 . For R = 2K 2 , we are again done by Lemma 29. Consider R = P 3 . G is connected, so e(B) ≥ 1. Any blue edges have weight at most s − 2 = 1 by Lemma 15. Each red edge has weight r − 2. If e(B) = 1, delete the blue edge and add a red edge for a net gain of at least r − 2 − 1 = r − 3 triangles, a weak increase for r ≥ 3. This reduces to the case R = K 2 .
, then folding will increase the number of triangles, and G was not extremal. Otherwise, 1 ≤ e(B) ≤ 3. The isolated K 2 in R has weight r − 1 ≥ 7. Any blue edge has weight at most s − 2 = 4. If there is only one blue edge incident to the red K 2 (or none), then delete it (or any blue edge) and add the edge corresponding to the red K 2 , which increases the number of triangles by at least 7 − 4 = 3. Otherwise, there are 2 blue edges incident to the red K 2 , so 0 or 1 blue edges incident to the red K 1,3 . Deleting a blue edge (from the K 1,3 if needed) and adding one of the red K 1,3 edges increases the number of triangles by at least 5 − 4 = 1. Therefore G was not extremal.

Degree Multiset Optimization
The number of triangles in a graph can be bounded easily (but crudely) as follows: We have shown, in Section 4, that vertices of degree r lie in clusters with certain red graphs forbidden. In this section we consider the possible degree multisets to give an upper bound on the number of triangles in graphs G that do not have any of the excluded red graphs R considered in Section 4. We consider the constraints imposed by the trivial bound above.
For instance, when r ≥ 3, Theorem 32 shows that in an extremal connected graph, every cluster is missing at least three edges. Similarly, for r = 7 and 8, Theorems 33 and 34 show that in an extremal connected graph, every cluster is missing at least four or five edges, respectively. We define upper bounds for k 3 (G) based on the degree multiset of G. Proof. Apply (1), and observe that (in each case) the degree multiset of G is one of the candidates in the maximization by Corollary 13.
We will show in many cases the lower bounds we have on the number of edges in red graphs ensure that the upper bound from Lemma 36 is less than the number of triangles in aK r+1 ∪ C(b), proving the Main Theorem in those cases. We say that a multiset D is optimal if it achieves the maximum M k (m, r) and has no 0 entries.
Lemma 37. An optimal multiset D contains at most one entry from [r − 2].
Proof. If an optimal multiset D had two elements in [r − 2], x ≤ y, then changing these two elements to x − 1 and y + 1 maintains the sum of 2m while increasing the weighted sum d∈D w(d), contradicting the optimality of D. If x − 1 = 0, then the 0 is discarded, and x = 1 and y are replaced by y + 1. The weighted sum is increased because Lemma 38. For any m and r ≤ 2k + 1, if an optimal multiset D contains an entry d ∈ [r − 2] and at least r − 1 − d copies of r, then there is an optimal multiset containing no entries from [r − 2].
Proof. We will change the r − 1 − d copies of r and the d ∈ [r − 2] to r − d copies of r − 1. The resulting multiset contains no entries from [r − 2] by Lemma 37.

Proof of Main Theorem
We now prove our main theorem.
Main Theorem. If G is a graph with m edges and maximum degree at most r for any fixed r ≤ 8, then k 3 (G) ≤ k 3 (aK r+1 ∪ C(b)), where m = a r+1 2 +b and 0 ≤ b < r+1 2 . That is, the graphs with the maximum number of triangles consist of as many disjoint copies of K r+1 as possible, with the remaining edges formed into a colex graph.
Proof. We will induct on m and r. For m ≤ r+1 2 , the Kruskal-Katona Theorem implies the theorem, so we may assume m ≥ r+1 2 + 1. Let G be an extremal graph. By Corollary 12 and induction on m, if G is not connected, then k 3 (G) ≤ k 3 (aK r+1 ∪ C(b)), so we assume G is connected. In particular, G does not contain a K r+1 . By Corollary 13 and induction on m and r, G contains a vertex of degree r. Therefore G contains a cluster, and every cluster has at least one red edge and at least one blue edge.
For r = 1, every G ∈ G(m, 1) has k 3 (G) = 0 = k 3 (aK 2 ∪ C(b)). For r = 2, we have assumed G does not contain a K r+1 = K 3 , so there are no triangles, and G is not extremal.

Open Problems
The question "Which graphs with a fixed number of edges m and maximum degree at most r maximize the number of K t 's?" remains open for maximum degrees r ≥ 9 and for complete subgraph sizes t ≥ 4. Similarly, the corresponding question when fixing the number of vertices n instead of the number of edges remains open for r ≥ 7 except when a = 1. Both are extremely natural questions.