For a graph $(G, V)$, $\# \text{edges}$ is given by the rank of $H_1(G, V)$. In my algebraic topology course, we are studying homology groups of graphs. We showed that for $(G, V)$ a graph (where $G$ is a Hausdroff space, the edges, and $V \subset G$ is finite subset, the vertices), we have
$$\text{rk } H_0(G) - \text{rk }H_1(G) = \# \text{vertices } - \# \text{edges }$$
where $\text{rk}$ is the rank of the group. By assuming $G$ path connected, and by considering the long exact sequence of $(G, V)$, we get
$$0 = H_1(V) \to H_1(G) \to H_1(G, V) \to H_0(V) \cong \mathbb Z^J \to H_0(G) \cong \mathbb Z \to 0,$$
where $J = \# V$. This gives us
$$0 = H_1(V) \to H_1(G) \to H_1(G, V) \to \tilde{H}_0(V) \cong \mathbb Z^{J-1}\to 0,$$
so that $H_1(G, V) \cong H_1(G) \oplus \tilde{H}_0(V)$. From there, my teacher told us that the statement was straightforward as
$$\#\text{edges } = \text{rk } H_1(G, V) = \text{rk }H_1(G) + \text{rk }\tilde{H}_0(G) = \text{rk }H_1(G) + \# \text{vertices } - 1.$$
However, I have absolutely no idea from where comes the first equality. Could one of you give me an intuition on why the number of edges should be equal to the rank of $H_1(G, V)$.
 A: Here is how I would view this, it doesn't use the long exact sequence, but I hope it gives you some intuition.
Since we are assuming that our graph is path-connected we know that there is a  single connected component, so $H_0(G)=\mathbb{Z}$, and we have that $\text{rank}(H_0(G))=1$
Now the part which you are interested in is $H_1(G)$. Now let us assume that our graph has $V$ vertices and $E$ edges. Then one way that we can view $H_1(G)$ is as the abelianization of the fundamental group of $G$ that is $H_1(G)=\pi_1(G)^{\text{ab}}$. Now if we let $T$ be a maximal spanning tree of $G$, then $T$ is a contractible subspace, and $G/T$ will end up being a wedge of circles (which is nice because we know that $\pi_1(\vee_{i=1}^n S^1)^{\text{ab}}=\mathbb{Z}^n$). Thus, we will have that $\text{rank}(H_1(G))=n$ where $n$ is the number of circles after we contract a maximal spanning tree.
Now you can just use the graph theory fact that for a connected graph with $V$ vertices will have a maximal spanning tree consisting of $V-1$ edges. Thus, we will have that when we contract the maximal spanning tree we will have a wedge of $E-(V-1)$ circles. Thus, we will have that $\text{rank}(H_1(G))=E-(V-1)=E-V+1$, and from this we get that
$$\text{rank}(H_0(G))-\text{rank}(H_1(G))=1-(E-V+1)=V-E$$
which is what we wanted to show.
A: The pair $(G,V)$ is what is called a nice pair of spaces, meaning that there is a neighborhood of $V$ in $G$, which deformation retracts onto $V$ (for example, you can take this neighborhood to be $G$ with all the midpoints of the edges removed). It is then a theorem in algebraic topology, that if $(X,A)$ is a nice pair of spaces, the canonical projection induces isomorphisms $H_i(X,A)\rightarrow H_i(X/A,A/A)$ for all $i\ge0$. Specializing to our case, $G/V$ as a topological space is homeomorphic to a wedge of circles, one circle for each edge of $G$, and $V/V$ corresponds to the wedge point. I recommend understanding this visually. How to construct a formal argument depends on how you have formalized the condition that $G$ is a graph. If, say, a graph is a one-dimensional CW-complex, this can be argued using the canonical quotient map. Now, $H_1(\bigvee_{\text{edges}}S^1,\ast)$, where $\ast$ is the wedge point, is free abelian on the 1-simplices representing each circle. Together, this tells us that $H_1(G,V)$ is free abelian on the 1-simplices representing each edge of $G$. In particular, this group has rank equaling the number of edges of $G$.
Alternatively, you could try proving this inductively using the Mayer-Vietoris sequence for pairs of spaces. The case in which there are no edges is trivial, as $H_1(V,V)=0$. If the theorem has been proven for graphs with $n$ edges, assume $(G,V)$ is a graph with $n+1$ edges. Choose an edge $\overline{e}\subseteq G$ (this is the closed edge, i.e. it should contain the endpoints) and think of $G$ as a CW-complex. Decompose the pair $(G,V)$ into the pairs $(\overline{e},V\cap\overline{e})$ and $(G\setminus e,V\setminus(V\cap e))$. This is a decomposition into subcomplexes, so we get a Mayer-Vietoris sequence. Since $\overline{e}\cap G\setminus e=V\cap\overline{e}\cap V\setminus(V\cap e)$, the homology of the pair of intersections vanishes, so we obtain an isomorphism $H_1(\overline{e},V\cap\overline{e})\oplus H_1(G\setminus e,V\setminus(V\cap e))\rightarrow H_1(G,V)$. The former group is free on the 1-simplex representing the edge $\overline{e}$ (use the LES of the pair), the latter group is free on the edges of $G\setminus e$, which are all edges of $G$ except $e$, by hypothesis. Since the isomorphism is induced by inclusions, this proves that $H_1(G,V)$ is free on the edges of $G$. This induction proves the claim for all finite graphs $(G,V)$. The first argument did not require $G$ to be finite, so this seems less general, but what we have already proven for finite graphs suffices to get the claim for infinite $G$ as well using a limiting argument, but I'll leave it at this.
