













































































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!














































































Recurrence relations (Section 5.1) Counting strings Partition function Solving recurrence solutions (Section 5.2) Fast numerical algorithm “dynamic programming” Closed solutions by telescoping (back-substitution) Linear recurrences with constant coefficients Homogeneous case (RHS = 0) General case Inclusion-Exclusion (Sections 5.5, 5.6) Standard (2 sets) “Inclusion-Exclusion-Inclusion” (3 sets) Generalized (n sets) Counting onto functions Derangements Sieve of Erastothenes (blackboard)
EG: Recall the Fibonacci sequence:
INITIALIZE: f 0 = 0, f 1 = 1 RECURSE: fn = fn-1+fn-2 for n > 1.
The recurrence relation is the recursive part
sequence consists of an equation that expresses each term in terms of lower terms.
Q: Is there another solution to the Fibonacci recurrence relation?
of initial conditions such as f 0 =1, f 1 = -
{fn } = 1,-1,0,-1,-2,-3,-5,-8,-13,-21,…
number of points of intersection of n lines.
number of bit strings of length n which
I. If the first n-1 letters contain 00 then so does
II. Else, string must be of the form u00 with u a
ending in 0 (why not?). But the number of
the total number of strings minus the number
Q: What are the initial conditions:
amount in the account after n months,
where r = 1 + 6%/12 = 1.
Let’s find a recursion relation for the partition
By the sum rule, we need to count the number of partitions of each kind, and then add together.
0 1
1
0
n
n
i
n i
Recursion + Lookup Table = Dynamic Programming
Consider a recurrence relation of the form:
Then can always solve the recurrence relation for
integer-array a(integers n, a 0 )
table 0 = a 0 for(i = 1 to n) tablei = f(table 0 ,table 1 ,…,tablei-1) return table
Pseudocode becomes:
integer-array a(integer n)
table 0 = table 1 = 0 table 2 = 1 for(i = 3 to n) tablei = 2i-3-tablei-3+2tablei- return table*
L20 19
Solve an = 2an-1 + 2^ n-3^ - an-3 up to n=7:
L20 20
Solve an = 2an-1 + 2^ n-3^ - an-3 up to n=7: