CS6015: Linear Algebra and Random Processes
Lecture 23: Counting sequences, Subtraction principle
Learning Objectives
What are sequences and how do you count them?
What is the subtraction principle?
The multiplication principle
(Special Cases)
Making a sequence of k objects from given n objects with repetition
10
M T W T F S S
How many weekly exercise plans can you make if you can repeat the same exercise more than once?
Make a sequence of 7 items from given 10 items
The number of sequences of kkk objects made from given nnn objects when any object in the sequence can be repeated any number of times is nkn^k
n^k
Make a sequence of 5 items from given 26 items
a b c d e f g h i j k l m n o p q r s t u v w x y z
26
5
How many 5 letter words can you form using the alphabets of the English language?
Making a sequence of k objects from given n objects with repetition
Making a sequence of k objects from given n objects without repetition
10
M T W T F S S
How many weekly exercise plans can you make if you cannot repeat the same exercise more than once?
Are the number choices at each step independent? Yes
10
M T W T F S S
Are the choices at each step independent? No
The number of sequences of kkk objects made from given nnn objects such that no object in the sequence can be repeated is n(n−1)(n−2)...(n−k+1)n (n-1) (n-2) ... (n-k+1)n(n−1)(n−2)...(n−k+1)
10
M T W T F S S
7
10 * 9 * 8 * 7 * 6 * 5 * 4
10 * (10 - 1) * (10 - 2) * (10 - 3) * (10 - 4) * (10 - 5) * (10 - 6)
3
How many 3 digit numbers are there that contain no zeros and no repeated digits?
How many of the above numbers are odd?
1 2 3 4 5 6 7 8 9
9
3
a b c d e f g h i j k l m n o p q r s t u v w x y z
26
5
How many 5 letter words can you form using the alphabets of the English language so that no letter is repeated?
5
How many of those words end with a consonant?
if the problem specifies a constraint or restriction then always start by addressing the restriction first
3
1 2 3 4 5 6 7 8 9
9
a b c d e f g h i j k l m n o p q r s t u v w x y z
26
5
Are we creating a sequence here?
Given a class of 15 students, on how many ways can you form a committee comprising of a president, vice-president, treasurer and secretary?
15
P
VP
T
S
15
P
VP
T
S
President | Vice-President | Treasurer | Secretary |
---|---|---|---|
Jack | Jill | Johnny | Mary |
Jill | Jack | Johnny | Mary |
Mary | Jack | Jill | Johnny |
Mary | Jill | Johnny | Jack |
Order Matters!
The number of ways of filling kkk named or numbered slots using a collection of nnn objects is the same as the number of ways of creating a sequence of k elements such that no object in the sequence can be repeated: n(n−1)(n−2)...(n−k+1)n (n-1) (n-2) ... (n-k+1)n(n−1)(n−2)...(n−k+1)
Making a sequence of n objects from given n objects
1 2 3 4 5 6 7 8 9
n = k = 9
n = 9
k = 9
n(n−1)(n−2)...(n−k+1)
9 * 8 * 7 * 6 * 5 * 4 * 3 * 2 * 1
= 9!
Suppose you haver 9 flower pots that you arrange in a line at the entrance of your house? In how many different ways can you arranges these pots?
The number of sequences of length n that can be formed using n objects so that no object in the sequence is repeated is n!
The number of ways in which n objects can be arranged amongst themselves is n!
The number of permutations of n objects is n!
The number of sequences of kkk objects made from a collection of nnn objects such that no object in the sequence can be repeated is n(n−1)(n−2)...(n−k+1)n (n-1) (n-2) ... (n-k+1)n(n−1)(n−2)...(n−k+1)
n*(n-1)(n-2)\dots(n-k+1)
= \frac{n!}{(n-k)!}
=\frac{n*(n-1)(n-2)\dots(n-k+1)(n-k)(n-k-1)(n-k-2)\dots3*2*1}{(n-k)(n-k-1)(n-k-2)\dots3*2*1}
n = 5+4
k = 9
In how many ways can you arrange the pots so that no two red pots are adjacent to each other?
1 2 3 4 5 1 2 3 4
The subtraction principle
Recap
Always address the restriction first
The number of choices at each step should be independent of the choices made at previous steps
What if you can't do this?
a b c d e f g h i j k l m n o p q r s t u v w x y z
26
How many 3 letter words can you form which contain at least one vowel and no letter is repeated?
3
count(B) = count(A) - count(C)
The number of objects that satisfy some condition is equal to the total number of objects in the collection minus the ones which do not satisfy this condition
A
C
B
a b c d e f g h i j k l m n o p q r s t u v w x y z
26
3
A = set of all 3 letter words with no letter repeated
B = set of all 3 letter words with no letter repeated and at least one vowel
C = set of all 3 letter words with no letter repeated and no vowels
count(A) = 26*25*24
count(C) = 21*20*19
count(B) = 26*25*24 - 21*20*19
a b c d e f g h i j k l m n o p q r s t u v w x y z
26
How many 5 letter words can you form which contain at least two consecutive letters which are the same?
5
APPLE, SHEEP, UTTER, ATTTA, LLLAP
BEARS, RUSTY, DODUD
a b c d e f g h i j k l m n o p q r s t u v w x y z
26
5
A = set of all 5 letter words
B = set of all 5 letter words containing at least two consecutive letters which are same
C = set of all 5 letter words containing no two consecutive letters which are same
count(A) = 26^5
count(C) = 26*25^4
count(C) = 26^5 - 26*25^4
Learning Objectives
What are sequences and how do you count them?
What is the subtraction principle?
(achieved)
Collections
Recap
In a sequence order matters
cat act
even though both words have the same letters: {t, c, a}
\neq
Collections
In a collection order does not matter
cat = cta = act = atc = tac = tca
all the 6 words have the same letters: {t, c, a}
\frac{n!}{(n-k)!}
a b c d e f g h i j k l m n o p q r s t u v w x y z
n = 26
k = 3
How many sequences of 3 letters can you form (no repetition)?
How many collections of 3 letters can you form (no repetition)?
We don't know!
But we know how to count sequences! Can we reuse that knowledge?
Sequences: Breaking it down
a b c d e f g h i j k l m n o p q r s t u v w x y z
26
3
Step 1: select the 3 letters to be put in the word
Step 2: re-arrange the 3 letters in 3! ways
a b c d e f g h i j k l m n o p q r s t u v w x y z
n
k
Step 1: select the k items to be put in the sequence
Step 2: re-arrange the k items in k! ways
Sequences: Breaking it down
Making a collection
Re-arranging elements in the collection
N = number of ways of selecting k elements
k! = number of ways of re-arranging the k terms
Sequences: Breaking it down
Making a collection
Re-arranging elements in the collection
Number of sequences
= N * k!
= \frac{n!}{(n-k)!}
\therefore N = \frac{n!}{(n-k)!k!}
What is the number of ways of selecting 3 vowels from 5 vowels ?
Collections | Sequences |
---|---|
(a,e,i) | {(a,e,i), (a,i,e), (e,a,i), (e,i,a), (i,a,e),(i,e,a)} |
(a,e,o) | {(a,e,o), (a,o,e), (e,a,o), (e,o,a), (o,a,e), (o,e,a)} |
(a,e,u) | {(a,e,u), (a,u,e), (e,a,u), (e,u,a), (u,a,e), (u,e,a)} |
(a,i,o) | {(a,i,o), (a,o,i), (i,a,o), (i,o,a), (o,a,i), (o,i,a)} |
(a,i,u) | {(a,i,u), (a,u,i), (i,a,u), (i,u,a), (u,a,i), (u,i,a)} |
(a,o,u) | {(a,o,u), (a,u,o), (o,a,u), (o,u,a), (u,a,o), (u,o,a)} |
(e,i,o) | {(e,i,o), (e,o,i), (i,e,o), (i,o,e), (o,e,i), (o,i,e)} |
(e,i,u) | {(e,i,u), (e,u,i), (i,e,u), (i,u,e), (u,e,i), (u,i,e)} |
(e,o,u) | {(e,o,u), (e,u,o), (o,e,u), (o,u,e), (u,e,o), (u,o,e)} |
(i,o,u) | {(i,o,u), (i,u,o), (o,i,u), (o,u,i), (u,i,o), (u,o,i)} |
a e i o u
10
60
\frac{5!}{~2!~3!~}
3!
Sequences |
---|
{(a,e,i), (a,i,e), (e,a,i), (e,i,a), (i,a,e),(i,e,a)} |
{(a,e,o), (a,o,e), (e,a,o), (e,o,a), (o,a,e), (o,e,a)} |
{(a,e,u), (a,u,e), (e,a,u), (e,u,a), (u,a,e), (u,e,a)} |
{(a,i,o), (a,o,i), (i,a,o), (i,o,a), (o,a,i), (o,i,a)} |
{(a,i,u), (a,u,i), (i,a,u), (i,u,a), (u,a,i), (u,i,a)} |
{(a,o,u), (a,u,o), (o,a,u), (o,u,a), (u,a,o), (u,o,a)} |
{(e,i,o), (e,o,i), (i,e,o), (i,o,e), (o,e,i), (o,i,e)} |
{(e,i,u), (e,u,i), (i,e,u), (i,u,e), (u,e,i), (u,i,e)} |
{(e,o,u), (e,u,o), (o,e,u), (o,u,e), (u,e,o), (u,o,e)} |
{(i,o,u), (i,u,o), (o,i,u), (o,u,i), (u,i,o), (u,o,i)} |
Sequence or Collection?
15
P
VP
T
S
ABCD |
---|
ABDC |
ACBD |
ACDB |
ADBC |
ADCB |
BACD |
BADC |
BCAD |
BCDA |
BDAC |
BDCA |
CABD |
CADB |
CBAD |
CBDA |
CDAB |
CDBA |
DABC |
---|
DACB |
DBAC |
DBCA |
DCAB |
DCBA |
Given a class of 15 students, in how many ways can you form a committee of 4 members?
All these 4! = 24 sequences are equal in a collection
15
All these 4! = 24 sequences are equal in a collection
ABCD |
---|
ABDC |
ACBD |
ACDB |
ADBC |
ADCB |
BACD |
BADC |
BCAD |
BCDA |
BDAC |
BDCA |
CABD |
CADB |
CBAD |
CBDA |
CDAB |
CDBA |
DABC |
---|
DACB |
DBAC |
DBCA |
DCAB |
DCBA |
\frac{15!}{~~~~~(15-4)!~~~~~~}
\frac{~}{4!}
n \choose k
The number of ways of selecting kkk objects from given nnn objects is and is denoted as n(n−. 1)(n−2)...(n−k+1)n (n-1) (n-2) ... (n-k+1)
\frac{n!}{(n-k)!k!}
Collections
(some examples)
10
Consider 10 people in a meeting. If each person shakes hands with every other person in the room what is the total number of handshakes ?
Consider 10 people in a meeting. If each person shakes hands with every other person in the room what is the total number of handshakes ?
10
2
{10 \choose 2} = 45
You are going on a vacation and your suitcase has space for 3 shirts only? In how many ways can you fill the suitcase?
3
10
You are going on a vacation and your suitcase has space for 3 shirts only? In how many ways can you fill the suitcase?
3
10
You are going on a vacation and your suitcase has space for 3 shirts only? In how many ways can you fill the suitcase?
3
10
{10 \choose 3} = 120
There are 6 points on a 2 - dimensional plane such that no 3 points are collinear. How many segments can you draw from these 6 points?
6
2
{6 \choose 2} = 15
How many triangles can be formed from the vertices of a polygon of n sides?
n = 8
k = 3
{n \choose 3}
Collections
(with repetitions)
Recap
Sequences
without repetitions
with repetitions
Collections
without repetitions
with repetitions
\frac{n!}{(n-k)!}
n^k
\frac{n!}{(n-k)!k!}
?
How many breakfast combos containing 5 items can you form if you are allowed to have multiple servings of the same dish?
5
10
How many breakfast combos containing 5 items can you form if you are allowed to have multiple servings of the same dish?
5
How many breakfast combos containing 5 items can you form if you are allowed to have multiple servings of the same dish?
5
How many breakfast combos containing 5 items can you form if you are allowed to have multiple servings of the same dish?
5
How many breakfast combos containing 5 items can you form if you are allowed to have multiple servings of the same dish?
5
How many breakfast combos containing 5 items can you form if you are allowed to have multiple servings of the same dish?
5
{14 \choose 5}
n original counters
{n+k-1 \choose k}
k-1 magic counters
The number of ways of selecting kkk objects from given nnn objects with repetitions is n(n−. 1)(n−2)...(n−k+1)n (n-1) (n-2) ... (n-k+1)
{n+k-1 \choose k}
(replicate any item which gets selected)
Summary
Sequences
without repetitions
with repetitions
Collections
without repetitions
with repetitions
\frac{n!}{(n-k)!}
n^k
\frac{n!}{(n-k)!k!}
{n+k-1 \choose k}
Collections
(+ multiplication principle)
Given a class of 7 boys and 8 girls, in how many ways can you form a committee of 4 members with 2 boys and 2 girls?
8
7
{8 \choose 2}
{7 \choose 2}
*
batsmen
keepers
pacers
spinners
7
2
4
3
Available
16
5
1
3
2
Select
11
{7 \choose 5}
{2 \choose 1}
{4 \choose 3}
{3 \choose 2}
{7 \choose 5}
{2 \choose 1}
{4 \choose 3}
{3 \choose 2}
*
*
*
Total =
(n−. 1)(n−2)...(n−k+1)n (n-1) (n-2) ... (n-k+1)
m_1 + m_2 + \dots + m_i = n
k_1 + k_2 + \dots + k_i = k
Given:n~items~of~i~different~types
{m_1 \choose k_1} * {m_2 \choose k_2} * \cdots * {m_i \choose k_i}
Form:collection~of~k~items
Collections
(+ subtraction principle)
3 cardiologists
4 diabetologists
2 neurologists
5 gynaecologists
7 general physicians
In how many ways can you form a 4-member committee containing at least one gynaecologist?
(total 21 doctors)
A = all possible committees of 4 members
B = all possible committees containing at least one gynaecologist
C = all possible committees containing no gynaecologist
count(A) = {21 \choose 4}
count(C) = {16 \choose 4}
count(B) = {21 \choose 4} - {16 \choose 4}
3 cardiologists
4 diabetologists
2 neurologists
5 gynaecologists
7 general physicians
(total 21 doctors)
Summary
Multiplication Principle
p*q*r*...
num. of choices at each step should be independent
address constraints first
Subtraction Principle
"at least one"
\frac{n!}{(n-k)!}
n^k
\frac{n!}{(n-k)!k!}
{n+k-1 \choose k}
Sequences
Collections
without repetitions
with repetitions
without repetitions
with repetitions
without repetitions
with repetitions
+ multiplication principle
+ multiplication/subtraction principle
CS6015: Lecture 24
By Mitesh Khapra
CS6015: Lecture 24
Lecture 24: Counting sequences, Subtraction principle
- 1,562