Recurrence Problems - CS 8109
Recurrence Problems - CS 8109
Recurrence Relations
1
Recurrence relations
• Many counting problems can be solved with
recurrence relations
• Example: The number of bacteria doubles
every 2 hours. If a colony begins with 5
bacteria, how many will be present in n
hours?
• Let an=2an-1 where n is a positive integer with
a0=5
2
Recurrence relations
3
Recursion and recurrence
• A recursive algorithm provides the solution of a
problem of size n in terms of the solutions of one or
more instances of the same problem of smaller size
• When we analyze the complexity of a recursive
algorithm, we obtain a recurrence relation that
expresses the number of operations required to
solve a problem of size n in terms of the number of
operations required to solve the problem for one or
more instance of smaller size
4
Example
• Let {an} be a sequence that satisfies the
recurrence relation an=an-1 – an-2 for n=2, 3, 4,
… and suppose that a0=3 and a1=5, what are a2
and a3?
• Using the recurrence relation, a2=a1-a0=5-3=2
and a3=a2-a1=2-5=-3
5
Example
• Determine whether the sequence {an}, where
an=3n for every nonnegative integer n, is a solution
of the recurrence relation an=2an-1 – an-2 for n=2, 3,
4, …
3(n-2)=3n=an.
• Thus, {an} where an=3n is a solution for
the recurrence relation
6
Modeling with recurrence relations
• Compound interest: Suppose that a person deposits
$10,000 in a savings account at a bank yielding 11%
per year with interest compounded annually. How
much will it be in the account after 30 years?
• Let Pn denote the amount in the account after n
years. The amount after n years equals the amount
after n-1 years plus interest for the n-th year, we
see the sequence {Pn} has the recurrence relation
Pn=Pn-1+0.11Pn-1=(1.11)Pn-1
7
Modeling with recurrence relations
• The initial condition P0=10,000, thus
• P1=(1.11)P0
• P2=(1.11)P1=(1.11)2P0
• P3=(1.11)P2=(1.11)3P0
• …
• Pn=(1.11)Pn-1=(1.11)nP0
• We can use mathematical induction to establish
its validity
8
Modeling with recurrence relations
• We can use mathematical induction to
establish its validity
• Assume Pn=(1.11)n10,000. Then from the
recurrence relation and the induction
hypothesis
• Pn+1=(1.11)Pn=(1.11)
(1.11)n10,000=(1.11)n+110,000
• n=30, P30=(1.11)3010,000=228,922.97
9
Solving linear recurrence relations
10
From mathematical induction
11
Linear homogenous recurrence
relations with constant coefficients
characteristic equation
12
Theorem 1
13
Example
14
Fibonacci numbers
15
16
17
Recurrence relations
• Play an important role in many aspects of
algorithms and complexity
• Can be used to
– analyze the complexity of divide-and-conquer
algorithms (e.g., merge sort)
– Solve dynamic programming problems (e.g.,
scheduling tasks, shortest-path, hidden Markov
model)
– Fractal
18