I am very interested in the maximum number of triangles could a connected graph with $n$ vertices and $m$ edges have. For example, if $m\leq n−1$, this number is $0$, if $m=n$, this number is $1$, if $m=n+1$, this number is $2$, and if $m=n+2$, this number is $4$. 



How many triangles can a connected graph with $n$ vertices and $m$ edges have?
It is a bound and since it is very long, I wrote it an answer, may be it can be helpful.


Let $G$ be a connected graph with $n$ vertices and $m$ edges. Suppose the eigenvalues of this graph are $\lambda\_1\geq \lambda\_2\geq\ldots\geq\lambda\_n$. We know that $\sum{\lambda\_i^3}=6\Delta\_G$, where $\Delta\_G$ counts the total number of triangles of the graph $G$.


Also,we have:


$$\lambda\_1\leq\sqrt{2m-\delta(n-1)+\Delta(\delta-1)}.$$


Since your graph is connected, we can set $\delta=1$ and obtain:
$$\lambda\_1\leq\sqrt{2m-n+1}.$$


So we have:


$$\Delta\_G\leq\frac{n}{6}(2m-n+1)^{\frac{3}{2}},$$


as you wanted in your comments.


Actually, you can get more information from this method since we exactly know when the upper inequalities which I used are equality for which graphs. You can search for "SHARP UPPER BOUNDS OF SPECTRAL RADIUS OF GRAPHS" or similar keywords.


