The number of $4$-cycles and the cyclomatic number of a finite simple graph

Abstract: Let $G$ be a finite connected simple graph with $n$ vertices and $m$ edges. We show that, when $G$ is not bipartite, the number of $4$-cycles contained in $G$ is at most $\binom{m-n+1}{2}$. We further provide a short combinatorial proof of the bound $\binom{m-n+2}{2}$ which holds for bipartite graphs.

\section*{Introduction}
In enumerative combinatorics on finite graphs, counting the number of cycles contained in a finite simple graph is one of the most traditional problems.  Let $G$ be a finite connected simple graph with $d$ vertices and $e$ edges.  Let $c(G)$ denote the number of cycles of $G$.
It is known that
$$
e-d+1 \le c(G) \le 2^{e-d+1} -1,
$$
where $e-d+1$ is called the {\em cyclomatic number} of $G$.
Let $c_4(G)$ denote the number of $4$-cycles of $G$ and $k_4(G)$ that of $K_4$, the complete graph with $4$ vertices.  In the language of commutative algebra, the invariant $c_4(G) - k_4(G)$ coincides with the graded Betti number $\beta_{1,2}$ of the edge ring (\cite{simpleedgepolytope}) of $G$.  Hence, by virtue of \cite[Corollary~2.6]{HSZ}, it follows that
\[
c_4(G) - k_4(G) \leq \binom{e-d+1}{2}
\]
if $G$ has at least one odd cycle and that
\begin{eqnarray}
\label{Sydney}
c_4(G) \leq \binom{e-d+2}{2}
\end{eqnarray}
if $G$ is bipartite.  It is then reasonable to discover a finite connected simple graph $G$ with $k_4(G) > 0$ for which $c_4(G) - k_4(G) = \binom{e-d+1}{2}$.  However, our effort has failed to find a desired example.  It turns out that, taking our failure into account, we cannot escape from the temptation to prove the inequality $c_4(G) \le \binom{e - d + 1}{2}$ for any finite connected simple graph with $d$ vertices and $e$ edges.  In fact, the main result of the present paper is

\begin{Theorem}
\label{maintheorem}
Let $G$ be a finite connected simple graph with $d$ vertices and $e$ edges, and $c_4(G)$ the number of $4$-cycles of $G$.  Suppose that $G$ has at least one odd cycle.  Then
\begin{eqnarray}
\label{Boston}
c_4(G) \le \binom{e - d + 1}{2}.
\end{eqnarray}
\end{Theorem}

Theorem \ref{maintheorem} will be proved in Section $2$.  In addition, a purely combinatorial proof of the inequality (\ref{Sydney}) will be achieved (Proposition \ref{anotherproof}).

\section{Graphs with at most one $K_4$}

Let $G$ be a finite connected simple graph with $d$ vertices and $e$ edges.
Given a graph $G$,
let $c_4(G)$ denote the number of $4$-cycles of $G$ and $k_4(G)$ that of $K_4$, the complete graph with $4$ vertices.
First, we give examples such that equality holds in equations (\ref{Sydney}) and (\ref{Boston}).

\begin{Example}
\label{complete}
Let $K_d$ denote the complete graph on $d \ge 4$ vertices
and $K_{\ell,m}$ the complete bipartite graph on the vertex set
$\{1,\ldots, \ell\} \cup \{\ell+1,\ldots, \ell+m\}$.
Then
$$
c_4(K_d)
= 3 \cdot \binom{d}{4}
=\frac{d(d-1)(d-2)(d-3)}{8}= \binom{e -d+1}{2}
$$
and
\begin{eqnarray*}
\binom{e -d + 2}{2} -
c_4(K_{\ell, m})
&= &
\binom{\ell m  - (\ell+m) + 2}{2}
-
\binom{\ell}{2}
\binom{m}{2}\\
&=& \frac{ (\ell-1) (\ell-2) (m-1)(m-2)}{4}  \ge 0.
\end{eqnarray*}
Note that $\binom{e -d + 2}{2} =
c_4(K_{\ell, m})  $ if and only if either $\ell \le 2$ or $m \le 2$.
\end{Example}

Given a graph $G$ on the vertex set $\{1,\ldots,d\}$, let ${\mathcal P}_G \subset {\NZQ R}^d$ denote the convex hull of
$\{{\bf e}_i + {\bf e}_j \ | \ \{i,j\} \in E(G)\}$, where ${\bf e}_i$ is
the $i$th unit coordinate vector in ${\NZQ R}^d$.
The polytope ${\mathcal P}_G$ is called the {\em edge polytope} of $G$.
Let $f_1(G)$ be the number of the edges of the edge polytope of $G$.
Several bounds for $f_1(G)$ are given in \cite{HMOS, TZ}.
In particular, the following proposition appears in \cite{TZ}.

\begin{Proposition}
\label{TZ}
Let $G$ be a graph with $e$ edges.
Then $$f_1(G) = \frac{e(e-1)}{2} - 2c_4(G)+3k_4(G).$$
\end{Proposition}

By using this fact, we have the following.

\begin{Proposition}
\label{fromTZ}
Let $G$ be a connected graph with $d$ vertices and $e$ edges.
\begin{itemize}
\item[(i)]
If $G$ is a bipartite graph, then
$$
c_4(G) \le \frac{e(e-d+1)}{4},
$$
with equality holds if and only if $G$ is a tree or a complete bipartite graph.

\item[(ii)]
If $G$ has at least one odd cycle and no $K_4$, then
$$
c_4(G) \le \frac{e(e-d)}{4},
$$
with equality holds if and only if $G$ has exactly one cycle and the length of the cycle is odd.
\item[(iii)]
If $G$ has at least one $K_4$, then
$$
c_4(G) < \frac{e(e-d)}{4} + \frac{3}{2}k_4(G).
$$

