












Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!













12/4/
Lecture 29
Recurrence Relations II
12/4/
-^
Back-Substitution
-^
Dynamic Programming
12/4/ Review: Number of Line Intersections^ • Remember maximum number of intersections?
-^
We derived a recurrence relation: a
n^
= a
n-
a
4
= a
3
But a
3
= a
2
a
4
= (a
2
a
4
= (a
1
But a
1
= 0
a
4
n^
= sum(1 .. n–1) =
12/4/
Sequence of steps, where the state of the next stepis computed from the previous steps
-^
Compare to
linear programming where we compute
the values of variables to minimize a function
int[]
SolveRecurrence(Rec_Fun
rec_fun,
int
num_to_solve,
int[n
] 0
initial_values)
terms[1..n
] = initial_values 0
for
(i
=
n
+1 0
to
n)
terms[i]
=
rec_fun(terms[1..i-1])
return
terms
12/4/
hand!
recurrence analytically?
Linear homogeneous (easy)
-^
Quadratic (hard)
12/4/
-^
Points C for which z
n^
= zn-
2
infinity (z
,C complex numbers, zn
0
= 0)
12/4/
Fibonacci recurrence: fib
n^
= fib
n-
n-
Assume solution of the form a
n^
= r
n
-^
nr = r
n-
n-
(substituting a
n^
= r
n^ )
-^
(^2) r n-2r
= r
1 r
n-
n-
(factoring)
-^
(^2) r = r + 1
(dividing by r
n-
)
This is the
recurrence relation
-^
QC: How do we solve for r?
12/4/
Find all r’s that seem to work•^
(^2) r = r + 1
We’ll call these solutions r
1
and r
2
5
1
r
2
5
1 1
= r^
2
5
1 2
r
12/4/
13
Use initial conditions to find
α
(and therefore
the specific solution)•^
a^0
= 0, a
1
= 1
So
0
2
0
1
2
5
1
2
5
1
0
^
−
^
=
α
α
1 5
1
= α n
n
a^ n
^
−
−
^
=
2
5
1 1 5
2
5
1 1 5
2
α
1
2
1
1
2
5
1
2
5
1
1
^
−
^
=
α
α
12/4/ Linear Homogenous RecurrenceRelations with Constant Coefficients^ • We can generalize the previous example•
) with coefficientsn^
an
= 3 a
n-
n-
(OK)
-^
H
n^
= 2 H
n-
(not OK—not homogeneous)
-^
an
= 3 a
n-
2
n-
(not OK—not linear)
-^
an
= n a
n-
n-
(not OK—non-const. coeff.)
12/4/
If not, why not?
n^
= 3a
n-
n-
n-
n^
= 2na
n-
n-
n^
= a
n-
n^
= a
n-
2
n^
= 4a
n-
a
n-
n-
12/4/
Can use the method from before
-^
Theorem: The sequence is a solution ofn
the recurrence relation a
=cn^
a 1
n-
+c
a 2
n-
iff
a
=n
α
r 1
n 1
α
r 2
n 2
. Here r
1
and r
2
are the two
distinct roots of r
2 –c
r–c 1
=0, n=0,1,2,…, and 2
α
1,
α
2
are constants.
Complications:•^
Repeated roots (can handle this with some tricks)
-^
Complex roots (just use complex numbers)
12/4/
n^
= 5a
n-
n-
, a
0
= 1, a
1
12/4/
back-substitution. (Works best when next valuein terms of a single previous value.)
Identify linear homogeneous recurrence relations
-^
Remember they can be solved systematically
-^
Remember how to do it, or where to look it up