If a graph with $n$ vertices and $n$ edges there must a cycle?

Solution 1:

Assume that $G$ contains no cycles. Then every connected component of $G$ is a tree.

Claim The number of edges in a tree on $n$ vertices is $n-1$.

Proof is by induction. The claim is obvious for $n=1$. Assume that it holds for trees on $n$ vertices. Take a tree on $n+1$ vertices. It's an easy exercise (look at a longest path in $G$) to show that a tree has at least one terminal vertex (i.e. with degree $1$). Removing this terminal vertex along with its edge, we get a tree on $n$ vertices, and induction takes us home.

Hence the number of edges in a graph without cycles is $n-k$, where $k$ is the number of connected components.

Solution 2:

Here's is an approach which does not use induction:

Let $G$ be a graph with $n$ vertices and $n$ edges. Keep removing vertices of degree $1$ from $G$ until no such removal is possible, and let $G'$ denote the resulting graph. Note that in each removal, we're removing exactly $1$ vertex and $1$ edge, so $G'$ cannot be empty, otherwise before the last removal we'd have a graph with $1$ vertex and $1$ edge, and $G'$ has the same number of vertices and edges. Therefore the minimum degree in $G'$ is at least $2$, which implies that $G'$ has a cycle.