I'm trying to work a few examples from the Repertoire Method from the Book Concrete Mathematics.
I'm working through the following recurrence:
$f(0) = 1$
$f(n) = 2f(n-1) + n$
Which I generalized as:
$f(0) = \alpha$
$f(n) = 2f(n-1) + \beta n$
My goal is to find the closed solution for f(n) for the generalized recurrence.
The first few solutions are:
$0 => \alpha$
$1 => 2 \alpha + \beta$
$2 => 4 \alpha + 4 \beta$
$3 => 8 \alpha + 8 \beta$
$4 => 16 \alpha + 25 \beta$
So it seems like I can rewrite my recurrence as:
$f(n) = A(n) \alpha + B(n) \beta$
$A(n)$ is certainly $2^n$, so $f(n) = \alpha 2^n + \beta B(n)$. The next step is I try to set f(n) to some simple function, and try to find the value of $B(n)$. For example, when $f(n) = 1$:
$1 = \alpha$
and
$1 = 2 + \beta n$
Then $\alpha = 1$ and $\beta = -1/n$
So $2^n - 1/n * B(n) = 1$ means $B(n) = -n + n2^n$. But this function is clearly wrong, in fact $B(2) = 6$ instead of 4, which is what I expected.
I guess my question is, how do I know that setting $f(n) = 1$ does not help me solve the equation? Is it because $\beta$ depends on $n$ for its value?
EDIT:
I think now I understand that $\beta$ has to be a constant.
As you have noticed, you can easily prove by induction that $f(n)=A(n)\alpha+B(n)\beta$. We can use the recurrence relation on $f$ to find relations for $A$ and $B$: $$A(n)\alpha+B(n)\beta = f(n) = 2f(n-1)+\beta n = 2A(n-1)\alpha+(2B(n-1)+n)\beta$$ and thus: $$A(n)=2A(n-1)$$ $$B(n)=2B(n-1)+n$$ With initial conditions given by $f(0)=\alpha\Rightarrow A(0)=1,\ B(0)=0$ we get that $A(n)=2^n$ and that $B(n)$ solves the generalized recurrence with $\alpha=0$ and $\beta=1$. You can check that the solution to this recurrence is given by $$B(n)=2^nB(0)+\sum_{k=0}^n2^{n-k}k = \sum_{k=0}^n2^{n-k}k$$ Its generating function should be: $$\sum_{n=0}^\infty B(n)x^n=\frac{-x}{(1-2x)(1-x)^2}$$