\end{itemize}
\end{Proposition}

\begin{proof}
By Proposition \ref{TZ}, we have
\begin{equation}
\label{fromTZshiki}
c_4(G) = \frac{1}{2} \left(\frac{e(e-1)}{2} - f_1(G)+3k_4(G)\right)
= \frac{e(e-1)}{4} -  \frac{1}{2}f_1(G) + \frac{3}{2}k_4(G).
\end{equation}
It is known \cite[Proposition 1.3]{normal} that the dimension of ${\mathcal P}_G$ is
$$
\dim {\mathcal P}_G =
\left\{
\begin{array}{cc}
d-2 & \mbox{ if } G \mbox{ is bipartite,}\\
\\
d-1 &  \mbox{otherwise.}
\end{array}
\right.
$$
Since ${\mathcal P}_G$ has $e$ vertices and
at least $\dim {\mathcal P}_G$ edges of ${\mathcal P}_G$ are incident to a vertex of ${\mathcal P}_G$,
$$
f_1(G) \ge
\left\{
\begin{array}{cc}
\frac{e(d-2)}{2} &\mbox{ if }  G \mbox{ is bipartite,}\\
\\
\frac{e(d-1)}{2} &  \mbox{otherwise.}\\
\end{array}
\right.
$$
Thus by (\ref{fromTZshiki}), we have
$$
c_4(G)  \le \left\{
\begin{array}{cc}
\frac{e(e-d+1)}{4} & \mbox{ if } G \mbox{ is bipartite,}\\
\\
\frac{e(e-d)}{4} + \frac{3}{2}k_4(G)&  \mbox{otherwise,}\\
\end{array}
\right.
$$
with equality holds if and only if the edge polytope of $G$ is a simple polytope.
Simple edge polytopes are classified in \cite{simpleedgepolytope}.
The edge polytope ${\mathcal P}_G$ is simple if and only if
either ${\mathcal P}_G$ is a simplex or $G$ is a complete bipartite graph.
It is known that ${\mathcal P}_G$ is a simplex if and only if either $G$ is a tree or
$G$ has exactly one odd cycle and it is a unique cycle of $G$.
In particular, if the edge polytope of $G$ is simple,
then $G$ has no $K_4$.
\end{proof}

Let
$$
\varepsilon(G) =
\left\{
\begin{array}{cc}
1 & \mbox{ if } G \mbox{ is bipartite},\\
0 & \mbox{otherwise}.
\end{array}
\right.
$$
By the following lemma, we often assume that a graph $G$ is 2-connected.

\begin{Lemma}
\label{2connected}
Let $G_1, \ldots, G_s$ {\rm (}$s \ge 2${\rm )} be
$2$-connected components of a connected graph $G$.
Let $d_i$ {\rm (}resp. $e_i${\rm )} be the number of the vertices {\rm (}resp. edges{\rm )} of $G_i$.
If
$$
c_4(G_i) \le
\binom{e_i-d_i+1+\varepsilon(G_i)}{2}
$$
for all $1 \le i \le s$,
then we have
$$
c_4(G) \le \binom{e -d +1+\varepsilon(G)}{2},
$$
with equality holds if and only if
$c_4(G_i) =
\binom{e_i-d_i+1 + \varepsilon(G_i)}{2}$ for all $1 \le i \le s$ and
either
(a) all of $G_2, \ldots, G_s$ are bridges of $G$;
or
(b)
$G_1$ is a bipartite graph  and
$G_2$ is an odd cycle, and $G_3, \ldots, G_s$ are bridges of $G$.
\end{Lemma}

\begin{proof}
Suppose that two connected graphs $H_1$ and $H_2$ have exactly one common vertex.
Let $p_i$ (resp. $q_i$) denote the number of vertices (resp. edges) of $H_i$ and let $H = H_1 \cup H_2$.
Note that $ c_4(H) =c_4(H_1) + c_4(H_2) $ and $\varepsilon(H) = \varepsilon(H_1) \cdot \varepsilon(H_2)$.
Hence  we have
\begin{eqnarray*}
 & & \binom{(q_1+q_2) - (p_1+p_2 -1) +1+\varepsilon(H)}{2} - c_4(H) \\
&\ge&
\binom{(q_1+q_2) - (p_1+p_2) +2+\varepsilon(H)}{2}\\
&& \ \ \ \ \ \  -\binom{q_1-p_1+1+\varepsilon(H_1)}{2}-\binom{q_2-p_2+1+\varepsilon(H_2)}{2}\\
\\
&=&
\left\{
\begin{array}{cl}
(q_1-p_1+1) (q_2-p_2+1) & \mbox{ if } \varepsilon(H_1)=\varepsilon(H_2),\\
\\
(q_1-p_1) (q_2-p_2+1) & \mbox{ if } \varepsilon(H_1) =0 \mbox{ and } \varepsilon(H_2)=1
\end{array}
\right.
\end{eqnarray*}
is nonnegative.
(The last value is zero if and only if
either (i) at least one of $H_i$ is a tree or (ii) $H_1$ has exactly one cycle and the length of the cycle is odd
 and $H_2$ is bipartite.)
Thus
$$
c_4(H) \le
\binom{(q_1+q_2) - (p_1+p_2 -1) +1+\varepsilon(H)}{2}.
$$
Applying this argument to $G_1, \ldots, G_s$, we have a desired conclusion.
\end{proof}

We now give a purely combinatorial proof of the inequality (\ref{Sydney}).

\begin{Proposition}
\label{anotherproof}
Let $G$ be a connected bipartite graph.
Then
$$
c_4(G) \le \binom{e-d+2}{2}.
$$
When $G$ has no vertices of degree one,
equality holds if and only if $G$ is the complete bipartite graph $K_{2, d-2}$.
\end{Proposition}

\begin{proof}
We proceed by induction on $d$ and $e$.
Let $G$ be a bipartite graph such that
$
c_4(G) > \binom{e-d+2}{2}.
$
By Lemma \ref{2connected}, we may assume that
$G$ is 2-connected.
Let $G'$ be a subgraph of $G$ obtained by deleting an edge $e_0$ of $G$.
Then $G'$ is connected.
Let $c_4(e_0)$ denote the number of 4-cycles of $G$ containing $e_0$.
By the hypothesis of induction, we have
$$
c_4(G') \le \binom{(e-1)-d+2}{2}
=
\binom{e-d+2}{2} - (e-d+1).
$$
Hence $e-d+2 \le c_4(e_0)$.
Since all edges satisfy this condition,
$$
c_4(G) \ge \frac{e(e-d+2)}{4}
>\frac{e(e-d+1)}{4}.
$$
This contradicts to Proposition \ref{fromTZ}.

On the other hand, let $G$ be a bipartite graph such that
$
c_4(G) =  \binom{e-d+2}{2}
$
and that $G$ has no vertices of degree one.
By Lemma \ref{2connected}, $G$ has no bridges since $G$ has no vertices of degree one.
Let $G'$ be a subgraph of $G$ obtained by deleting an edge $e_0$ of $G$.
Since
$$
c_4(G') \le \binom{(e-1)-d+2}{2}
= c_4(G) - (e-d+1)
$$
holds, it follows that $e-d+1 \le c_4(e_0)$ for each edge $e_0 \in E(G)$.
By Proposition \ref{fromTZ},
$c_4(G) =\frac{e(e-d+1)}{4}$ and hence $G$ is a complete bipartite graph.
Since $G$ is not a tree,  $e-d+1\neq 0$.
Hence
$\frac{(e-d+1)(e-d+2)}{2}=\frac{e(e-d+1)}{4}$ if and only if $e=2(d-2)$.
It then follows that $G$ is the complete bipartite graph $K_{2, d-2}$.
\end{proof}

We now show that, if $G$ has at most one $K_4$, then the inequality (\ref{Boston}) holds.
Note that graphs satisfying one of the conditions (a)--(c) below
appeared in \cite[Theorem~4.6]{simpleedgepolytope}
as graphs whose edge ring has $2$-linear resolution.

\begin{Theorem}
\label{withoutk4}
Let $G$ be a connected graph having at least one odd cycle.
If $k_4(G) \le 1$, then we have
$$
c_4(G) \le \binom{e-d+1}{2}.
$$
When $G$ has no vertices of degree one and $k_4(G)=0$,
equality holds if and only if $G$ is one of the following:
\begin{itemize}
\item[(a)]
 an odd cycle;
\item[(b)]
a graph
obtained by adding a path to
the complete bipartite graph $K_{2, m}$;
\item[(c)]
$2$-connected components of $G$ consist of $K_{2,m}$, an odd cycle and bridges.
\end{itemize}
\end{Theorem}

\begin{proof}
We proceed by induction on $d$ and $e$.
Let $G$ be a connected graph having at least one odd cycle
such that $k_4(G) \le 1$ and
$
c_4(G) > \binom{e-d+1}{2}.
$
By Lemma \ref{2connected}, we may assume that $G$ is 2-connected.
Let $G'$ be a subgraph of $G$ obtained by deleting an edge $e_0$ of $G$.
Then $G'$ is connected.
If $G'$ is bipartite, then there exists no $C_4$ that contains $e_0$.
Hence
$$
c_4(G) = c_4(G') \le \binom{(e-1)-d+2}{2}
= \binom{e-d+1}{2}
$$
which is a contradiction.
Thus $G'$ has at least one odd cycle.
By the hypothesis of induction, we have
$$
c_4(G') \le \binom{(e-1)-d+1}{2}
= \binom{e-d+1}{2} - (e-d).
$$
Hence $e-d+1 \le c_4(e_0)$.
Since all edges satisfy this condition,
$$
c_4(G) \ge \frac{e(e-d+1)}{4}.
$$
However, by Proposition \ref{fromTZ},
$$
c_4(G) \le \frac{e(e-d)}{4} <  \frac{e(e-d+1)}{4},
$$
if $G$ has no $K_4$, and
$$
c_4(G) < \frac{e(e-d)}{4} + \frac{3}{2}
\le \frac{e(e-d)}{4} + \frac{e}{4}
=
\frac{e(e-d+1)}{4}
$$
if $G$ has one $K_4$.
This is a contradiction.

On the other hand, let $G$ be a connected graph having at least one odd cycle
such that
$
c_4(G) = \binom{e-d+1}{2}
$
and that $G$ has no vertices of degree one.
By Lemma \ref{2connected} and Proposition~\ref{anotherproof}, if $G$ has a bridge, then
2-connected components of $G$ consist of $K_{2,m}$, an odd cycle and bridges.
Suppose that $G$ has no bridges.
Let $G'$ be a subgraph of $G$ obtained by deleting an edge $e_0$ of $G$.
Then $G'$ is connected.
If $G'$ is bipartite, then there exists no $C_4$ that contains $e_0$.
Thus we have
$$
c_4(G') = c_4(G) = \binom{e-d+1}{2}=
\binom{(e-1)-d+2}{2}.
$$
Hence $G'$ is either a tree or the complete bipartite graph $K_{2, m}$
(by removing vertices of degree one).
Therefore $G$ is either an odd cycle or a graph
obtained by adding a path to
 the complete bipartite graph $K_{2, m}$.
Suppose that for any edge $e_0$ of $G$,
the subgraph of $G$ obtained by deleting $e_0$ has at least one odd cycle.
Then
$$
c_4(G') \le \binom{(e-1)-d+1}{2}
= c_4(G) - (e-d).
$$
Hence $e-d \le c_4(e_0)$ for each edge $e_0$ of $G$.
If $k_4(G) = 0$, then by Proposition \ref{fromTZ},
$c_4(G)=\frac{e(e-d)}{4}$.
Since $G$ has no vertices of degree one, $G$ is an odd cycle.
This contradicts to the hypothesis that $G'$ has at least one odd cycle.
\end{proof}

\section{Proof of the main theorem}

Given a graph $G$ on the vertex set $[d] = \{1,\ldots,d\}$,
let $\delta(G)$ (resp. $\Delta(G)$) denote the {\em minimum} (resp. {\em maximum}) {\em degree} of $G$.
That is,
$$\delta(G) = \min \{ \deg_G(i) \ | \ i \in [d]\}, \ \
\Delta(G) = \max \{ \deg_G(i) \ | \ i \in [d]\}.
$$
In this section we will give an upper bound for $c_4(G)$ in terms of
$\left(e - \frac{\delta(G)}{2} d\right)^2 $
and prove the main theorem  (Theorem \ref{maintheorem}) of the present paper.

A {\em clique} of a graph $G$ is a subgraphs of $G$ that are complete graphs.
The {\em clique number} $\omega(G)$ of a graph $G$ is the number of vertices in a maximum clique in $G$.
If $\omega(G) =d$, then $G=K_d$.
On the other hand, if $\omega(G)$ is at most $3$, then $G$ has no $K_4$
and hence the inequality (\ref{Boston}) holds for $G$.

\begin{Example}
\label{large:w(G)}
Let $G$ be a connected graph with $d \ge 4$ vertices and $\omega(G) =d-1$.
Then $K_{d-1}$ is a subgraph of $G$.
Suppose that $e=\binom{d-1}{2}+k$ where $1 \le k \le d-2$.
Then
\begin{eqnarray*}
&&
\binom{e-d+1}{2} - c_4(G) \\
&=&
\frac{(\binom{d-1}{2}+k-d)(\binom{d-1}{2}+k-d+1)}{2}
-
3 \binom{d-1}{4} - (d-3) \binom{k}{2}\\
&=&
\frac{(d-4) (k-1) (d-1-k)}{2}  \ge 0.
\end{eqnarray*}
Thus $c_4(G) \le \binom{e-d+1}{2}$,
with equality holds if and only if either $d=4$ or $k=1$.
\end{Example}

Given a graph $G$ on the vertex set $[d]$,
let $$\Sigma_2 = \sum_{i=1}^d \deg_G(i)^2.$$
Several upper bounds for $\Sigma_2$ are known.
For example, if $\delta = \delta(G)$ and $\Delta = \Delta(G)$, then
\begin{eqnarray}
\Sigma_2
&\le&
e \left(\frac{2e}{d-1}+ d-2 \right),
\\
\Sigma_2
&\le & 2e (\Delta + \delta ) - d \Delta \delta .
\end{eqnarray}
See \cite{s2, s2s2}.
Note that, for any $\alpha \le \delta$ and $\alpha' \ge \Delta$,
$$
(2e (\alpha' + \alpha ) - d \alpha \alpha')
-
(2e (\Delta + \delta ) - d \Delta \delta)
=
(2e-d \alpha)(\alpha'-\Delta) + (d\Delta-2e)(\delta-\alpha) \ge 0,
$$
and hence $\Sigma_2 \le 2 e (\Delta + \delta ) - d \Delta \delta  \le 2e (\alpha' + \alpha ) - d \alpha \alpha' $.

\begin{Theorem}
\label{omegadelta}
Let $G$ be a connected graph with $\delta(G)\ge 2$.
Then, for any $2 \le \alpha \le \delta(G)$ and
$\beta  \ge \omega(G)$, we have
$$
c_4(G) \le \frac{(2e- \alpha d)^2}{8}\left(1 - \frac{1}{\beta}\right)+\frac{e(d-\alpha^2+1)}{4}
+\frac{\alpha -2}{4}
\Sigma_2.
$$
In addition,
$$
c_4(G) =  \frac{(2e-  \delta(G) d)^2}{8}\left(1 - \frac{1}{\omega(G)}\right)+\frac{e(d- \delta(G)^2+1)}{4}
+\frac{ \delta(G) -2}{4} \Sigma_2
$$
holds if and only if  $G$ is either $K_d$ or $K_{m,m}$ with $d=2m$.
\end{Theorem}

\begin{proof}
Let $c_t (i,j)$ denote the number of $t$-cycles of $G$ containing $\{i,j\} \in E(G)$.
Then
\begin{eqnarray*}
c_4(i,j) &\le& (\deg_G(i) - 1)(\deg_G(j) - 1)  - c_3(i,j)\\
&\le& (\deg_G(i) - 1)(\deg_G(j) - 1)  - (\deg_G(i)+\deg_G(j)-d)\\
&=& (\deg_G(i) - \alpha )(\deg_G(j) - \alpha )
+ (\alpha -2)(\deg_G(i) +\deg_G(j) )  +d-\alpha^2+1.
\end{eqnarray*}
Since $ \sum_{\{i,j\}\in E(G)} c_4 (i,j)= 4 c_4(G) $
and
$
\sum_{\{i,j\}  \in E(G)}(\deg_G(i) +\deg_G(j) )
=\Sigma_2
$, we have
\begin{eqnarray*}
c_4(G) &\le &
\frac{1}{4}
\sum_{\{i,j\} \in E(G)}
(\deg_G(i) - \alpha )(\deg_G(j) -\alpha )
+ \frac{e(d-\alpha^2+1)}{4} +  \frac{\alpha -2}{4} \Sigma_2 .
\end{eqnarray*}
Since $\alpha d \le \delta(G) d \le 2e$, we have $2 e- \alpha  d \ge 0$.
Equality holds if and only if $\alpha = \delta(G)$
and $G$ is a regular graph.
In this case,
$\sum_{\{i,j\}  \in E(G)}
(\deg_G(i) - \alpha )(\deg_G(j) -\alpha )
=0$.
If $2 e- \alpha  d > 0$, then
let $x_i = \frac{\deg_G(i) - \alpha}{2 e- \alpha  d}\ge 0$
for each vertex $i$.
Since
$\sum_{i=1}^d (\deg_G(i) - \alpha )=
2 e-  \alpha d,$
we have $ \sum_{i=1}^d x_i = 1$.
By Motzkin--Straus Theorem \cite{MSthm},
$$
\sum_{\{i,j\}  \in E(G)} x_i x_j \
\le \
\frac{1}{2}\left(1-\frac{1}{\omega(G)}\right).$$
It follows that
\begin{eqnarray*}
c_4(G) &\le&
\frac{(2e- \alpha d)^2}{8}\left(1 - \frac{1}{\omega(G)}\right)+\frac{e(d-\alpha^2+1)}{4}
+\frac{\alpha-2}{4} \Sigma_2\\
&\le &\frac{(2e- \alpha d)^2}{8}\left(1 - \frac{1}{\beta}\right)+\frac{e(d-\alpha^2+1)}{4}
+\frac{\alpha-2}{4}
\Sigma_2
\end{eqnarray*}
for any $\beta \ge \omega(G)$.
Next we will classify graphs $G$ with
$$
c_4(G) =  \frac{(2e-  \delta(G) d)^2}{8}\left(1 - \frac{1}{\omega(G)}\right)+\frac{e(d- \delta(G)^2+1)}{4}
+\frac{ \delta(G) -2}{4}
\Sigma_2.
$$
The complete graph $K_d$ satisfies
$e = d(d-1)/2$, $\delta(K_d) =d-1$, $\Sigma_2=d(d-1)^2$.
By substituting these values, we have
\begin{eqnarray*}
&&\frac{(2e-  \delta(K_d) d)^2}{8}\left(1 - \frac{1}{\omega(K_d)}\right)+\frac{e(d- \delta(K_d)^2+1)}{4}
+\frac{ \delta(K_d) -2}{4}
\Sigma_2\\
&=&d (d- 1)(d- 2)(d- 3)/8\\
&=&c_4(K_d).
\end{eqnarray*}
On the other hand, if $G=K_{m,m}$, then
$d=2m, e=m^2$, $\delta(G) =m$, $\Sigma_2=2 m^3$.
By substituting these values, we have
\begin{eqnarray*}
&&
\frac{(2e-  \delta(K_{m,m}) d)^2}{8}\left(1 - \frac{1}{\omega(K_{m,m})}\right)+\frac{e(d- \delta(K_{m,m})^2+1)}{4}
+\frac{ \delta(K_{m,m}) -2}{4}
\Sigma_2\\
&=&\frac{m^2(m-1)^2}{4}=c_4(K_{m,m}).
\end{eqnarray*}

Conversely, suppose that $G \neq K_d, K_{m,m}$ satisfies equality.
It then follows that
\begin{eqnarray}
c_4(i,j) &=&(\deg_G(i) - 1)(\deg_G(j) - 1)  - c_3(i,j) \label{cij4}\\
c_3(i,j) &=& \deg_G(i)+\deg_G(j)-d  \label{cij3}
\end{eqnarray}
for any edge $\{i,j\}$ of $G$.
From (\ref{cij3}), we have
$$
(\deg_G(i)-1)+(\deg_G(j)-1) -c_3(i,j)=d-2.
$$
Hence any vertex of $G$ is adjacent to either $i$ or $j$.
Moreover, from (\ref{cij4}),
if $\{i,k\}$ and $\{j,\ell\}$ are edges of $G$ with $k \neq j$, $\ell \neq i$, $k \neq \ell$,
then $\{k,\ell\}$ is an edge of $G$.
Let $K_r$ ($r < d$) be a maximum clique of $G$.

Case 1 ($r\ge3$):
Since $G$ is connected,
there exists an edge $\{i,j\}$ of $G$ such that $i$ is a vertex of $K_r$
and $j$ is not a vertex of $K_r$.
Then the above claim guarantees that
$j$ is adjacent to all vertices of $K_r$.
This contradicts to the hypothesis that $K_r$ is a maximum clique.

Case 2 ($r=2$):
Let $\{i,j\}$ be an edge of $G$.
Since $G$ has no triangles,
any vertex of $G$ is adjacent to exactly one of $i$ and $j$.
Moreover, since $c_4(i,j) = (\deg_G(i) - 1)(\deg_G(j) - 1)$,
$G$ is a complete bipartite graph $K_{\ell ,m}$,
where $\ell = \deg_G(i)$, $m=\deg_G(j)$.
We may assume that $m \le \ell$.
Then
$$
\frac{(2 \ell m-m (\ell+m))^2}{16}
+\frac{ \ell m \left(\ell+m-m^2+1\right)}{4}
+\frac{(m-2) \ell m ( \ell + m )}{4}
-
c_4(K_{\ell,m}) \\
=
\frac{m^2 (\ell -m)^2}{16} .
$$
Thus equality holds if and only if $\ell = m$.
\end{proof}

As an application, we have the following fact that
will play an important role for a proof of the main theorem.

\begin{Corollary}
\label{deltafour}
Let $G$ be a connected graph with $d$ vertices having at least one odd cycle.
If $G$ satisfies one of the following conditions,
then we have
$
c_4(G) \le \binom{e-d+1}{2}.
$
\begin{enumerate}
\item[{\rm (i)}]
$\delta(G) \ge 4$ and $ \Delta(G) \le \frac{3d+1}{4}${\rm ;}

\item[{\rm (ii)}]
$\delta(G) \ge 12${\rm ;}

\item[{\rm (iii)}]
$5 \le \delta(G) \le \Delta(G) \le d-2$ and $10 \le d \le 24$.
\end{enumerate}
\end{Corollary}

\begin{proof}
By Theorem \ref{withoutk4} and Examples \ref{complete} and \ref{large:w(G)},
the inequality holds if either $d \le 5$ or $\omega(G) \ge d-1$.
We may assume that $d \ge 6$ and $\omega(G) \le d-2$.
Let $\delta = \delta(G)$ and $\Delta = \Delta(G)$.

(i)
Since $\delta \ge 4$,
we have
$
\Sigma_2
\le 2e(\Delta+4) -4d \Delta.$
By Theorem \ref{omegadelta}, it follows that
$$
c_4(G) \le \frac{(e- 2 d)^2}{2}\left(1 - \frac{1}{\omega(G)}\right)+\frac{e(d-15)}{4}
+ e(\Delta+4) - 2 d \Delta.
$$
Hence
\begin{eqnarray*}
&&\binom{e-d+1}{2} - c_4(G) \\
& \ge & \binom{e-d+1}{2} -
\left(
\frac{(e- 2 d)^2}{2}\left(1 - \frac{1}{\omega(G)}\right)+\frac{e(d-15)}{4}
+ e(\Delta+4) - 2 d \Delta
\right)\\
&=& \frac{(e-2 d) ( e- (2 d +\frac{\omega(G)}{2}( 4 \Delta- 3d-1) ))}{2 \omega(G)}.
\end{eqnarray*}
Since $\delta \ge 4$, we have $e \ge 2d$.
Thus $\binom{e-d+1}{2} - c_4(G) \ge 0$ if
$ \Delta \le \frac{3d+1}{4}$ holds.

(ii)
Let $\delta(G) \ge 12$.
Then $d \ge 13$ and $e \ge 6d$.
By substituting $\alpha=4$ and $\beta = d-2$ in the inequality
in Theorem \ref{omegadelta},
we have
\begin{eqnarray*}
& &
\binom{e-d+1}{2}-c_4(G)\\
& \ge &
\binom{e-d+1}{2}-
\left(
\frac{( e- 2d)^2}{2}\left(1 - \frac{1}{d-2}\right)+\frac{e(d-15)}{4}
+\frac{1}{2}
e \left(\frac{2 e}{d-1}+d-2\right)
\right)\\
&=&
\frac{1}{2(d-2)}
\left(
-\frac{ d-3 }{ d-1 }e^2
+
\frac{ (d-3)(d+14)}{2}e
-
d (3 d^2-9 d-2)
\right).
\end{eqnarray*}
Let
$$\varphi(x) = -\frac{ d-3 }{ d-1 }x^2
+
\frac{ (d-3)(d+14)}{2}x
-
d (3 d^2-9 d-2).$$
Since $d \ge 13$,
\begin{eqnarray*}
\varphi(6d)&=&
\frac{2 d \left(3 d^2-29 d+62\right)}{d-1} >0\\
\varphi \left( \binom{d}{2} \right)&=&
\frac{d(d-5)^2}{2} > 0.
\end{eqnarray*}
Thus
$\varphi(x) >0$ for all $6d \le x \le \binom{d}{2}$.
Since $6d \le e \le \binom{d}{2}$, it follows that
$
c_4(G) \le \binom{e-d+1}{2}
$.

(iii)
Since $5 \le \delta \le \Delta \le d-2$,
by substituting $\alpha=5$ and $\beta = d-2$ in the inequality
in Theorem \ref{omegadelta},
we have
\begin{eqnarray*}
& &
\binom{e-d+1}{2}-c_4(G)\\
& \ge &
\binom{e-d+1}{2}-
\left(
\frac{( e- \frac{5d}{2})^2}{2}\left(1 - \frac{1}{d-2}\right)+\frac{e(d-24)}{4}
+\frac{3}{4}
 \left(2e (d+3) -5d (d-2) \right)
\right)\\
&=&
\frac{1}{2(d-2)}
\left( e^2
-\frac{1}{2} \left(d^2+16\right)e
+
\frac{1}{4} d \left(9 d^2-57 d+128\right)
\right).
\end{eqnarray*}
The minimum value of this function
is
$$
\frac{1}{32} \left(-d^3+34 d^2-192 d+128\right)
=
\frac{1}{32} \left((24-d) d (d-10) + 16 (3 d+8) \right)
$$
for $e = \frac{1}{4} \left(d^2+16\right)$
and this value is positive since $10 \le d \le 24$.
\end{proof}

\begin{Proposition}
\label{induction}
Let $G$ be a connected graph with $d \ge 6$ vertices and $e$ edges that has at least one odd cycle.
Let $ \delta =\delta(G) \ge 2$ and $\Delta = \Delta(G)$.
Suppose that the inequality {\rm (\ref{Boston})} holds for any connected graph $G'$
having at least one odd cycle
obtained by deleting either a vertex or an edge of $G$.
If $G$ satisfies one of
\begin{enumerate}
\item[{\rm (i)}]
$\Delta = d-1${\rm ;}
\item[{\rm (ii)}]
$\delta \ge 3$ and
$e < \delta(d-\delta) ${\rm ;}
\item[{\rm (iii)}]
$
e \ge  \frac{ ( \delta + 2)  d - (3 \delta +1)}{2} +\frac{1}{2(\delta-1)}
${\rm ;}

\item[{\rm (iv)}]
$\delta \le 3$,
\end{enumerate}
then we have $c_4(G) \le \binom{e-d+1}{2}$.
\end{Proposition}

\begin{proof}
(i)
Let $v$ be a vertex of $G$ of degree $d-1$ and
let $G'$ an induced subgraph of $G$ obtained by removing $v$ from $G$.
Then $G'$ has $d-1$ vertices and $e-d+1$ edges.
By Lemma \ref{2connected}, we may assume that $G'$ is connected.
If $G'$ is a bipartite graph, then $G$ has no $K_4$ since $G'$ has no triangles.
Suppose that $G'$ has at least one odd cycle.
Then $G'$ satisfies the inequality (\ref{Boston})
and hence we have
\begin{eqnarray*}
c_4(G) &=& c_4(G') + \sum_{v' \in V(G')} \binom{\deg_{G'} (v')}{2} \\
&\le &  \binom{e-2d+3}{2}
+ \frac{1}{2}\sum_{v' \in V(G')} \left(\deg_{G'} (v')^2 -\deg_{G'} (v')\right)\\
&\le& \binom{e-2d+3}{2} +
\frac{1}{2} (e-d+1) \left(\frac{2 (e-d+1)}{d-2}+d-3\right)
-(e-d+1)\\
&= & \binom{e-d+1}{2} - \frac{\left(\binom{d}{2}-e\right) (e-2 d+3)}{d-2}.
\end{eqnarray*}
Since $G'$ is a connected graph with $d-1$ vertices,
it follows that $(d- 1) -1 \le e-d+1$.
Hence $2d -3 \le e \le \binom{d}{2} $.
Thus $c_4(G) \le \binom{e-d+1}{2}$.

\bigskip

(ii)
Suppose that $G$ satisfies $c_4(G) > \binom{ e-d+1 }{2}$, $\delta \ge 3$ and
$e < \delta(d-\delta) $.
Let $v$ be a vertex of $G$ such that the degree of a vertex $v$ is $\delta$.
Suppose that $v_1,\ldots, v_\delta$ are incident with $v$ in $G$.
Let $\deg_G(v_i) = \delta + \alpha_i$ and $\alpha = \min\{\alpha_1,\ldots, \alpha_\delta\}$.
Then we have
$$\frac{1}{2}\delta(d+\alpha) \le \frac{1}{2}\sum_{i=1}^d \deg_G(i) =  e.$$
On the other hand,
by the hypothesis, each edge $\{v,v_i\}$ is contained in at least $e-d+1$
4-cycles of $G$.
Then
$$
e-d+1 \le  (\delta - 1)(\delta + \alpha - 1)
$$
and hence
$$
\frac{1}{2} \delta(d+\alpha) \le e \le (\delta - 1)(\delta + \alpha - 1) +d-1.
$$
Then
$
(\delta -2) (d -2\delta)
\le
(\delta - 2)\alpha
$.
Since $\delta \ge 3$, we have
$
d -2 \delta \le \alpha
$.
Thus
$$
\delta(d-\delta) \le
\frac{1}{2}\delta(d+\alpha) \le  e,$$
a contradiction.

\bigskip

(iii)
We may assume that $\Delta \le d-2$ by (i).
Let $v$ be a vertex of $G$ of degree $\delta$
that is adjacent to $v_1,\ldots, v_\delta$
and let $G'$ an induced subgraph of $G$ obtained by deleting $v$.
Note that the number of $C_4$ that contains $v$ is equal to $\sum_{1 \le i < j \le \delta} s_{ij}$,
where
$$s_{ij}= | \{v' \ | \  \{v_i,v'\}, \{v_j,v'\} \in E(G), v' \ne v \}|.$$
It is trivial that $s_{ij} \le d-3$.
On the other hand, if $s_{ij} = s_{ik} = d-3$ ($j \ne k$), then
the degree of $v_i$ is $d-1$.
Hence the number of $i , j $ such that $s_{ij} = d-3$ is at most $\lfloor \delta/2 \rfloor $.
Thus the number of $C_4$ that contains $v$ is at most $(d-4) \binom{\delta}{2} +  \left\lfloor \frac{\delta}{2} \right\rfloor$.
Therefore
$$
c_4(G) \le c_4(G') + (d-4) \binom{\delta}{2} +\left\lfloor \frac{\delta}{2} \right\rfloor.
$$
If $G'$ satisfies the inequality (\ref{Boston}),
then we have
\begin{eqnarray*}
\binom{e-d+1}{2} - c_4(G)
& \ge & \binom{e-d+1}{2} - \binom{(e-\delta)-(d-1)+1}{2}- (d-4) \binom{\delta}{2} - \left\lfloor \frac{\delta}{2} \right\rfloor \\
&=&
(\delta-1)
\left( e - \frac{ ( \delta + 2)  d - (3 \delta +1)}{2}\right) - \frac{1}{2}
+
\frac{\delta}{2}
-
\left\lfloor \frac{\delta}{2} \right\rfloor.
\end{eqnarray*}
This is nonnegative if
$
e \ge
\left\{
\begin{array}{ll}
\frac{ ( \delta + 2)  d - (3 \delta +1)}{2} +\frac{1}{2(\delta-1)}
& \ \ \  \delta \mbox{ is even,}\\
\frac{ ( \delta + 2)  d - (3 \delta +1)}{2} & \ \ \ \delta \mbox{ is odd.}
\end{array}
\right.
$

\bigskip

(iv)
Let $G$ be a 2-connected graph with minimum degree $\delta \in \{2,3\}$
having at least one odd cycle
such that
$$c_4(G) > \binom{ e-d+1 }{2}.$$
Suppose that the inequality {\rm (\ref{Boston})} holds for any connected graph $G'$
having at least one odd cycle
obtained by deleting either a vertex or an edge of $G$.

Suppose that $\delta =2$.
By the same argument in Proof of Theorem \ref{withoutk4},
each edge of $G$ is contained in at least $e-d+1$ 4-cycles of $G$.
Suppose that the degree of a vertex $v_1$ is $2$ and
that $v_1$ is contained in $k$ 4-cycles of $G$.
Then $0 \le k \le d-3$.
By the hypothesis, we have $e-d+1 \le k$ and hence $e \le d+k-1$.
The union of $k$ $C_4$'s is a complete bipartite graph $K_{2,k+1}$ with $2(k+1)$ edges.
If $k=d-3$, then $G$ has at least $2(k+1)+1=2k+3=d+k$ edges since $G$ has at least one odd cycle.
If $k <d-3$, then $G$ has at least $2(k+1) + (d-k-3) +1= d+k$ edges
 since remaining $d-k-3$ vertices are of degree $\ge 2$
and $G$ is 2-connected.
Thus we have $d+k \le e \le  d+k-1$, a contradiction.

Suppose that $\delta = 3$.
By (ii) and (iii), we may assume that
\begin{equation}
\label{last}
3(d-3) \le e < \frac{ ( \delta + 2)  d - (3 \delta +1)}{2}
=
\frac{5}{2} d -5.
\end{equation}
Since $3 d-9< \frac{5}{2} d -5$, we have $d <8$ and hence $d = 6,7$.
If $d=6$, then $e = 9$ by (\ref{last}).
Then $G$ is a connected $3$-regular graph with $6$ vertices.
It is easy to see that $G$ has no $K_4$, a contradiction.
If $d=7$, then $e = 12$ by (\ref{last}).
Let $\{v_1, \ldots, v_7\}$ be the vertex set of $G$
with
$\{v_1,v_2\},\{v_1,v_3\},\{v_1,v_4\} \in E(G)$.
Since $e = \delta(d-\delta)$, by the argument in the proof of (ii),
the degree of $v_i$ ($i=2,3,4$) is $\delta+\alpha= \delta + d - 2\delta = 4$.
Then
$$24= 2e =\sum_{i=1}^7 \deg_G (v_i)=  15+ \deg_G (v_5) + \deg_G (v_6) + \deg_G (v_7)
.$$
Since $\deg_G (v_i) \ge 3$, we have $\deg_G (v_i)=3$ for $i = 5,6,7$.
Note that the degree of a vertex incident
with one of the vertices $v_1, v_5, v_6, v_7$ of degree 3
sholud be 4.
Thus $G$ is the complete bipartite graph
$K_{3,4}$ on the vertex set $\{v_2,v_3,v_4\} \cup\{v_1, v_5, v_6, v_7\} $,
a contradition.

\end{proof}

We are now in the position to prove the main theorem (Theorem \ref{maintheorem}) of the present paper.

\begin{Theorem}
\label{main}
Let $G$ be a finite connected simple graph with $d$ vertices and $e$ edges, and $c_4(G)$ the number of $4$-cycles of $G$.  Suppose that $G$ has at least one odd cycle.  Then
$$
c_4(G) \le \binom{e-d+1}{2}.
$$
\end{Theorem}

\begin{proof}
Let $G$ be a 2-connected graph with $d \ge 6$ vertices having at least one odd cycle
with
$$
c_4(G) >\binom{e-d+1}{2}.
$$
Suppose that the assertion holds for any connected graph $G'$
having at least one odd cycle
obtained by deleting either a vertex or an edge of $G$.
For $d= 6,7,8, 9$, $\left\lfloor (3d+1)/4 \right\rfloor=d-2$.
By Corollary~\ref{deltafour} (i) and Proposition~\ref{induction} (i) and (iv),
it follows that $d\ge 10$.
In addition, by Corollary~\ref{deltafour} (ii) and Proposition~\ref{induction},
we may assume that $G$ is a 2-connected graph with
$\omega(G) \le d-2$ and $4 \le \delta \le 11$, $\Delta \le d-2$, and
$$
\delta(d-\delta) \le e <\frac{ ( \delta + 2)  d - (3 \delta +1)}{2} +\frac{1}{2(\delta-1)}
.$$
In particular,
$$
\delta(d-\delta) <
\frac{ ( \delta + 2)  d - (3 \delta +1)}{2} +\frac{1}{2(\delta-1)}
$$
holds.
Since $\delta \ge 4$, we have
$$
d <
\frac{2 \delta^3-5 \delta^2+2 \delta+2}{(\delta-2) (\delta-1)}.
$$
If $\delta = 4$, then
$$
d <
\frac{2 \delta^3-5 \delta^2+2 \delta+2}{(\delta-2) (\delta-1)}
= \frac{29}{3} < 10,
$$
a contradiction.
Thus $\delta \ge 5$.
By Corollary \ref{deltafour} (iii), we have $d \ge 25$.
However, since $\delta \in \{5, \ldots ,11\}$,
$$
d <
\frac{2 \delta^3-5 \delta^2+2 \delta+2}{(\delta-2) (\delta-1)}
\le \frac{2081}{90} <24.
$$
This is a contradiction.
\end{proof}

It would, of course, be of interest to classify all finite connected simple graphs $G$ which satisfy the equality $c_4(G) = \binom{e - d + 1}{2}$.