TITLE: How to solve this recurrence relation? $f_n = 3f_{n-1} + 12(-1)^n$
QUESTION [17 upvotes]: How to solve this particular recurrence relation  ?
$$f_n = 3f_{n-1} + 12(-1)^n,\quad f_1 = 0$$
such that $f_2 = 12, f_3 = 24$ and so on.
I tried out a lot but due to $(-1)^n$ I am not able to solve this recurrence?
Any help will be highly appreciated.
Please this is no homework. I came across this while solving a problem on SPOJ

REPLY [2 votes]: Let 
$$g_n=(-1)^nf_n$$ 
then the $g_n$ satisfy 
$$g_n=-3g_{n-1}+12$$
Now let 
$$h_n=g_n-3$$
so
$$\begin{align}
h_n &= g_n-3 \\
    &=(-3g_{n-1}+12)-3\\
    &=-3(h_{n-1}+3)+9 \\
    &=-3h_{n-1}
\end{align}$$
So 
$$h_n=(-3)^{n-1}h_1$$
since $g_2=12$ so $h_2=9, h_1=-3$ and thus 
$$f_n=(-1)^n(h_n+3)=3^{n}+3(-1)^n$$.