Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to solve the following recurrence?

I am not familiar with recurrence-solving techniques outside of the master theorem, recursion trees, and the substitution method. I am guessing that solving the following recurrence for a big-O bound does not utilize one of those methods:

T(n) = T(n-1) + 2T(n-2) + 1
like image 344
velen Avatar asked Feb 18 '16 03:02

velen


1 Answers

We can make the substitution U(n) = T(n) + 1/2 and then get a recurrence

U(n) = T(n) + 1/2
     = T(n-1) + 2T(n-2) + 1 + 1/2
     = T(n-1) + 1/2 + 2(T(n-2) + 1/2)
     = U(n-1) + 2U(n-2),

which is a little magic but, as templatetypedef mentions, the magic can be created with the annihilator method. Now we just have to solve the linear homogeneous recurrence. The characteristic polynomial x^2 - x - 2 factors as (x+1)(x-2), so the solutions are U(n) = a(-1)^n + b2^n where a and b are any constants. Equivalently, T(n) = a(-1)^n + b2^n - 1/2, which is Theta(2^n) except in special cases.

like image 60
David Eisenstat Avatar answered Nov 15 '22 05:11

David Eisenstat