TITLE: Prove that $x\ge n(n-1)(n-3)/8$, where $x$ is the number of $4$-cycles in a graph on $n$ vertices with at least $\frac12\binom{n}{2}$ edges.
QUESTION [7 upvotes]: Prove that $x\ge \dfrac{n(n-1)(n-3)}8$, where $x$ is the number of $4$-cycles in a graph on $n$ vertices with at least $\displaystyle\frac12\,\binom{n}{2}$ edges.

If there are no $4$-cycles in a graph the edges in $G$, then the number of edges $e(G)$ of $G$ satisfies $$e(G)\le\frac n4(\sqrt{4n-3}+1)\,.$$
But if $e(G)\ge\displaystyle\frac12 {n \choose 2}$, we have to show that the number of $4$-cycles $x$ satisfies $$x \ge \dfrac{n(n-1)(n-3)}8\,.$$
I know that we have to find the difference of edges also the number of cycles of length $4$ is $${n \choose 4}\cdot \frac{3!}2$$ (where $\displaystyle n \choose 4$ is to account for the selection of $4$ vertices and $3!$ for ways of selecting and division by $2$ to delete reverse cycles). But am unable to incorporate the condition on edges and find my result.

REPLY [2 votes]: Lemma.
If $a_i\in\mathbb N_0$ for $1\le i\le N$ and $\sum a_i\ge M>0$ then
$$\sum_{i=1}^N{a_i \choose 2}\ge \frac{(M-N)M}{2N}$$
Proof.
Using the QM-AM inequality
$$ \frac{\sum_i a_i^2}N\ge \left(\frac{\sum_i a_i}{N}\right)^2$$
we find 
$$\begin{align}2 \sum_{i=1}^N{a_i \choose 2}
&=\sum a_i^2-\sum a_i\\
&\ge\frac1N\left(\sum a_i\right)^2-\sum a_i\\
&=\left(\frac 1N\sum a_i-1\right)\sum a_i\\
&\ge \frac{(M-N)M}{N}\end{align}$$
where the last inequality is justified even when the expressin in parentheses is negative because the left hand side is certainly non-negative. $_\square$
Each vertex of degree $d$ gives rise to ${d\choose 2}$ paths of length $2$. Thus using the lemma with $\sum_v d(v)=2e(G)\ge\frac{n(n-1)}2$, the number of length 2 paths is 
$$ n_2\ge\frac{(\frac{n(n-1)}2-n)\frac{n(n-1)}2}{2n}=\frac{n(n-1)(n-3)}{8}$$
For two distinct vertices $a,b$ let $f(a,b)$ be the number of $2$-paths from $a$ to $b$ (i.e., the number of common neighbours). Then 
$$\sum_{\{a,b\}}f(a,b)=n_2\ge  \frac{n(n-1)(n-3)}8$$
and 
$$2x = \sum_{\{a,b\}}{f(a,b)\choose 2}$$
so that by the lemma
$$x \ge \frac{(\frac{n(n-1)(n-3)}8-{n\choose 2})\frac{n(n-1)(n-3)}8}{2{n\choose 2}} =\frac{n(n-1)(n-3)(n-7)}{64}.$$
For $n\ge 15$, this implies the desired result.
After getting rid of the mistakes Batominovski kindly noticed, the result is  of course the same as his. :(