Dept. of Computer Engineering
Middle East Technical Univ.
Ankara - TURKEY
Anaysis of Algorihms, Fall 2012
CEng 315
1
Recurrences (cont.)
• Inhomogeneous Recurrences: We now consider recurrences of a slightly more general form: a0tn + a1tn-1 + … + aktn-k = bnp(n)
(2)
• The left hand side is the same as (1), but on the right hand side we have bnp(n), where b is a constant and p(n) is a polynomial in n of degree d.
Anaysis of Algorihms, Fall 2012
CEng 315
2
Recurrences (cont.)
Example: Solve the following recurrence: tn - 2tn-1 = 3n.
In this case b =3 and p(n) = 1, a polynomial of degree d=0.
A little manipulation allows us to reduce this example to the form (1).
To see this, we first multiply the recurrence by 3, obtaining
3tn - 6tn-1 = 3n+1.
If we replace n by n+1 in the original recurrence, we get tn+1 - 2tn = 3n+1.
Finally, subtracting these two equations, we have tn+1 - 5tn + 6tn-1 = 0, which can be solved by the above method.
The characteristic equation is x2 - 5x + 6 = 0. That is, (x-2)(x-3) = 0.
• Intuitively we can see that the factor (x-2) corresponds to the left-hand side of the original recurrence, whereas the factor (x-3) has appeared as a result of our manipulation to get rid of the right-hand side.
Anaysis of Algorihms, Fall 2012
CEng 315
3
Recurrences (cont.)
• Generalizing this approach, to solve (2): a0tn + a1tn-1 + … + aktn-k = bnp(n) (2) we can show that it is sufficient to take the following characteristic equation:
(a0xk+ a1xk-1 +…+ ak )(x-b)d+1 = 0,
where d is the degree of polynomial p(n)
• Once this equation is obtained, proceed as in the homogeneous case.
Anaysis of Algorihms, Fall 2012
CEng 315
4
Recurrences (cont.)
Example: The number of movements of a ring required in the Towers of
Hanoi problem is given by the following recurrence relation: tn = 2tn-1 + 1, n 1, subject to t0 = 0.
The recurrence can be written tn - 2tn-1