Modeling with Recurrence Relations
-
Upload
devanshu-taneja -
Category
Engineering
-
view
113 -
download
10
Transcript of Modeling with Recurrence Relations
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