Let $X$ be a discrete random variable with possible outcomes: $x_1, x_2, x_3,\dots, x_i,\dots$ with associated probabilities $p_1,p_2,p_3,\dots,p_i,\dots$
The expected value of $f(X)$ is given as:
$E[f(X)] = \sum\limits_{i\in\Delta} f(x_i)p_i$
In your specific example, $X$ could be one of the values: $1,2,3,\dots ,i,\dots$ with corresponding probabilities $\frac{1}{2},\frac{1}{4},\frac{1}{8},\dots,\frac{1}{2^i},\dots$ (seen easily from the beginnings of a tree diagram)
So, the expected value of $X$ is:
$\sum\limits_{i=1}^\infty i(\frac{1}{2})^i$
This is a well-known infinite sum of the form $\sum\limits_{i=1}^\infty i p (1-p)^{i-1}$, in this case with $p=1-p=\frac{1}{2}$. You will likely be expected to simply memorize the result, and it is included in most formula lists. $\sum\limits_{i=1}^\infty i p (1-p)^{i-1}=\frac{1}{p}~~~~~~~(\dagger)$
Using this result without proof, we get our expected number of flips is $\frac{1}{0.5}=2$
The proof of $(\dagger)$:
$$\sum\limits_{i=1}^\infty i p (1-p)^{i-1} = p\sum\limits_{i=1}^\infty i (1-p)^{i-1}\\
= p\left(\sum\limits_{i=1}^\infty (1-p)^{i-1} + \sum\limits_{i=2}^\infty (1-p)^{i-1} + \sum\limits_{i=3}^\infty (1-p)^{i-1} + \dots\right)\\
= p\left[(1/p)+(1-p)/p+(1-p)^2/p+\dots\right]\\
= 1 + (1-p)+(1-p)^2+\dots\\
=\frac{1}{p}$$