Lecture 17 MTL180
Lecture 17 MTL180
Lecture 17 — 30/09/2024
Lecturer: Prof Minati De Scribe: 17
Scribed by:
5. Sapna (2023MT10470)
1 Overview
In the last lecture, we learned about distributing objects into boxes and the recurrence aspect of
permutations and combinations.
In this lecture, we will learn about recurrence relations, and how to apply them in various
problems.
2 Recurrence Relations
Fn = F n − 1 + Fn−2
1
2.2 Factorial:
n! = n ∗ (n − 1) · · · ∗ 1
n! = n(n − 1)!
We will now study various problems where we will find the recurrence relation in order to reach
the answer.
Question 1: You have n stairs and n rectangles. In how many ways can you fill the entire
staircase.
Answer:
t0 = 1, t1 = 1, t2 = 2, t3 = 5
Then, the tnk for this particular case would be equal to tk−1 tn−k . Therefore,
2
n
X
tn = tk−1 tn−k
k=1
where t0 = 1 and t1 = 1
Answer:
S0 = ϕ , S1 = {a1 }, S2 = {a1 , a2 }, ..... , Sn = {a1 , a2 , .... ,an }
If Sn = {a1 , a2 , .... ,an }, then all the subsets of Sn , not containing an , would be the same as all
the subsets of Sn−1 . Therefore, the number of these subsets would be equal to the cardinality of
Sn−1 .
All the remaining subsets of Sn would contain an . Each of these subsets would be a union of some
unique subset of Sn−1 and an . Therefore, the number of the remaining subsets would be equal to
the cardinality of Sn−1 .
|Pn | = 2 ∗ |Pn−1 |
|Pn | = 2 ∗ 2 ∗ |Pn−2 | = 22 ∗ |Pn−2 |
|Pn | = 2 ∗ 22 ∗ |Pn−3 | = 23 ∗ |Pn−3 |
.
.
.
.
|Pn | = 2n ∗ |P0 | = 2n
Question 3: Find the number of sequences of upper-case letters that do not contain ”ZZ”.
Answer:
t0 = 1 , t1 = 26 , t2 = 262 −1(number of sequences f rom AA to ZZ = 262 , and we subtract 1 f or ZZ)
Case 1:
When the first letter of the tn sequence is ”Z”, the next letter cannot be ”Z”. There are 25 ways
to achieve this. Since the second letter is not ”Z”, the third letter can be anything. Therefore, the
3
total number of possibilities of the next n - 2 letters is tn−2 . Total number of sequences in this case
is 25 * tn−2 .
Case 2:
When the first letter of the tn sequence is not ”Z”. There are 25 ways to achieve this. Since the
first letter is not ”Z”, the second letter can be anything. Therefore, the total number of possibilities
of the next n - 2 letters is tn−1 . Total number of sequences in this case is 25 * tn−1 .
Therefore, total number of sequences (tn ) = 25 * (tn−1 + tn−2 )
Question 4: Find the number of sequences of upper-case letters that do not contain the substring
”DOG”.
Answer:
Let tn represent the number of valid sequences of length n. We calculate the values as follows:
t0 = 1
t1 = 26
t2 = 262
t3 = 263 − 1(number of sequences f rom AAA to ZZZ = 263 , and we subtract 1 f or DOG)
tn = 26tn−1 − tn−3
Case 1:
If the first letter of the sequence is ’D’, then the next two letters cannot be ’O’ and ’G’. Therefore,
the remaining n − 3 letters form a sequence of length tn−3 .
4
Case 2:
If the first letter is not ’D’, there are 25 choices (since it can be any other letter). The number of
possible sequences for the remaining n − 1 letters is tn−1 .
Thus, the total number of valid sequences is:
tn = 26tn−1 − tn−3
Question 5: Number of sequences of A’s, B’s and C’s that contain an odd number of C’s.
Answer:
t0 = 0
t1 = 1
t2 = 4
5
Answer:
t1 = 1
t2 = ( () ) , ( ()() ) , ⇒ 2
n
X
tn = tk tn−k ⇒ Catalan number
k=1
2n
n
Cn = , Cn = Catalan number
n+1
2. A disk can only be placed on top of a larger disk, never on a smaller one.
3. All disks start on one peg in decreasing size (largest at the bottom, smallest at the top).
6
Tower of Hanoi: Recurrence Relation
Hn = 2Hn−1 + 1
where Hn represents the minimum number of moves required to transfer n disks from one peg to
another, following the rules of the puzzle. The initial condition is H1 = 1, because one disk can be
moved in a single step.
We can iteratively expand this recurrence relation to obtain:
Hn = 2(2Hn−2 + 1) + 1 = 22 Hn−2 + 2 + 1
= 23 Hn−3 + 22 + 2 + 1
= . . . = 2n−1 H1 + 2n−2 + 2n−3 + · · · + 2 + 1
Hn = 2n − 1
The name for this method is pretty self explanatory. We look at the recurrence relation and try to
guess the answer. Then we check if our guess is consistent with both the initial condition and the
recurrence.
hn = 2hn−1 + 1
h1 = 1
We now guess hn to equal 2n − 1.
Putting n = 1 we get h1 = 1.
7
Now, putting hn = 2n − 1 into the equation, we get:
hn = 2(2n−1 − 1) + 1
= 2n − 2 + 1
= 2n − 1
It is clear that both the initial conditions and the equation are consistent. Hence, our guess was
correct.
In this method, we repeatedly substitute the recurrence relation into itself until we reach the initial
condition. It is easier to illustrate this with an example.
tn = 3hn−1 + 7
t0 = 5
Now we will begin substituting the equation into itself.
tn = 3tn−1 + 7
= 3(3tn−2 + 7) + 7
= 32 tn−2 + 3 · 7 + 7
= 33 tn−3 + 32 · 7 + 3 · 7 + 7
= 3k tn−k + 3k−1 · 7 + 3k−2 · 7 + · · · + 3 · 7 + 7
Putting k = n
= 3n t0 + 3n−1 · 7 + 3n−2 · 7 + · · · + 3 · 7 + 7
= 3n · 5 + 7 3n−1 + 3n−2 + · · · + 3 + 1
n
n 3 −1
=5·3 +7
2
References
[1] [1] K. H. Rosen, Discrete Mathematics and Its Applications, 7th ed., New York, NY: McGraw-
Hill, 2012