There are four basketball players $A, B, C, D$. Initially, the ball is with $A$. The ball is always passed from one person to a different person. In how many ways can the ball come back to $A$ after seven passes? (For example $A \mapsto C \mapsto B \mapsto D \mapsto A \mapsto B \mapsto C \mapsto A$ and $A \mapsto D \mapsto A \mapsto C \mapsto A \mapsto B \mapsto C \mapsto A$)
I know that it can be done considering cases (location and the number of passes received by $A$ in between). But I'm interested in learning some recursion. So, it would be good if some explicitly explains how to get the recursion. Not just the recursion, but how to "derive" it.
Note that there are only two states: either A has the ball or somebody else has it. Define $f(n)$ as the number of ways to pass the ball $n$ times so that $A$ has it at the end and $g(n)$ as the number of ways to pass the ball $n$ times so that somebody else has it at the end. We start with $f(0)=1, g(0)=0$ because after $0$ passes $A$ has the ball. If somebody else has the ball there is $1$ way to pass it to $A$, so $f(n+1)=g(n)$. If $A$ has the ball there are three ways to pass it to somebody else, while if somebody else has it there are two, so $g(n+1)=3f(n)+2g(n)$