TITLE: Deriving the number of edges in a Turán graph
QUESTION [7 upvotes]: When stating Turán's theorem, the Turán graphs are often used to give an upper bound on the possible number of edges in a graph without a clique of a certain size. This bound can also be proven explicitly (see this  for different ways to state/prove the theorem).
But when the Turán graph is used, the number of its edges must be determined somehow. Wolfram gives us a number, but I really need to derive it somehow. So, again, in short: How is the number of edges in a Turán graph derived?

REPLY [6 votes]: This is a bit late, but I thought I would give an alternative to Brian M. Scott's derivation of the number of edges in the Turán graph $T(n,r)$ which involves a little more counting and a little less manipulation. I'll denote the number of edges in $T(n,r)$ by $t(n,r)$.
If $r$ evenly divides $n$, then as Adriano remarked, we have $r$ parts each of size $n/r$, and every edge between two different parts. Thus in this case,
$$
t(n,r)
=
{r\choose 2}\bigg(\frac{n}{r}\bigg)^2
=
\frac{r-1}{r}\cdot \frac{n^2}{2}.
$$
Now suppose $n$ isn't evenly divisible by $r$, and let $s$ denote the remainder, so $0<s<r$, and $n-s$ is divisible by $r$. The Turán graph $T(n,r)$ consists of $T(n-s,r)$ together with $s$ "extra vertices", which are distributed so that each part of $T(n-s,r)$ gets at most one extra vertex. The number of edges in $T(n-s,r)$ is given by our formula above. Each of the extra vertices is adjacent to all of the vertices of this $T(n-s,r)$ except for those in its part, and this accounts for $\frac{r-1}{r}s(n-s)$ edges in total. Finally, the extra vertices are all adjacent to each other, which contributes ${s\choose 2}$ edges. Putting this all together, we have
\begin{align*}
t(n,r)
&=
t(n-s,r)+\frac{r-1}{r}s(n-s)+{s\choose 2}\\
&=
\frac{r-1}{r}\left(\frac{(n-s)^2}{2}+s(n-s)\right)+{s\choose 2}\\
&=
\frac{r-1}{r}\cdot\frac{n^2-s^2}{2}+{s\choose 2}.\\
&=
\frac{r-1}{r}\cdot\frac{n^2}{2}-\frac{s(r-s)}{2r}.
\end{align*}