Consider a game played on the tree above, where the "cost" at a leaf is paid by P1 to P2. Thus P1 wants the number to be as small as possible where P2 wants it to be large. What is the cost paid by P1 to P2 if both players play optimally?
When a question asks "optimally", does it mean that the players play trying to get the maximum amount after each move, and that the opposite player is also playing optimally? What I mean is:
in this graph, player 1 has to move left, since 0 is his goal. Now, player 2 can move left next which gives him a chance to get to 4, however, it could also get him to 0. if he moves right, he guarantees at least a 1.
So does it mean that to play optimally, player 2 would go right in his first move, even tough he has "a chance" of getting four if he goes the other way?

The meaning of an optimal strategy (here: Nash equilibrium) is that if one of the players diverges from the strategy he will get worse results. Since both player try to do their best, it makes no sense to hope that the opponent makes an error. Thus players try to optimize the worst case.
The graph has to be solved bottom up: in the last row, it is pretty clear that player 2 chooses always the better alternative.
In the third row, player 1 tries to maximize his worst case results, thus choosing (from left to right) R-L-R-R.
The action in the second row is now more difficult to compute. From above, we know all decisions further down, thus the we can predict the outcome of each move: first pair: L$\to0$, R$\to1$, second pair: L$\to2$, R$\to3$. So player 2 would choose always choose R in his first move.
For the first move: L would give $1$, R would give $3$, so player 1 chooses first L.
The actual game is then L-R-L-L, with result 1.