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
I didn't see anyone using generating functions yet, so I'll use them for no other reason than they're fun.
You are trying to solve the recurrence with $f_0=0$ and $f_k=3f_{k-1}+12(-1)^{k+1}$ for all $k\in\mathbb{Z}^{+}$.
Let $F(x)=\sum_{k\geq0}f_kx^k$ be the generating function of the sequence defined by the given recurrence.
$\begin{align} F(x) &= \sum_{k\geq0}f_kx^k\\ &= f_0x^0+\sum_{k\geq1}f_kx^k\\ &= \sum_{k\geq1}(3f_{k-1}+12(-1)^{k+1})x^k\\ &= \sum_{k\geq1}3f_{k-1}x^k+\sum_{k\geq1}12(-1)^{k+1}x^k\\ &= 3x\sum_{k\geq0}3f_kx^k+12x\sum_{k\geq0}(-1)^kx^k\\ &= 3xF(x)+\frac{12x}{1+x}\\ \end{align}$
Now we may solve for $F(x)$ and obtain $F(x)=\frac{12x}{(1+x)(1-3x)}=\frac{3}{1-3x}-\frac{3}{1+x}$.
To find the closed form for the recurrence, we may expand $F(x)$ about the point $x_0=0$.
$\begin{align} F(x) &= \frac{3}{1-3x}-\frac{3}{1+x}\\ &= 3\sum_{k\geq0}3^kx^k-3\sum_{k\geq0}(-1)^kx^k\\ &= \sum_{k\geq0}(3^{k+1}-3(-1)^k)x^k\\ \end{align}$
So the closed form for the recurrence is $f_k=3^{k+1}-3(-1)^k$, for all non-negative $k$.
The original recurrence used an initial index of one rather than zero. Then the closed form becomes $f_k=3^k-3(-1)^{k-1}$, for all positive $k$.
EDIT: OP mentioned that he is not familiar with generating functions, so here is a link the generatingfunctionology.