0% found this document useful (0 votes)
61 views

Lec 08 z Recurrence

Uploaded by

bdgamingtr
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
61 views

Lec 08 z Recurrence

Uploaded by

bdgamingtr
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 27

CENG 2003

Assist. Prof. Dr. Zeynep Filiz EREN

LECTURE 8: RECURRENCES
Rosen 5th ed., §6.1 – 6.3
RECURRENCE RELATIONS
¢ Some of the counting problems that cannot be
solved using the techniques discussed in Chapter
4 can be solved by finding relationships, called
recurrence relations, between the terms of a
sequence.
¢ We will study a variety of counting problems that
can be modeled using recurrence relations.

1
LEARNING OUTCOMES
¢ Solve problems using recurrence relations.
¢ Define appropriate recurrence relations for a
given problem.
¢ Solve linear recurrence relations by recognizing
homogeneity, linearity, constant coefficients,
degree, and characteristic equation.
¢ Design recurrence relations using the divide-and-
conquer algorithm.

(#)
BOOK EX-3: 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 be in the account
after 30 years?
Solution:
¢ To solve this problem, let Pn denote the amount in the
account after n years. Since the amount in the account
after n years equals the amount in the account after n- 1
years plus interest for the nth year, we see that the
sequence {Pn} satisfies the recurrence relation

2
BOOK EX-4: RABBITS AND THE FIBONACCI
NUMBERS
¢ A young pair of rabbits (one of each sex) is placed
on an island. A pair of rabbits does not breed
until they are 2 months old. After they are 2
months old, each pair of rabbits produces another
pair each month, as shown in Figure 1. Find a
recurrence relation for the number of pairs of
rabbits on the island after n months, assuming
that no rabbits ever die.

3
BOOK EX-4: RABBITS AND THE FIBONACCI
NUMBERS

4
EX: PARANTHESIS OF MULTIPLICATION

The picture can't be displayed.

¢ Find a recurrence relation for Cn, the number of


ways to parenthesize the product of n + 1 numbers,
x0 × x1 × .... × xn
to specify the order of multiplication.

(For example, C3 = 5 since there are five ways to


parenthesize x0 × x1 × .... × x5 to determine the order of
multiplication. Show!)

5
EX: BIT STRINGS OF LENGTH N THAT DO NOT HAVE
TWO CONSECUTIVE 0’S

¢ Find a recurrence relation and give initial conditions


for the number of bit strings of length n that do not
have two consecutive 0s. How many such bit strings
are there of length five? Assume n≥3
¢ Examples: 01111010, 10, 10101

sn = sn-1 + sn-2
s1 = 2
s2 = 3 6
LINEAR HOMOGENEOUS RECURRENCE
RELATIONS WITH CONSTANT COEFFICIENTS

We’ve seen a variety. Techniques for solving


depend on the particular form of the recurrence.

Linear Recurrences with Constant Coefficients


an = c1an-1 + c2an-2 + … + ckan-k + f(n) “order k”

Ex. an = 5an-1 - 6an-2 , a0 = 0, a1 = 1

a2 = 5
Given any k consecutive values, a
a3 = 5(5) - 6(1) = 19 unique solution exists.
a4 = … 7
THEOREM

¢ BOOK EXAMPLE-3: What is the solution of the


recurrence relation:
an = an -1 + 2an - 2
with a0 = 2, a1 = 7
Rewrite:
Find characteristic eqn:
Find roots of char eqn:
Find general solution:
8
EXAMPLE

Linear homogeneous recurrence relations with


constant coefficients.
We want to be able to
another example: compute T(n), without
T(n) = 7T(n-1) - 10T(n-2) having to compute T(n-k)
T(0) = 2, T(1) = 1
To achieve this we “solve” the
recurrence.
Rewrite: T(n) - 7T(n-1) + 10T(n-2) = 0
Find characteristic eqn: r2 - 7r + 10 = 0
Find roots of char eqn: (r-2)(r-5) = 0, r=2,5
General solution is T(n) = α12n + α25n
9
EXAMPLE CONT’D

Example continued:
T(n) = 7T(n-1) - 10T(n-2)
T(0) = 2, T(1) = 1

General solution is T(n) = α12n + α25n

Now what? … think about what we know!

α 12 0 + α 25 0 = 2 α 1+ α 2 = 2 α1= 3, α2 = -1
α 12 1 + α 25 1 = 1 2α1 + 5α2 = 1

Unique solution is T(n) = 3·2n - 5n 10


EXERCISE

You try a tricky one:


T(n) = T(n-2)/4
T(0) = 1, T(1) = 0

Rewrite:
Find characteristic eqn:
Find roots of char eqn:
General solution is
Set up system of eqn to get unique soln.

11
BOOK EXAMPLE-6

Find the solution to the recurrence relation:

an = 6an-1 - 11an-2 + 6an-3, n ³ 3


a0 = 2, a1 = 5, a2 = 15

12
EXERCISE

Find the solution to the recurrence relation:

an = 4an-1 - 5an-2 + 2an-3, n ³ 3


a0 = 0, a1 = 1, a2 = 2

13
LINEAR NON-HOMOGENEOUS RECURRENCE
RELATIONS

Linear NONhomogeneous recurrence relations with


constant coefficients.

c0an + c1an-1 + c2an-2 + … + ckan-k = f(n),

constant
Where f(n) is
polynomial in n
cn for some constant c
cn · polynomial(n)

This approach is different than the one before.


15
THEOREM

14
BOOK EX-10
¢ Find all solutions of the recurrence relation
an = 3an-1 + 2n. What is the solution with a1 =3?

16
BOOK EX-11
¢ Find all solutions of the recurrence relation
n
an = 5an -1 - 6an - 2 + 7

17
SEQUENCES

First, some notation:

A sequence a0, a1, a2, …, is denoted áanñ

Examples á2nñ = 1,2,4,8,…


án2ñ = 0,1,4,9,…
ánñ = 0,1,2,3,…

Note: if áanñ and ábnñ are sequences, then áanñ + ábnñ


represents the sequence áan + bnñ (termwise addition). 18
SEQUENCES

Sequence operators:

Constant multiplication
c·áanñ defined to be ác·anñ
Ex: 3·á2nñ = á3·2nñ = 3, 6, 12, 24, 48, …

Shift “E”
Eáanñ = áan+1ñ shifts the sequence
Ex: Eá2nñ = á2n+1ñ = 2, 4, 8, 16, …
Ex: Eá3n + 1ñ = á3(n+1) + 1ñ = á3n + 4ñ

19
SEQUENCES

Combining operators:

If A,B are seq ops, then A+B is a seq op:


(A+B)áanñ defined to be Aáanñ + Báanñ
Ex: (E+2)á2nñ = Eá2nñ + 2á2nñ
= á2n+1ñ + á2·2nñ
= á2n+1ñ + á2n+1ñ
= á2n+1 + 2n+1ñ
= á2·2n+1ñ = á2n+2ñ
If A,B are seq ops, then AB is a seq op:
(AB)áanñ defined to be A(Báanñ)
Ex: E3áanñ = E·E·Eáanñ = E(E(Eáanñ)) = áan+3ñ
20
SEQUENCES

An important operator: (E-1) Discrete derivative

Example: (E-1)ánñ = Eánñ - ánñ


= án + 1ñ - ánñ
= án + 1 - nñ = á1ñ
More generally: (E-1)áanñ = áan+1ñ - áanñ
= áan+1 - anñ
(E-1)án2ñ = Eán2ñ - án2ñ
= á(n+1)2ñ - án2ñ
= án2 + 2n + 1ñ - án2ñ = á2n + 1ñ
21
SEQUENCES

For any constant sequence ácñ:

(E-1)ácñ = á0ñ (E-1) “annihilates” ácñ

TRICK: to solve a NONhomogeneous linear


recurrence with constant coefficients, turn
it into a homogeneous recurrence by applying
operators to annihilate the right side.

22
EXAMPLE

Solve an = 5an-1 - 6an-2 + 4

Rewrite: an - 5an-1 + 6an-2 = 4


Rewrite again so n is smallest index:
an+2 - 5an+1 + 6an = 4
Rewrite again as a sequence:
áan+2 - 5an+1 + 6anñ = á4ñ
Rewrite again using operators:
(E2 - 5E + 6)áanñ = á4ñ
23
(E-1) “annihilates” ácñ
EXAMPLE CONT’D

Example: solve an = 5an-1 - 6an-2 + 4

(E2 - 5E + 6)áanñ = á4ñ (E-1) “annihilates” ácñ


Annihilate right side:
(E-1)(E2 - 5E + 6)áanñ = (E-1)á4ñ
(E3 - 6E2 + 11E - 6)áanñ = á0ñ
But that’s just:
an+3 - 6an+2 + 11an+1 - 6an = 0
an - 6an-1 + 11an-2 - 6an-3 = 0
Homogeneous!!!
24
EXAMPLE CONT’D

Example: solve an - 6an-1 + 11an-2 - 6an-3 = 0 Homogeneous!!!

Characteristic equation:
(r3 - 6r2 + 11r - 6) = 0
(r-1)(r-2)(r-3) = 0

General solution: an = A1 + A22n + A33n

25

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy