Lecture 16 MTL180
Lecture 16 MTL180
Lecture 16 — 26/09/2024
Lecturer: Prof Minati De Scribe:
Scribed by:
1. Himanshu (2023MT10074)
1 Overview
In last class we discussed about r permutations and r combinations. In this class we are going to
discuss about distributing objects into boxes and recurrence aspect of permutation and combination.
• We first consider the case when distinguishable objects are placed into distinguishable boxes.
Question 1. What is the number of ways of distributing n different objects in n different boxes
such that each box contain atmost 1 object?
Answer. Total number of ways of distributing n distinct objects in n distinct boxes is n! with the
condition that each box can contain atmost 1 object as first object has n choices, second one has
n-1 choices and so on.
1
Question 2. What is the number of ways of distributing n different objects in r different boxes
such that each box contain atmost 1 object?
Question 3. What is the number of ways of distributing r different objects in n different boxes
such that each box has endless capacity?
Answer. In this question we can see that each object has n choices. Hence, total number of
distributions possible are nr .
• We can generalise it for n objects and k boxes such that each box has ni number of objects.
The number of ways to distribute n distinguishable objects into k distinguishable boxes so
n!
that ni objects are placed into box i, i = 1,2,...,k equals n !n !···n !
1 2 k
Question 1. There are n distinct boxes and we have to distribute n objects not all distinct and
also we are given that any box can contain at most 1 object. We are given that a1 number of
objects are of type 1, a2 are of type 2,... ak are of type k and
k
X
ai = n
i=1
n!
Answer. Number of ways of distribution are a !a !···a ! because first we choose a1 number of boxes
1 2 k
and distribute type 1 objects into them we can do this in C(n,a1 ) number of ways then we chose
a2 number of boxes from remaining n-a1 boxes and distribute type 2 objects into them we can do
this in C(n − a1 ,a2 ) number of ways and so on for type k we can choose ak number of boxes from
remaining n − a1 − a2 ... − ak−1 boxes which is C(n − a1 − a2 ... − ak−1 ,ak ) which overall results in
n!
a !a !···a ! .
1 2 k
2
Question 2. We are given n distinguishable boxes and r non-distinguishable objects and also we
are given that r ≥ n. What is number of ways in which we can distribute these objects into boxes?
Answer. If we assume that each box contains exactly 1 object then total number of ways of
distributing objects into boxes are 1 as all boxes will have 1 object and as all objects are non-
distinguishable their order of distribution is immaterial.
Question 3. We are given n distinguishable boxes and r non-distinguishable objects and also we
are given that r < n and any box can contains at most 1 object. What is number of ways in which
we can distribute these objects into boxes?
Answer. We can distribute objects into boxes in C(n, r) number of ways. We can select r boxes
out of n boxes and place 1 object in each box as all objects are non-distinguishable their order of
distribution is immaterial.
Question 4. We are given n distinguishable boxes and r non-distinguishable objects and also we
are given that r < n and any box may contain any number of objects. What is number of ways in
which we can distribute these objects into boxes?
Answer. We can proceed with this question by partition method. We make n − 1 partitions and
we are given r objects we can permute these partitions and objects in total C(n + r − 1, r) ways.
Question 5. We are given n distinguishable boxes and r non-distinguishable objects and also we
are given that r ≥ n and any box contains at least 1 object. What is number of ways in which we
can distribute these objects into boxes?
Answer. We can proceed with this question by distributing 1 object in each of the boxes and
then we are left with r − n number of objects which are to to distributed in n boxes which can be
done in C(n − 1 + (r − n), r − n) number of ways. (From Question 4)
• We can generalise the argument given in Question 5 as let we are given condition that each
box must contain at least q number of elements then number of ways of distributing objects
into boxes can be written as C(n − 1 + (r − nq), r − nq).
• If we are given a problem like x1 , x2 ..., xn are non-negative integers and given a condition
that x1 + x2 + x3 ... + xn = r then this situation is same as distributing r indistinguishable
objects into n distinct boxes with condition that a box may contain any number of objects.
• If we are given a problem like x1 , x2 ..., xn are non-negative integers and given a condition
that x1 + x2 + x3 ... + xn ≤ r then we can solve this by introducing a dummy variable y such
that x1 + x2 + x3 ... + xn + y = r such that y is an integer with value ranging from 0 to r.
3
3 Recurrence Relation
• We can use recurrence relations to model a wide variety of problems, such as finding compound
interest, determining the number of moves in the Tower of Hanoi puzzle, and counting bit
strings with certain properties.
Answer. For the given code the correct output is 10,9,8,7,6,5,4,3,2,1. If we swap Line 1 and Line
2 (Given in the code) then correct output will be 1,2,3,4,5,6,7,8,9,10.
Example. How many times will the function print be called?
int p r i n t ( int n ) {
i f ( n == 0 )
return 1 ;
return p r i n t ( n−1)+ p r i n t ( n −1);
}
print (n ) ;
Answer. The function print will be called 2n times. A tree will be formed with 1 call at it’s first
level, 2 at it’s second level, 4 at it’s third and so on.
Example. How many times will the function print be called?
int p r i n t ( int n ) {
i f ( n == 0 )
return 1 ;
return 2∗ p r i n t ( n −1);
}
print (n ) ;
Answer. The function print will be called n times. A stack of recursive calls will be formed with
n levels.
Question. 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. Find a recurrence relation for the number of pairs of rabbits
on the island after n months , assuming that no rabbits ever die.
4
Figure 1: Rabbits on an Island
Answer. From the given Figure 1 we can can clearly see that total pairs is equal to sum of
reproducing pairs and young pairs in each month. We can also see that reproducing and young
pairs are forming Fibonacci sequence after 2nd month. Hence we can write that T P [n] = T P [n −
1] + T P [n − 2] for n greater than equal to 4, for n=1,2,3 the values of total pairs is equal to 1,1
and 2 respectively.
Question. We are given dominoes of size 2 × 1 we are given a board of size 2 × n we have to fill
the board with given dominoes keeping in mind that one can rotate the dominoes. What are the
total number of ways one can fill the board?
Answer. We assume that total number of to fill 2 × n board is T (n). We can solve this problem
using recursion. We first consider a board of size 2 × (n − 1), to obtain board of size 2 × n from
2×(n−1) we have just one way of putting domino in that 2×(n−1) i.e. vertically. Now we consider
board of size 2 × (n − 2), we can obtain 2 × n sized board by putting two dominoes horizontally. If
we put one domino vertically 1st case is repeated. Hence we have to only one way to obtain board
of size 2 × n from board of size 2 × (n − 2) i.e. put both dominoes horizontally. Hence total number
of ways T (n) can be written as T (n − 1) + T (n − 2).
Question. Define k-stair such that maximum height of staircase is k. We have to fill a k-stair
using rectangles of variable dimensions. Compute the total number of ways of filling the k-stair.
Answer. We can see in figure 2 that n-stair is partitioned into a k − 1 stair and n − k stair and a
rectangle. We can write recursive formula as tn = nk=1 tk−1 · tn−k where tn denotes total number
P
of ways for n-stair and t0 = 0, t1 = 1 and t2 = 2.
5
Figure 2: Schematic for above question
References
[1] K. H. Rosen, Discrete Mathematics and Its Applications, 7th ed., New York, NY: McGraw-Hill,
2012.