415 lecture note #8
(1) Iteration Method (cont.)
where a is some number (constant or some expression which depends on n), and c is a constant.
Let T(n) be the number of moves required for n disks. It can be defined in two ways, by recurrence relation and by closed formula, as:
T(n) = 2*T(n-1)+ 1, for all n >= 2, and
T(1) = 1.
T(n) = 2n - 1, for all n >= 1.
So we need to prove that the two formulas are the same, for all n >= 1.
--------------------------------------------------------------------------------
Theorem: Show if T(1), T(2),.., T(n) is the sequence defined by
T(n) = 2*T(n-1) + 1, for all n >= 2, and T(1) = 1
then, T(n) = 2n - 1, for all n >= 1.
Proof: by strong mathematical induction (with one base case).
Basic Step (n = 1):
Therefore, the closed formula holds for n = 1. ........... (A)
Inductive Step:
Assume the closed formula holds for n-1, that is, T(n-1) = 2n-1
- 1, for all n >= 2.
Show the formula also holds for n, that is, T(n) = 2n - 1.
T(n) = 2*T(n-1) + 1 ... by recursive
definition
= 2*(2n-1 - 1) +
1 ... by inductive hypothesis
= 2*(2n-1) - 2 + 1
= 2*(2n-1) - 1
= 2n - 1
Therefore, the closed formula holds for n >= 2. ........... (B)
By (A) and (B), the closed formula holds for all n >= 1. QED.
---------------------------------------------------------------------
T(n) = -3*T(n-1) for all n >= 1, and T(0) = 2
then, T(n) = 2*(-3)n
Proof:
(will do in the class)
Example: T(n) = 2n - 1
(2) Characteristic Equation
Example: How can we derive a closed form for fn = fn-1 + fn-2 ?
Second order, Linear Homogeneous recurrence with Constant Coefficients
an = c1*an-1 + c2*an-2 for all integers n >= some fixed integer,
where c1, c2 are fixed real numbers with c2 != 0.
State whether each of the following is a second order linear homogeneous recurrence with constant coefficients.
an = 3an-1 - 2an-2 an = 3an-1 - 2an-2 + 5an-3 an = (1/3)*an-1 - (1/2)*an-2 an = 3(an-1)2 + 2an-2 an = 2an-2 an = 3an-1 + 2 an = (-1)n*3an-1 + 2an-2
t2 - At - B = 0
Theorem: Consider a recurrence relation an
= A*an-1 + B*an-2. Let x and y be the roots
of the characteristic equation for this relation. Then there
are any numbers C, D such that
Proof: See Section 5.2. |
an = an-1 + 2an-2, for all integers n >= 2
with initial conditions a0 = 1 and a1 = 8.
Solution:
The characteristic equation for this relation is t2 - t - 2 = 0. Computing the roots of this equation,
t2 - t - 2 = 0, so (t - 2)(t + 1) = 0
we get t1 = 2 and t2 = -1. Then from the theorem above, we know the closed form is written as:
an = C*(2)n + D*(-1)n ........... (*)
Now, we must solve for C and D (at this point, they are unknown). To do so, we use the initial conditions -- by plugging in n = 0 (for a0) and n = 1 (for a1) in (*), and solve the two equations.
a0 = C*(2)0 + D*(-1)0 = C + D = 1 ..... (1)
a1 = C*(2)1 + D*(-1)1 = 2C - D = 8 ..... (2)
To solve those equations, there are several ways. Here is one way
using substitution.
We know C = 1 - D by (1). Substituting this in (2),
we get
2(1 - D) - D = 8
2 - 2D - D = 8
3D = -6
D = -2, so C = 1 + 2 = 3
Then we have completely solved the closed form, which is now
an = 3*(2)n + (-2)*(-1)n ........... (**)
As the last note, the complexity of this formula is Q(____).
an = 4an-1 - 4an-2, for all integers n >= 2
with initial conditions a0 = 1 and a1 = 3.
Solution:
The characteristic equation for this relation is t2 - 4t + 4 = 0. Computing the roots of this equation,
t2 - 4t + 4 = 0, so (t - 2)2 = 0
we get t = 2. Then from the theorem above, we know the closed form is written as:
an = C*(2)n + D*n*(2)n ........... (*)
Now, we must solve for C and D (at this point, they are unknown). To do so, we use the initial conditions -- by plugging in n = 0 (for a0) and n = 1 (for a1) in (*), and solve the two equations.
a0 = C*(2)0 + D*n*(2)0 = C = 1 ..... (1)
a1 = C*(2)1 + D*n*(2)1 = 2C + 2D = 3 ..... (2)
We know C = 1 by (1). Substituting this in (2), we get
2(1) + 2 D = 3
2D = 1
D = 1/2
Then we have completely solved the closed form, which is now
an = 1*(2)n + (1/2)*n*(2)n
= (1 + (1/2)*n) * (2)n .................. (**)
And the complexity of this formula is Q(____).
![]() |