modeling with recurrence relations
TRANSCRIPT
MODELING WITH
RECURRENCE RELATIONS
CONTENTS
COUNTING TECHNIQUES
MOTIVATION
RECURSIVE DEFINITIONS
RECURRENCE RELATIONS
MODELING WITH RECURRENCE RELATIONS
(PROBLEMS AND SOLUTIONS)
β Product rule
β Sum rule
β The Inclusion-Exclusion Principle
β The Pigeonhole Principle
β Permutations
β Combinations
1 2 1 2 1 2A A A A A A
Counting technique
Number of ways = n1n2 Β·Β·Β· nm
Number of ways = n1 + n2 +β¦+ nm
If N objects are placed into k boxes, then there is at least one box
containing at least objects.
N k
!, 1 2 1
!
nP n r n n n n r
n r
!,
! !
n nC n r
r r n r
MOTIVATION
The number of bacteria in a colony doubles every hour. If the colony begins with 5 bacteria, how many will be present in n hours?
Let an : the number of bacteria at the end of n hoursThen;
an = 2an-1, a0=5
What we are doing actually?
We find a formula/model for an (the relationship between an and a0) β this is called recurrence relations between the term of sequence.
Since bacteria double every hour Initial condition
By using
recursive
definition
Solution:
RECURSIVE DEFINITIONS
Recursion β a process to define an object explicitly
The object can be a sequence, function or set (for BCT2078 purposes)
The ideas β construct new elements from known elements.
Process β specify some initial elements in a basis step and provide a rule for constructing new
elements from those we already have in the recursive step.
Mathematical Induction can be used to prove the result.
The given
complex
problem
This
simple
version
can be
solved
This simple
version
can be
solved
Can be
solved if
Can be
solved if
Can be
solved if
an = 2an-1 an-1 = 2an-2, a1 = 2a0, a0=5
RECURRENCE RELATION
A recursive algorithm provides the solution of a problem of size n in term of the solutions of one or more instances of the same problem in smaller size.
The initial condition specify the terms that precede the first term where the recurrence relation takes effect.
A recurrence relation for the sequence {an} is an equation that expresses an in terms of one or more of the previous terms of the sequence, namely, a0, a1,β¦, an-1, for all integers n with n β₯ n0,
where n0 is a nonnegative integer.
A sequence is call solution of a recurrence relation if its term satisfy the recurrence relation.
an = 2an-1
a0 = 5 Initial condition
Recurrence relationRecursive
definition
Modeling with Recurrence Relation
We can use recurrence relation to model a wide variety of problems
such as
Finding a compound interest
Counting a population of rabbits
Determining the number of moves in the Tower of Hanoi puzzle
Counting bit strings
RABBITS
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.
Assume that none of the rabbits die.
How many rabbits are there after n months?
RABBITS
Let ππ denote the number of pairs of rabbits after n
months.
ππ = 1 { reproducing pairs = 0, young pairs = 1 }
ππ = 1 { reproducing pairs = 0, young pairs = 1 }
ππ = 2 { reproducing pairs = 1, young pairs = 1 }
ππ = 3 { reproducing pairs = 1, young pairs = 2 }
ππ = 5 { reproducing pairs = 2, young pairs = 3 }
ππ= 8 { reproducing pairs = 3, young pairs = 5 }
RABBITS
The rabbit population can be modeled by a recurrence relation.
At the end of the first month, the number of rabbits on the island is ππ = 1.
At the end of the second month, the number of rabbits on the island is ππ = 1.
The number of pairs of rabbits after n months ππ is equal to the number of
pairs of rabbits from the previous month ππβπ plus the number of pairs of
newborn rabbits, which equals ππβπ, since each newborn pair comes from a
pair that is at least two months old, so
ππ = ππβπ + ππβπ for n >= 3.
SOLVING RABBITS PROBLEM
The recurrence system
Initial conditions: ππ = 1, ππ = 1
Recurrence relation: ππ = ππβπ + ππβπ for n >= 3. (Linear Homogeneous RR
with const coeff.)
For small values of n, we get
(ππ,, ππ , ππ,...) = (1,1,2,3,5,8,13,...)
Characteristic equation : ππ- π -1 =0
Characteristic roots: ππ= (1+β5)/2 and ππ = (1- β5)/2
SOLVING RABBITS PROBLEM
Therefore, ππ = π¨πβ((1+β5)/2)π
+ π¨πβ((1ββ5)/2)π
, π¨π and π¨π are
constants
π¨π = β5/5 ; π¨π = ββ5/5
ππ = π¨πβ((1+β5)/2)π
+ π¨πβ((1ββ5)/2)π
=π
βπβ(1+β5)/2)
π-
π
βπβ(1ββ5)/2)
π
TOWER OF HANOI
Initially, n discs are placed on the first peg. Move the n discs one at a time
from one peg to another such that no larger disc is ever placed on a
smaller disc.
Goal: Move the discs from peg 1 to peg 2.
TOWER OF HANOI
Let π»π denote the number of moves needed to solve the tower of Hanoi
problem with n discs.
1) Move the top n-1 discs from peg 1 to peg 3 using Hn-1 moves.
TOWER OF HANOI
Let π»π denote the number of moves needed to solve the tower of Hanoi
problem with n discs.
1) Move the top n-1 discs from peg 1 to peg 3 using Hn-1 moves.
2) Move the largest disc from peg 1 to peg 2.
TOWER OF HANOI
Let π»π denote the number of moves needed to solve the tower of Hanoi problem with n
discs.
1) Move the top n-1 discs from peg 1 to peg 3 using Hn-1 moves.
2) Move the largest disc from peg 1 to peg 2.
3) Move the n-1 discs from peg 3 to peg 2 using Hn-1 moves.
TOWER OF HANOI
Let π»π denote the number of moves needed to solve the tower of Hanoi problem with n
discs.
1) Move the top n-1 discs from peg 1 to peg 3 using π»πβ1 moves.
2) Move the largest disc from peg 1 to peg 2.
3) Move the n-1 discs from peg 3 to peg 2 using π»πβ1 moves.
TOWER OF HANOI
Let π»π denote the number of moves needed to solve the tower of Hanoi
problem with n discs. Thus the no of moves is given by
Where:
1 12 1 ; 1n nH H H
Hn-1 moves
Moves the largestdisk to peg 2
transfer the top ofn-1 disks to peg 2
1 moveHn-1 moves
transfer the top ofn-1 disks to peg 3
+ +
SOLVING TOWER OF HANOI PROBLEM
Initial condition: π»1 = 1
Recurrence relation: π»π = 2π»πβ1+1 for n >= 2.
For small values of n, we get
(π»1π»2π»3π»4,...) = (1,3,7,15,...)
Therefore, we can guess that π»π = ππ - 1
SOLVING TOWER OF HANOI PROBLEM
How can we prove that π―π = ππ-1 holds for all n>=1?
By induction.
Base Step: π―π = 1 = ππ β π, so our claim holds for n=1.
Inductive Step: Suppose that π»π = ππ - 1 holds for some n>=1.
It follows that
π―π+π = 2π»π + 1 = 2(ππ- 1 ) + 1 = ππ+π-2+1= ππ+π-1
Therefore, the claim follows by induction on n.
CODEWORD ENUMERATION
A computer system considers a string of decimal digits a valid
codeword if it contains an even number of 0 digits.
For instance, 1230407869 is valid, whereas 120987045608 is not valid.
Let ππ be the number of valid n-digit codewords.
CODEWORD ENUMERATION
Note that ππ = 9
A recurrence relation can be derived for this sequence by
considering how a valid n-digit string can be obtained from
strings of n-1 digits.
Two ways to form a valid string with n digits from a string with
one fewer digit.
CODEWORD ENUMERATION
First, a valid string of n digits can be obtained by appending a valid
string of n β 1 digits with a digit other than 0. This appending can be
done in nine ways. Hence, a valid string
with n digits can be formed in this manner in 9ππβ1 ways
CODEWORD ENUMERATION
Second, a valid string of n digits can be obtained by appending a 0 to a string of
length n β 1 that is not valid. The number of ways that this can be done equals
the number of invalid (n β 1)-digit strings. Because there are πππβπ strings of length
n β 1, and ππβπ are valid, there are πππβπ β ππβπ valid n-digit strings obtained by
appending an invalid string of length n β 1 with a 0.
Since all valid strings of length n are produced in one of these two ways, it follows
that there are
ππ = 9ππβπ + (πππβπ β ππβπ)
= 8ππβπ + πππβπ
valid strings of length n.
SOLVING CODEWORD ENUMERATION
Initial condition: π1 = 1
Recurrence relation: ππ = 8ππβ1 + 10πβ1 for n >= 2. (Non-homogeneous RR with const coeff.)
=> ππ - 8ππβ1 = 10πβ1
We need to solve ππ = ππ(π)
+ ππ(π)
Characteristic equation: r - 8 = 0
Characteristic root: π1 = 8
Ξ² = 10
SOLVING CODEWORD ENUMERATION
Therefore, ππ(π)
= π¨πβ ππ , where π¨π is constant
And, ππ(π)
= ππ β(π·π β πππβπ) , where π·π is a constant
=> π·π(πππβπ β π β πππβπ) = πππβπ , since ππ - 8ππβ1 = 10πβ1
=> π·π = 5
=> ππ(π)
= 5β πππβπ
Therefore, ππ = ππ(π)
+ ππ(π)
= (π¨πβ ππ) + (5 β πππβπ)
=> π¨π = Β½ (ππ = 9)
SOLVING CODEWORD ENUMERATION
Therefore,
ππ = ππ(π)
+ ππ(π)
= (π¨πβ ππ) + (5 β πππβπ)
= (1/2 β ππ) + (5 β πππβπ)
=π
π(ππ + πππ)
THATβS ALL : THANK YOU