Professional Documents
Culture Documents
1. Counting
1. Counting
Solved Examples
1. In how many ways can we draw a face Rule of product:
card from a deck?
If there are m choices for one event and n
Solution: choices for another event, then there are m
In a deck of 52 cards, there are 4 suits. × n choices for both these events to occur.
If a sequence of tasks T1, T2 … Tn can be done
in W1, W2, …, Wn ways respectively (every task
arrives after the occurrence of the previous
J→4 task) then the number of ways to perform all
the tasks is W1 × W2 × … × Wn.
Q→4
K→4 Note:
In the rule of multiplication, different jobs/
We want to draw a one-face card between
operations are mutually inclusive, it implies
all these no of choice = 4 + 4 + 4 = 12
that all jobs are being done in succession.
In this case, we use word ‘and’ to complete
2. A pencil box contains 2 red and 3 black
all stages of operation, and the meaning of
pens. Total number of ways for selecting
‘and’ is multiplication.
1 red pen and 1 black pen or 2 red pens.
Solution:
2 ways for selecting red pens because 2 pens 3. Let us consider the following. Rahul has
are there. 3 pants and 2 shirts. How many different
pairs of pants and a shirt, can he dress
3 ways for selecting black pens because 3
up with?
pens are there.
Solution:
∴ Total ways for selecting 1 red and 1 black
=3×2=6 There are 3 ways in which a pant can be
chosen (because 3, pants available) says P1,
∴ Number of ways of selecting 2 red pens = 1
P2, P3
Total ways for selecting 1 red and 2 black or
2 red is 6 + 1, i.e., 7 ways.
Counting 85
Similarly, a shirt can be chosen in 2 ways. Solution:
(Because 2 shirts available, say S1, S2). A die can fall in 6 different ways, i.e., 1, 2, 3,
For every choice of a pant, there are 2 choices 4, 5, 6, and a coin can fall in 2 different ways,
of a shirt. i.e., head or tail.
Therefore, there are 3 × 2 = 6 pairs of pants Number of possible outcomes from a die
and shirts. and a coin = 6 × 2 = 12 ways.
86 Counting
y Permutation of n different thing taken r at
a time when a particular thing always
Rack Your Brain occurs = r*(n−1)P(r − 1)
Counting 87
Combination: y)n nC 0 xn−0 y 0 + nC 1xn−1 y 1 + ...nC nxn−n yn
y (x +=
y An unordered selection of object is called
a combination. y 2n = nC + nC + nC ... + nC
0 1 2 n
y In combination arrangement of things
{Put x = 1 and y = 1 in above equation}
doesn’t matter until the specific thing is
to be included. y (1 + x)n = nC + nC x + nC x2 + ...nC xn
0 1 2 n
y The combination of three alphabets {a, b,
c} taken two at a time are {a, b}, {a, c}, {b, y n ⋅ 2n− 1 = 1 ⋅ nC + 2 ⋅ nC + ... + n ⋅ nC
1 2 n
c}, here {a, b} and {b, a} are not considered
separately. {By differentiate above and put x = 1}
y The word combination and selection are
2n
synonymous. y nC + nC + nC + = nC + nC + nC + = = 2n− 1
0 2 4 1 3 5 2
2n
nC + nC + nC + = nC + nC + nC + = = 2n− 1
Rack Your Brain 0 2 4 1 3 5 2
88 Counting
Solution: (A), (C)
Let x1 x2 x3 are number of balls in box 1, box In how many ways of placing 20 similar
2, box 3 respectively. balls into 4 boxes where each box is non
So, x1 + x2 + x3 = 10 [n = 3, r = 10] empty?
Using n – 1 + r Cr = 3–1 + 10
C10 = 12
C10 = 12
C2
Solved Examples
10. In how many ways you can place atmost y The number of ways of dividing 2p items
7 similar balls into 4 distinct boxes. (2p) !
into two equal groups of p each is ,
Solution: 2 !(p !)2
Let x1,x2,x3,x4 are the number of balls in box 1, where the two groups do not have a distinct
2, 3, 4 respectively. identities.
y The number of ways in which (p + q + r)
x1 x2 x3 x4
things can be divided into three groups
So, x1 + x2 + x3 + x4 ≤ 7. ∀xi ≥ 0 here r containing p, q, and r things, respectively,
value can be any of between 0 to 7. (p + q + r) !
is
7
p ! q!r !
=
So, ∑n − 1 + r
r =0
Cr
{n = 4} Difference between permutation and
combination:
7
Permutation Combination
= ∑3 +r Cr
r =0 Order is not
Order is important
3 4 5 6
= C0 + C1 + C2 + C3 + C4 + C5 + C6 + C7 7 8 9 10 important
= 1 + 4 + 10 + 20 + 35 + 56 + 84 + 120 Arrangement Selection
= 330 Keywords: Sets,
Keywords: password,
subset, team,
number, word
committee
Note:
The above problem can also solve using Derangement:
taken n = 5 (one more box as dustbin) and r y Derangement is a permutational
is 7 in formula n−1+r Cr. arrangement with no fixed points.
y Arrangement of elements in such a way
Dividing given into groups: that no is in its correct position. If n
y The number of ways of dividing (p + q) distinct items are arranged, the number
items, into two groups of p and q items, of ways they can be arranged so that they
do not occupy their intended spot is:
(p + q) !
respectively is
p ! q! 1 1 1 1 ( −1)n
D
=n
n! − + − +
y The number of ways of dividing 2p items 0 ! 1! 2 ! 3 ! n!
(2p) !
into two equal groups of p each is n
n!
(p !)2 Dn
= ∑ (−1) r
r!
where two groups have distinct identities. r =2
Counting 89
Solved Examples
11. There are 5 tables in a class, each Derangement of the remaining 5 envelopes
table containing the roll number of the and letters D5 = 44
student. How many ways can 5 students
Total number of ways of arrangement = 44 ×
be arranged such that no student sits at
21 = 924
the table having their own roll number?
Solution:
Previous Years’ Questions
This is a clear case of derangements of 5
tables and 5 students
In how many ways can we distribute 5
1 1 1 1 1 distinct balls, B1, B2, …, B5 in 5 distinct
D5= 5 ! 1 − + − + −
1! 2 ! 3 ! 4 ! 5 ! cells, C1, C2, …, C5 such that Ball B is not
in cell Ci, ∀ = 1, 2, … 5, and each cell
1 1 1 1 i
= 120 1 − 1 + − + − contains exactly one ball?
2 6 24 120
(A) 44 (B) 96
60 − 20 + 5 − 1 (C) 120 (D) 3125
= 120 ×
120 Solution: (A) [GATE 2004]
= 44
Number of divisors:
12. In how many ways can you put 7 letters If the prime factorisation of n is P1e1 ⋅ P2e1 Pkek ,
into their respective envelopes such that where P1 are distinct prime numbers then
exactly 2 go into the right envelope? the Number of divisors is
Solution: d(n) = (e1 + 1) × (e2 + 1) … × (ek + 1)
Number of ways in which the 2 correct Sum of the divisor is
envelopes can be selected
e1 + 1 e2 + 1 ek + 1
P1 −1 P2 −1 Pk −1
7 × 6 × 5! σ
=(n) × ×
= 7=
C2 7=
C5 = 21 P1 − 1 P2 − 1 Pk − 1
5! 2!
90 Counting
Properties of binomial coefficient: Multinomial theorem:
n
� Cr = nCn-r (symmetry) The multinomial theorem describes how to
n n-1 n-1 expand the power of a sum in terms of the
� Cr = Cr + Cr-1 (Pascal identity)
power of the terms in that sum. It is the
n r n n-k
� Cr × Ck = Ck × Cr − k (Newton’s identity) generalisation of the binomial theorem from
n binomials to multinomials.
� ∑
r=0
n
Cr = nC0 + nC1 + nC2 + nCn = 2n
n t n
(Row summation) (x 1 + x2 + xt )n
= ∑ ∏
⋅ xm
n ,n nt m = 1 m
n 1 2
∀n1 + n2 + nt =
n
� ∑ (-1) r r
Cr = nC0 – nC1 + nC2 – nC3 = 0 n n!
r =0 where =
n1 ,n2 nt n1 !n2 ! nt !
(Alternating sign row summation)
r
� Cr + r + 1Cr + 1 + r +2Cr +2 + + nCr =
n+ 1
Cr + 1
(Column summation) Note:
r The coefficient of x 1n1 x2n2 xtnt in the
� ∑
K =0
n m n m n
CK ⋅ Cr −K = C0 ⋅ Cr + C1 ⋅ Cr −1 + C2 ⋅ Cr −2 m n m n
Cr ⋅ mC0 = nof
+ expansion +m
C(xr + x + … x )n
1 2 t
n!
where n = n1 + n2 + … nt is .
= nC0 ⋅ mCr + nC1 ⋅ mCr −1 + nC2 ⋅ mCr −2 + nCr ⋅ mC0 = n+m
Cr n1 !n2 ! nt !
(Vandemondes identity)
1
Rack Your Brain Cn = 2n
n + 1 Cn
Counting 91
Solved Examples � Polygon triangulation (A convex polygon
with n + 2 sides can be triangulated in Cn
16. In how many ways can we start from (0, ways.
0) and go to (5, 5) without crossing the � If 2n people are seated around a circular
diagonal? (Assuming that you can move table, the number of ways can all of them be
up or right). simultaneously shaking hands with another
person at the table in such a way that none
Solution: of the arms crosses each other is Cn.
� Number of full binary trees with n + 1
1 2n
Cn = Cn leaves is Cn.
n+1
Generating function:
1 A generating function is a way of encoding an
= 2 × 5C
5+1 5
infinite sequence of numbers (an) by treating
them as the coefficients of a formal power
1
= 10 series. This series is called the generating
6 C5
function of the sequence.
10 ! Consider a sequence (a0,a1,a2…an…) of real
=
6 ⋅ 5!5! numbers then a function f(x) is defined as f(x)
= 42 = a0+a1x+a2x2+…anxn+… is called generating
function of the sequence.
Application of catalan numbers:
∞
There are number of applications which can f(x) = ∑a x
r =0
r
r
Solved Examples
17. Find generating function for finite 19. Find the generating function for 1, 2, 3, 4
sequence: Solution:
a0, a1, a2, a3, a4
f(x) =1 + 2x + 3x2 + 4x3 + ...
Solution:
We know that,
f(x) =a 0 + a 1x + a 2 x 2 + a 3 x 3 + a 4 x 4
1
=1 + x + x2 + x3 + x4 ...
1− x
18. Find generating function for the infinite
sequence: d
Differentiate both side by
1, 1, 1, 1… dx
Solution:
Generating function of 1, 1, 1, …
d 1
=
d
dx 1 − x dx
(
1 + x + x2 + x2 + x4 + ... )
1
= 1 + x + x 2 + x3 + x4 + … ∞ = (sum of
1− x
a 1
infinite GP series ) =1 + 2x + 3x2 + 4x3 + ...
1− x (1 − x)2
92 Counting
Solution:
To simplify the expansion. We extract x2
Rack Your Brain coefficient of x12 in
⇒ coefficient of x12 in (x2)2 (1+x+x2+…)2
Generating function for 12 , 22 , 32 , 42...
2
1
4
coefficient of x in x
12
Identities of generating functions: 1− x
2 3 1
1 + x + x + x + ... =
n
1. (1 + x)n =
1 + nC1 x + nC2 x2 + ... nCn xn = ∑
r =0
n
Cr xr 1 − x
1
1 1−1 −xnxn coefficient of x8 in the expansion of
2.1 +1 +x x+ +x2x......
2
+ +xnx−n1 −=
...... = (1 − x)2
1 −1 −x x
∞
1 ∞ coefficient of x8 in ∑ (r + 1) x r
(put r = 8)
3. 1 + x + x + x =
2
...
r =0
x
=
1− x
3
∑ r
r =0
1 (r + 1)(r + 2) r i =0
6.
(1 − x) 3
= ∑ r =0
2
x
what is g(i).
(A) i (B) i + 1
1 ∞ (C) 2i (D) 2i
7. =
1+ x ∑ (−1) x
r =0
r r
Solution: (A) [GATE 2005]
∞
1
8.
1 − ax
= ∑a x
r =0
r r
∞ ∞ ∞
Rack Your Brain
x
9.
= (1 − x)2
= (r + 1)
r 0=r 0=
Cr∑xr+1
= (r + 1)xr+1
= ∑
K 1
KxK ∑ Find coefficient of x12 in the expansion of
∞ ∞ ∞ (x3 + x4 + x5 + …)2 is _______.
x
x)2
= ∑ (r + 1)
r 0=r 0=
Cr xr+1
=∑ (r + 1)xr+1
=
K 1
∑
KxK (if r+1 = k)
Counting 93
Previous Years’ Questions Previous Years’ Questions
94 Counting
Recurrence relation: The recurrence relation is
y Many counting problems cannot be solved
a n = an− 1 + d n ≥ 1 , a0 = a
easily; one such problem can be easily
solved by a recurrence relation.
2. For the geometric progression {a, ar, ar2,
y A recurrence relation is a formula which
ar3 …}. The recurrence relation is
relates an with one or more preceding
terms (previous term) an–1, an–2 … . Where a n = (an− 1 ) ⋅ r n ≥ 1 , a0 = a
a0, a1, a2 be a sequence of real numbers.
Solved Examples
Counting 95
Characteristic equation for homogenous Characteristic equation for non-homogenous
recurrence relation: linear recurrence relation (f(n)¹ 0):
� If the roots are real and distinct � If f(n) = C(b)n and b is not root of C(t)
an anH + anP
= where anH is solution of
C1t1n + C2t2n + … + Cktkn
homogenous linear recurrence relation
� If the roots are real and equal (two roots and anP is particular solution (depends on
are equal) the form of f(n)).
(C1 + C2n) t1n + C3t3n + … + Cktkn � f(n) = C(b)n and b is not root of C(t)
anP = D(b)n
� If all the rots are real and equal
� f(n) = C(b)n and b is root of C(t) of
(C1 + C2n + C3n + … + Ckn ) t
2 k
1
n
multiplicity m.
t = 2, 1 an(P) = D(2)n
Put this in an – 3an – 1 = 7(2)n
Since the roots are real and distinct.
D(2)n – 3D(2)n – 1 = 7(2)n
So, an = C1(2)n + C2(1)n. 2n – 1 [2D – 3D] = 7(2)n
–D = 7 × 2
D = −14
Rack Your Brain
an(P) = –14(2)n
Write the recurrence relation of binary an = anH + anP
string of length n. Which do not contain
two consecutive zero. an C1 (3)n − 14(2)n
=
96 Counting
Chapter Summary
np nr n!
Permutation r
n1 ! ⋅ n2 !
n
Generating
Combination Cr n− 1+r
Cr function
y The number of combinations (selections) of n different things taking r at a time is
considered as a combination. It is written as n Cr (n choose r)
n n!
C(n,=
r) Cr
=
r !(n − r) !
y Selecting r objects out of n is the same as selecting (n-r) object out of n
n
Cr = nCc −r
{k-selection equal to k rejection} n
y Total selections that can be made from ‘n’ distinct items is given ∑
k =0
n
Ck = 2n
n n− 1
y = Cr Cr + n− 1Cr − 1
y The total number of selections of one or more objects from n different objects
=2n − 1 =(n C1 + nC2 + nC3 + ... + nCn )
y Total ways to select any number of items from n identical items
= n + 1 (when selection of 0 things is allowed)
=n (when at least one thing is to be selected)
y The total number of selections from p like things, q like things of another type, and r
distinct things
= (p + 1) (q + 1)2r – 1 (if at least one thing is to be selected)
= (p + 1) (q + 1)2r – 2 (if none or all cannot be selected)
y The total number of selections of r things from n different things when each thing can
be repeated an unlimited number of times = n − 1 + r C .
r
y Derangement is an arrangement such that no item should be there in its correct
position
n
n!
Dn
= ∑ (−1)
r =2
r
r!
n!
where n = n1 + n2 + … nt is
n1 !n2 ! nt !
y The number of shortest paths from point (i, j) to a point (p, q) is (p + q – i – j)C
p −i
Counting 97
Inclusion-exclusion principle:
y n (A ∪ B)= n (A) + n (B) − n (A ∩ B)
y n (A ∪ B ∪ C)
= n (A) + n (B) + n (C) − n (A ∩ B) − n (B ∩ C) − n (A ∩ C) + n (A ∩ B ∩ C)
y n (A ⊕ B)= n (A) − n (A ∩ B)
y n (A − B)= n (A) − n (A ∩ B)
y n (B − A)= n (B) − n (A ∩ B)
y n (A ∩ B)= n (∪) − n (A ∪ B)
y n (A ∪ B)= n (∪) − n (A ∩ B)
98 Counting