0% found this document useful (0 votes)
28 views75 pages

Chapter 6

Uploaded by

soovamsg
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
28 views75 pages

Chapter 6

Uploaded by

soovamsg
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 75

CHAPTER:06, Counting

Suppose that a password on a computer system consists of six, seven, or


eight characters. Each of these characters must be a digit or a letter of
the alphabet. Each password must contain at least one digit. How many
such passwords are there? The techniques needed to answer this
question and a wide variety of other counting problems will be
introduced in this Chapter.

Counting problems arise throughout mathematics and computer


science. For example, we must count the successful outcomes of
experiments and all the possible outcomes of these experiments to
determine probabilities of discrete events. We need to count the
number of operations used by an algorithm to study its time complexity.

FREE: For Complete Playlist: https://www.youtube.com/c/FahadHussaintutorial/playlists


For Code, Slide and Books: https://fahadhussaincs.blogspot.com/
6.1 The Basics of Counting
Basic Counting Principles: The Sum Rule
The Sum Rule: If a task can be done either in
one of n1 ways or in one of n2 ways to do the
second task, where none of the set of n1 ways is
the same as any of the n2 ways, then there are n1
+ n2 ways to do the task.

Sum Rule in terms of sets

|A 𝖴 B|= |A| + |B| as long as A and B are


• The sum rule can be phrased in terms of sets.

disjoint sets.

|A1 𝖴 A2 𝖴 ∙∙∙ 𝖴 Am |= |A1| + |A2| + ∙∙∙ + |Am|


• Or more generally,

FREE: For Complete Playlist: when Ai ∩ Aj = ∅ for all i, j.


https://www.youtube.com/c/FahadHussaintutorial/playlists
For Code, Slide and Books: https://fahadhussaincs.blogspot.com/
Basic Counting Principles: The Sum
Rule
Example:
Suppose there are 7 different optional courses in
Computer Science and 3 different optional
courses in Mathematics. How many ways
student can choose a course.

Solution:
By the sum rule it follows that there are 7 +
3 = 10 choices for a student who wants to take
one optional course.

FREE: For Complete Playlist: https://www.youtube.com/c/FahadHussaintutorial/playlists


For Code, Slide and Books: https://fahadhussaincs.blogspot.com/
Basic Counting Principles: The Sum
Rule
Example: The mathematics department must
choose either a student or a faculty member
as a representative for a university

this representative if there are 37 members


committee. How many choices are there for

of the mathematics faculty and 83


mathematics majors and no one is both a
faculty member and a student.

Solution: By the sum rule it follows that

37 + 83 = 120 possible ways to pick a


there are

representative.
Basic Counting Principles: The Sum
Rule
Example: A student can choose a computer
project from one of the three lists. The three
lists contain 23, 15 and 19 possible projects,
respectively. How many possible projects are
there to choose from?

Solution: The student can choose a project from


the first list in 23 ways, from the second list in
15 ways, and from the third list in 19 ways.
Hence, there are
23 + 15 + 19 = 57 projects to choose from.

FREE: For Complete Playlist: https://www.youtube.com/c/FahadHussaintutorial/playlists


For Code, Slide and Books: https://fahadhussaincs.blogspot.com/
Basic Counting Principles: The Product Rule
The Product Rule: A procedure can be
broken down into a sequence of two tasks. There
are n1 ways to do the first task and n2 ways to do
the second task. Then there are n1∙n2 ways to do
the procedure.
Product Rule in Terms of Sets

⚫ If A1, A2, … , Am are finite sets, then the


number of elements in the Cartesian product
of these sets is the product of the number of
elements of each set.

Cartesian product A1 ⨉ A2 ⨉ ∙∙∙ ⨉ Am is done by


⚫ The task of choosing an element in the

choosing an element in A1, an element in A2 , …,


FREE: and an element in Ahttps://fahadhussaincs.blogspot.com/
m.
For Complete Playlist: https://www.youtube.com/c/FahadHussaintutorial/playlists
For Code, Slide and Books:
The Product Rule
Example: How many ways a student can
choose one optional course each from
computer science and mathematics courses if
there are 7 different optional courses in
Computer Science and 3 different optional
courses in Mathematics.
Solution:
A student who wants to take one optional
course of each subject, there are 7 × 3 = 21
choices.

FREE: For Complete Playlist: https://www.youtube.com/c/FahadHussaintutorial/playlists


For Code, Slide and Books: https://fahadhussaincs.blogspot.com/
The Product Rule
Example: The chairs of an auditorium are to
be labeled with two characters, a letter
followed by a digit. What is the largest
number of chairs that can be labeled
differently?
Solution:
The procedure of labeling a chair consists of
two events, namely,
Assigning one of the 26 letters: A, B, C, …,
Z and Assigning one of the 10 digits: 0,
1, 2, …, 9
By product rule, there are 26 × 10 = 260
FREE: For Complete Playlist: https://www.youtube.com/c/FahadHussaintutorial/playlists
different ways
For Code, Slide thathttps://fahadhussaincs.blogspot.com/
and Books: a chair can be labeled by
The Product Rule
Example: Find the number n of ways that an
organization consisting of 15 members can elect
a president, treasurer, and secretary. (assuming
no person is elected to more than one position)
Solution:
The president can be elected in 15 different ways;
following this, the treasurer can be elected in 14
different ways; and following this, the secretary
can be elected in 13 different ways. Thus, by
product rule, there are
n = 15 × 14 × 13 = 2730
different ways in which the organization can elect
FREE: the officers.
For Complete Playlist: https://www.youtube.com/c/FahadHussaintutorial/playlists
For Code, Slide and Books: https://fahadhussaincs.blogspot.com/
The Product Rule
Example: There are four bus lines between A
and B; and three bus lines between B and C.
Find the number of ways a person can travel:
a) By bus from A to C by way of B;
b) Round trip by bus from A to C by way
of B;
c) Round trip by bus from A to C
by way of B, if the person does not
want to use a bus line more than once.

FREE: For Complete Playlist: https://www.youtube.com/c/FahadHussaintutorial/playlists


For Code, Slide and Books: https://fahadhussaincs.blogspot.com/
The Product Rule
a) By bus from A to C by
way of B; Solution:

There are 4 ways to go from A to B and 3 ways


to go from B to C; hence there are 4 × 3 =
12 ways to go from A to C by way of B.

FREE: For Complete Playlist: https://www.youtube.com/c/FahadHussaintutorial/playlists


For Code, Slide and Books: https://fahadhussaincs.blogspot.com/
The Product Rule
b) Round trip by bus from A to C by way of B;
Solution:
The person will travel from A to B to C to B to
A for the round trip. i.e. (A →B →C →B →A)

The person can travel 4 ways from A to B


and 3 way from B to C and back.
Thus there are 4 ×3 ×3 × 4 =
144 ways to travel the round trip.

FREE: For Complete Playlist: https://www.youtube.com/c/FahadHussaintutorial/playlists


For Code, Slide and Books: https://fahadhussaincs.blogspot.com/
The Product Rule
c) Round trip by bus from A to C
by way of B, if the person does
not want to use a bus line more than once.
Solution:

The person can travel 4 ways from A to B and 3


ways from B to C, but only 2 ways from C to
B and 3 ways from B to A, since bus line
cannot be used more than once. Hence there
are
4 ×3 ×2 × 3 = 72 ways
FREE: For Complete Playlist: https://www.youtube.com/c/FahadHussaintutorial/playlists
to travelFor Code,the round
Slide and Books: trip without using a bus line
https://fahadhussaincs.blogspot.com/
The Product Rule
Example: A bit string is a sequence of 0’s and
1’s.How many bit string are there of length 4?

Solution:
Each bit (binary digit) is either 0 or 1.
Hence, there are 2 ways to choose each bit. Since
we have to choose four bits therefore,

the product rule shows, there are a total


of different bit strings of
length four.

FREE: For Complete Playlist: https://www.youtube.com/c/FahadHussaintutorial/playlists


For Code, Slide and Books: https://fahadhussaincs.blogspot.com/
The Product Rule
Example: How many bit strings of
length 8: (i ) begin with a 1?
(ii) begin and end with a 1?
Solution:
(i) If the first bit (left most bit) is a 1, then it
can be filled in only one way. Each of the
remaining seven positions in the bit string
can be filled in 2 ways (i.e., either by 0 or 1).
Hence, there are

FREE:different bit
For Complete Playlist: strings of length 8 that begin with
https://www.youtube.com/c/FahadHussaintutorial/playlists
For Code, Slide and Books: https://fahadhussaincs.blogspot.com/
The Product Rule
(ii) begin and end with a 1?
Solution:
If the first and last bit in an 8 bit string is a 1,
then only the intermediate six bits can be filled
in 2 ways, i.e. by a 0 or 1.
Hence there are

different bit strings of length 8 that begin and


end with a 1.

FREE: For Complete Playlist: https://www.youtube.com/c/FahadHussaintutorial/playlists


For Code, Slide and Books: https://fahadhussaincs.blogspot.com/
The Product Rule
Example: Suppose that an automobile
license plate has three letters followed by
three digits.
(a) How many different license plates are possible?
Solution:
Each of the three letters can be written in 26
different ways, and each of the three digits can
be written in 10 different ways.

Hence, by the product rule, there is a total of


26 × 26 × 26 × 10 × 10 × 10 = 17,576,000
different License plates
FREE: For Complete Playlist: possible.
https://www.youtube.com/c/FahadHussaintutorial/playlists
For Code, Slide and Books: https://fahadhussaincs.blogspot.com/
The Product Rule
(b) How many license plates could begin with A and
end on 0?
Solution:
The first and last place can be filled in one way
only, while each of second and third place can be
filled in 26 ways and each of fourth and fifth place
can be filled in 10 ways.

Number of license plates that begin with A and


end in 0 are
1 × 26 × 26 × 10 × 10 × 1 =
FREE: For Complete Playlist: 67600
https://www.youtube.com/c/FahadHussaintutorial/playlists
For Code, Slide and Books: https://fahadhussaincs.blogspot.com/
The Product Rule
(c) How many license plates begin
with PQR.
Solution:

Number of license plates that begin with PQR


are
1 × 1 × 1 × 10 × 10 × 10 =
1000 ways.
FREE: For Complete Playlist: https://www.youtube.com/c/FahadHussaintutorial/playlists
For Code, Slide and Books: https://fahadhussaincs.blogspot.com/
The Product Rule
(d) How many license plates are possible in
which all the letters and digits are distinct?
Solution:
The first letter place can be filled in 26 ways.
Since, the second letter place should contain a
different letter than the first, so it can be filled in
25 ways. Similarly, the third letter place can be
filled in 24 ways. And the digits can be
respectively filled in 10, 9, and 8 ways.
Hence;
number of license plates in which all the
letters and digits are distinct are
26 × 25 × 24 × 10 × 9 × 8 = 11,
232, 000
FREE: For Complete Playlist: https://www.youtube.com/c/FahadHussaintutorial/playlists
For Code, Slide and Books: https://fahadhussaincs.blogspot.com/
The Product Rule
(e) How many license plates could begin with have
AB and all
three letters and digits distinct.
Solution:

The first two letters places are fixed (to be filled with
A and B), so there is only one way to fill them. The
third letter place should contain a letter different
from A & B, so there
are 24 ways to fill it.
The three digit positions can be filled in 10 and 8
ways to have distinct digits. Hence, desired number
of For
FREE: license plates are
Complete Playlist: https://www.youtube.com/c/FahadHussaintutorial/playlists
For Code, Slide and Books:
1https://fahadhussaincs.blogspot.com/
× 1 × 24 × 10 × 9 × 8 =
Telephone Numbering Plan
telephone number consists of 10 digits,
Example: The North American numbering plan (NANP)
specifies that a
consisting of a three-digit area code, a three-digit office code,
and a four-digit station code. There are some restrictions on the

Let X denote a digit from 0 through 9.


digits.

Let N denote a digit from 2 through 9.


Let Y denote a digit that is 0 or 1.


In the old plan (in use in the 1960s) the format was NYX-NNX-


XXXX.
⚫ In the new plan, the format is NXX-NXX-XXXX.
How many different telephone numbers are possible under the
old plan and the new plan?

⚫ There are 8 ∙2 ∙10 = 160 area codes with the format NYX.
Solution: Use the Product Rule.

⚫ There are 8 ∙10 ∙10 = 800 area codes with the format NXX.
⚫ There are 8 ∙8 ∙10 = 640 office codes with the format NNX.
⚫There are 10 ∙10 ∙10 ∙10 = 10,000 station codes with the format
XXXX. Number of old plan telephone numbers: 160 ∙640
∙10,000 = 1,024,000,000. Number of new plan telephone
NUMBER OF ITERATIONS OF A NESTED LOOP
Example: Determine how many
times when
iterate the the following
inner algorithm
loop willbe
is implemented
d and run For i: = 1 to 4
For j : = 1 to 3
[Statement in body of inner loop. None contain
branching statements that lead out of the inner loop.]
next j
next i
Solution:
The outer loop is iterated four times, and during
each iteration of
the outer loop, there are three iterations of the
inner loop.
Example: Determine how many times the inner
loop will be iterated when the following
algorithm is implemented and run.
for i = 5 to 50
for j: = 10 to 20
[Statement in body of inner loop. None contain
branching statements that lead out of the inner
loop.]
next
j
next
i
Solution:
Example: Determine how many times the inner
loop will be iterated when the following algorithm is
implemented and run.
for i: = 1 to 4
for j: = 1 to i
[Statements in body of inner loop. None contain
branching statements that lead outside the loop.]
n
ext j

next
i
Solu
tion:
The outer loop is iterated 4 times, but during each
iteration of the outer loop, the inner loop iterates
Combining the Sum and Product Rule
Example: Suppose statement labels in a
programming language can be either a single
letter or a letter followed by a digit. Find the
number of possible labels.
Solution:
⚫ First consider variable names one character in
length. Since such names consist of a single
letter, there are 26 variable names of length 1.
⚫ Next, consider variable names two characters
in length. Since the first character is a letter,
there are 26 ways to choose it. The second
character is a digit, there are 10 ways to choose
it. Hence, to construct variable name of two
characters in length, there are 26×10 = 260
ways.
Combining the Sum and Product Rule
Example: A computer access code word consists
of from one to three letters of English alphabets
with repetitions allowed. How many different
code words are possible.
Solution:
Number of code words of length 1
= 261 Number of code words of
length 2 = 262 Number of code
words of length 3 = 263 Hence,
the total number of code words =
26 1+ 262 +

263= 18,278
FREE: For Complete Playlist: https://www.youtube.com/c/FahadHussaintutorial/playlists
For Code, Slide and Books: https://fahadhussaincs.blogspot.com/
Counting Passwords
⚫ Combining the sum and product rule allows us to solve more complex
problems.
Example: Each user on a computer system has a password,
which is six to eight characters long, where each character is
an uppercase letter or a digit. Each password must contain at
least one digit. How many possible passwords are there?
Solution: Let P be the total number of passwords, and let
P6, P7, and P8
be the passwords of length 6, 7, and 8.
⚫ By the sum rule P = P6 + P7 +P8.
Finding P6 directly is difficult. To find P6 it is easier to find the
number of strings of uppercase letters and digits that are six
characters long, including those with no digits, and subtract

of six characters is 366 ,and the


from this the number of strings with no digits. By the product

digits is 266
rule,
FREE: the number
For Complete Playlist: of strings
https://www.youtube.com/c/FahadHussaintutorial/playlists
number For of strings
Code, Slide andwith
Books: no https://fahadhussaincs.blogspot.com/
Counting Passwords(Continued)
⚫ To find each of P6, P7, and P8 , we find the
number of passwords of the specified length
composed of letters and digits and subtract the
number composed only of letters. We find that:
⚫ P6 = 366 − 266 = 2,176,782,336 − 308,915,776
=1,867,866,560.
⚫ P7 = 367 − 267 = 78,364,164,096 − 8,031,810,176 =
70,332,353,920.
⚫ P8 = 368 − 268 = 2,821,109,907,456 − 208,827,064,576
=2,612,282,842,880.
⚫ Consequently, P = P6 + P7 + P8 = 2,684,483,063,360.
FREE: For Complete Playlist: https://www.youtube.com/c/FahadHussaintutorial/playlists
For Code, Slide and Books: https://fahadhussaincs.blogspot.com/
Basic Counting Principles: Subtraction Rule
Subtraction Rule: If a task can be done
either in one of n1 ways or in one of n2

the task is n1 + n2 minus the number of ways


ways, then the total number of ways to do

to do the task that are common to the


two different ways.
⚫ Also known as, the principle of inclusion-
exclusion:

FREE: For Complete Playlist: https://www.youtube.com/c/FahadHussaintutorial/playlists


For Code, Slide and Books: https://fahadhussaincs.blogspot.com/
Counting Bit Strings
eight start either with a 1 bit or end with
Example: How many bit strings of length

the two bits 00?


Solution: Use the subtraction rule.
⚫ Number of bit strings of

1 bit: 27 = 128
length eight that start with a

⚫ Number of bit strings of

00: 26 = 64
length eight that end with bits

⚫ Number of bit strings of

that start with a 1 bit and end


length eight

with bits 00 :
FREE: For Complete Playlist: https://www.youtube.com/c/FahadHussaintutorial/playlists
For Code, Slide and Books: https://fahadhussaincs.blogspot.com/
Counting Functions
Counting Functions: How many functions are
there from a
set with m elements to a set with n elements?
Solution: Since a function represents a choice of
one of the n elements of the codomain for each of

us that there are n ∙ n ∙ ∙ ∙ n = nm such functions.


the m elements in the domain, the product rule tells

Counting One-to-One Functions: How many one-


to-one functions are there from a set with m
elements to one with n elements?
Solution: Suppose the elements in the
domain are a1, a2,…, am. There are n ways to
choose the value of a1 and n−1 ways to choose a2,

(n−2)∙∙∙(n−m +1) such functions.


etc. The product rule tells us that there are n(n−1)
FREE: For Complete Playlist: https://www.youtube.com/c/FahadHussaintutorial/playlists
For Code, Slide and Books: https://fahadhussaincs.blogspot.com/
Tree Diagrams
⚫ Tree Diagrams: We can solve many counting
problems through the use of tree diagrams,
where a branch represents a possible choice
and the leaves represent possible outcomes.
⚫ Example: Suppose that “I Love Discrete Math”
T-shirts come in five different sizes: S,M,L,XL,
and XXL. Each size comes in four colors (white,
red, green, and black), except XL, which comes
only in red, green, and black, and XXL, which
comes only in green and black. What is the
minimum number of shirts that the campus
book store needs to stock to have one of each
size and color available?
FREE: For Complete Playlist: https://www.youtube.com/c/FahadHussaintutorial/playlists
For Code, Slide and Books: https://fahadhussaincs.blogspot.com/
Tree Diagrams
⚫ Solution: Draw the tree
diagram.

⚫ The store must stock 17 T-


shirts.
6.2 The Pigeonhole
Principle
integer and k + 1 objects are placed into k
Pigeonhole Principle: If k is a positive

boxes, then at least one box contains two or


more objects.

Proof: We use a proof by contraposition.


Suppose none of the k boxes has more than
one object. Then the total number of
objects would be at most k. This

1 objects.
contradicts the statement that we have k +

FREE: For Complete Playlist: https://www.youtube.com/c/FahadHussaintutorial/playlists


For Code, Slide and Books: https://fahadhussaincs.blogspot.com/
The Pigeonhole Principle
⚫ If a flock of 20 pigeons roosts in a set of
19 pigeonholes, one of the pigeonholes
must have more than 1 pigeon.

FREE: For Complete Playlist: https://www.youtube.com/c/FahadHussaintutorial/playlists


For Code, Slide and Books: https://fahadhussaincs.blogspot.com/
The Pigeonhole Principle
Corollary 1: A function f from a set
with k +1
elements to a set with k elements is not one-
to-one.
Proof: Use the pigeonhole principle.
⚫ Create a box for each element y in the
codomain of f .
⚫ Put in the box for y all of the elements x
from the
domain such that f(x) = y.
⚫ Because there are k + 1 elements and only k
boxes, at least one box has two or more
FREE: For Complete Playlist: https://www.youtube.com/c/FahadHussaintutorial/playlists
elements.
For Code, Slide and Books: https://fahadhussaincs.blogspot.com/
The Generalized Pigeonhole Principle
The Generalized Pigeonhole Principle:

is at least one box containing at least ⌈N/k⌉


If N objects are placed into k boxes, then there
objects.

Proof: We use a proof by contraposition.


than ⌈N/k⌉ − 1 objects.
Suppose that none of the boxes contains more
Then the total number of objects is at most

where the inequality ⌈N/k⌉ < ⌈N/k⌉ + 1 has been


used. This is a contradiction because there are a
total of n objects.
FREE: For Complete Playlist: https://www.youtube.com/c/FahadHussaintutorial/playlists
For Code, Slide and Books: https://fahadhussaincs.blogspot.com/
Pigeonhole Principle
Example: Among any group of 367 people,

birthday, because there are only 366 possible


there must be at least two with the same

birthdays. ⌈367/366⌉ = 2

Example: Among 100 people there are

⌈100/12⌉ = 9 who were born in the same


at least

month.

Example: In any set of 27 English , must be at


least two that begin with the same letter,
FREE:
since there
For Complete Playlist:
are 26https://fahadhussaincs.blogspot.com/
letters in the English
https://www.youtube.com/c/FahadHussaintutorial/playlists
For Code, Slide and Books:
Pigeonhole Principle

FREE: For Complete Playlist: https://www.youtube.com/c/FahadHussaintutorial/playlists


For Code, Slide and Books: https://fahadhussaincs.blogspot.com/
The Generalized Pigeonhole Principle
Example: What is the minimum number of students
required in a Discrete Mathematics class to be sure
that at least six will receive the same grade, if there
are five possible grades, A, B, C, D, and F.

Solution:
The minimum number of students needed to

same grade is the smallest integer N such that ⌈ N/K


guarantee that at least six students receive the

⌉ = ⌈ N/5 ⌉ = 6. The smallest such integer is


N = K(⌈ N/K ⌉-1)+1 = 5(6-1)+1=5 ⋅ 5 + 1 = 26.
Thus 26 is the minimum number of students needed
to be sure that at least 6 students will receive the
same
FREE: grades.
For Complete Playlist: https://www.youtube.com/c/FahadHussaintutorial/playlists
For Code, Slide and Books: https://fahadhussaincs.blogspot.com/
The Generalized Pigeonhole Principle

FREE: For Complete Playlist: https://www.youtube.com/c/FahadHussaintutorial/playlists


For Code, Slide and Books: https://fahadhussaincs.blogspot.com/
The Generalized Pigeonhole Principle

FREE: For Complete Playlist: https://www.youtube.com/c/FahadHussaintutorial/playlists


For Code, Slide and Books: https://fahadhussaincs.blogspot.com/
6.3 Permutations and
Combinations
Permutations
Definition: A permutation of a set of distinct
objects is an ordered arrangement of these
objects. An ordered arrangement of r elements of
a set is called an r-permutation.

Example: Let S = {1,2,3}.


⚫ The ordered arrangement 3,1,2 is a permutation of S.
⚫ The ordered arrangement 3,2 is a 2-permutation of S.

⚫ The number of r-permutations of a set


with n

⚫ The 2-permutations of S = {1,2,3} are 1,2; 1,3;


elements is denoted by P(n,r).

FREE: 2,1; 2,3;Playlist:


3,1;Forand
Code,3,2. Hence, P(3,2) = 6.
For Complete https://www.youtube.com/c/FahadHussaintutorial/playlists
Slide and Books: https://fahadhussaincs.blogspot.com/
A Formula for the Number of Permutations
Theorem 1: If n is a positive integer and r is an

1 ≤ r ≤ n, then there are


integer with

P(n, r) = n(n − 1)(n − 2) ∙∙∙ (n − r + 1)


r-permutations of a set with n distinct elements.

Proof: Use the product rule. The first element can


be chosen in n

ways. The second in n − 1 ways, and so on


until there are
(n − ( r − 1)) ways to choose the last element.
⚫ Note that P(n,0) = 1, since there is only one

Corollary 1: If n and r are integers with 1 ≤ r


way to order zero elements.

≤For
FREE: n,Complete
thenPlaylist: https://www.youtube.com/c/FahadHussaintutorial/playlists
For Code, Slide and Books: https://fahadhussaincs.blogspot.com/
Solving Counting Problems by
Counting Permutations

Example: How many ways are there to

winner, and a third-prize winner from 100


select a first- prize winner, a second prize

different people who have entered a


contest?

P(100,3) = 100 ∙ 99 ∙ 98 = 970,200


Solution:

FREE: For Complete Playlist: https://www.youtube.com/c/FahadHussaintutorial/playlists


For Code, Slide and Books: https://fahadhussaincs.blogspot.com/
Solving Counting Problems by
Counting Permutations (continued)
⚫ Example: Suppose that there are eight runners in a
race. The winner receives a gold medal, the second
place finisher receives a silver medal, and the third-
place finisher receives a bronze medal. How many
different ways are there to award these medals, if all
possible outcomes of the race can occur and there
are no ties?

⚫ Solution: The number of different ways to award the


medals is the number of 3-permutations of a set
with eight elements. Hence, there are
P(8, 3) = 8 · 7 · 6 = 336
possible ways to award the medals.
FREE: For Complete Playlist: https://www.youtube.com/c/FahadHussaintutorial/playlists
For Code, Slide and Books: https://fahadhussaincs.blogspot.com/
Solving Counting Problems by
Counting Permutations (continued)
Example: Suppose that a saleswoman has to visit
eight different cities. She must begin her trip in
a specified city, but she can visit the other seven
cities in any order she wishes. How many
possible orders can the saleswoman use when
visiting these cities?

Solution: The first city is chosen, and the rest

P(7,7)= 7! = 7 ∙ 6 ∙ 5 ∙ 4 ∙ 3 ∙ 2 ∙ 1 = 5040
are ordered arbitrarily. Hence the orders are:

If she wants to find the tour with the shortest


path that visits all the cities, she must consider
5040 paths!
FREE: For Complete Playlist: https://www.youtube.com/c/FahadHussaintutorial/playlists
For Code, Slide and Books: https://fahadhussaincs.blogspot.com/
Solving Counting Problems by
Counting Permutations (continued)

Example: How many permutations of the


letters
ABCDEFGH contain the string ABC ?

Solution: We solve this problem by


counting the permutations of six objects,
ABC, D, E, F, G, and H.

P(6,6)= 6! = 6 ∙ 5 ∙ 4 ∙ 3 ∙ 2 ∙ 1 = 720

FREE: For Complete Playlist: https://www.youtube.com/c/FahadHussaintutorial/playlists


For Code, Slide and Books: https://fahadhussaincs.blogspot.com/
Combinations
Definition: An r-combination of elements
of a set is an unordered selection of r
elements from the set.
Thus, an r-combination is simply a subset
of the set with r elements.
⚫ The number of r-combinations of a set with n
distinct elements is denoted by C(n, r).

⚫ The notation is also used and is called a


binomial coefficient. (We will see the

Section. 6.4)
notation again in the binomial theorem in
FREE: For Complete Playlist: https://www.youtube.com/c/FahadHussaintutorial/playlists
For Code, Slide and Books: https://fahadhussaincs.blogspot.com/
Combinations
Example:
⚫ Let S be the set {a, b, c, d}. Then {a, c, d} is a 3- combination
from S. It is the same as {d, c, a} since the order listed does not
matter.
⚫ C(4,2) = 6 because the 2-combinations of {a, b, c, d} are the
six subsets {a, b}, {a, c}, {a, d}, {b, c}, {b, d}, and {c, d}.

Theorem 2: The number of r-combinations


of a set with n elements, where n ≥ r ≥ 0,
equals

Proof: By the product rule P(n, r) =


C(n,r) ∙ P(r,r). Therefore,

FREE: For Complete Playlist: https://www.youtube.com/c/FahadHussaintutorial/playlists


For Code, Slide and Books: https://fahadhussaincs.blogspot.com/
Combinations

Theorem 2: The number of r-combinations


of a set with n elements, where n ≥ r ≥ 0,
equals

Proof: By the product rule P(n, r) =


C(n,r) ∙ P(r,r). Therefore,

FREE: For Complete Playlist: https://www.youtube.com/c/FahadHussaintutorial/playlists


For Code, Slide and Books: https://fahadhussaincs.blogspot.com/
Combinations
can be dealt from a standard deck of 52 cards?
Example: How many poker hands of five cards

Also, how many ways are there to select 47


cards from a deck of 52 cards?
Solution: Since the order in which the cards
are dealt does not matter, the number of five
card hands is:

⚫ The different ways to select 47 cards


from 52 is

result. →
This is a special case of a general

FREE: For Complete Playlist: https://www.youtube.com/c/FahadHussaintutorial/playlists


For Code, Slide and Books: https://fahadhussaincs.blogspot.com/
Combinations
Corollary 2: Let n and r be nonnegative

r ≤ n. Then C(n, r) = C(n, n − r).


integers with

Proof: From Theorem 2, it follows that

and

Hence, C(n, r) = C(n, n − r).

manipulation. →
This result can be proved without using algebraic

FREE: For Complete Playlist: https://www.youtube.com/c/FahadHussaintutorial/playlists


For Code, Slide and Books: https://fahadhussaincs.blogspot.com/
Combinatorial Proofs
⚫ Definition 1: A combinatorial proof of an
identity is a proof that uses one of the
following methods.

⚫A double counting proof uses counting


arguments to prove that both sides of an
identity count the same objects, but in
different ways.
⚫ A bijective proof shows that there is a bijection
between the sets of objects counted by the two
sides of the identity.

FREE: For Complete Playlist: https://www.youtube.com/c/FahadHussaintutorial/playlists


For Code, Slide and Books: https://fahadhussaincs.blogspot.com/
Combinatorial Proofs
Proof: We will use a bijective proof to show that C(n, r) = C(n, n − r) for all
integers n and r with 0 ≤ r ≤ n. Suppose that S is a set with n elements. The
function that maps a subset A of S to A` is a bijection between subsets of S
with r elements and subsets with n − r elements (as the reader should verify).

The identity C(n, r) = C(n, n − r) follows because when there is a bijection


between two finite sets, the two sets must have the same number of
elements. Alternatively, we can reformulate this argument as a double
counting proof.

By definition, the number of subsets of S with r elements equals C(n, r). But
each subset A of S is also determined by specifying which elements are not in
A, and so are in A`. Because the complement of a subset of S with r elements
has n − r elements, there are also C(n, n − r) subsets of S with r elements. It
follows that C(n, r) = C(n, n − r).

FREE: For Complete Playlist: https://www.youtube.com/c/FahadHussaintutorial/playlists


For Code, Slide and Books: https://fahadhussaincs.blogspot.com/
Combinations
players from a 10-member tennis team to make a
Example: How many ways are there to select five

Solution: By Theorem 2, the number of


trip to a match at another school.

combinations is

Example: A group of 30 people have been trained


as astronauts to go on the first mission to Mars.
How many ways are there to select a crew of six
people to go on this mission?
Solution: By Theorem 2, the number of possible
crews is

FREE: For Complete Playlist: https://www.youtube.com/c/FahadHussaintutorial/playlists


For Code, Slide and Books: https://fahadhussaincs.blogspot.com/
6.4 Binomial Coefficients and
Identities
Binomial Theorem: Let x and y be
variables, and n a nonnegative integer.
Then:

Proof: We use combinatorial reasoning . The


terms in the expansion of (x + y)n are of the

j = 0,1,2,…,n. To form the term


form xn−jyj for
xn−jyj, it
is necessary to choose n−j xs from
the n sums. Therefore, the coefficient of
xn−jyj is which equals .

FREE: For Complete Playlist: https://www.youtube.com/c/FahadHussaintutorial/playlists


For Code, Slide and Books: https://fahadhussaincs.blogspot.com/
Powers of Binomial Expressions
Definition: A binomial expression is the sum of two terms,
such as x + y. (More generally, these terms can be products
of constants and variables.)
⚫ We can use counting principles to find the coefficients in the
expansion of (x +
y)n where n is a positive integer.

expanding (x + y)3.
⚫ To illustrate this idea, we first look at the process of

⚫ (x + y) (x + y) (x + y) expands into a sum of terms that are


the product of a term

⚫ Terms of the form x3, x2y, x y2, y3 arise. The question is what
from each of the three sums.

are the coefficients?


⚫ To obtain x3 , an x must be chosen from each of the sums. There is
only one way to do this. So, the coefficient of x3 is 1.
⚫ To obtain x2y, an x must be chosen from two of the sums and a y
from the other.
There are ways to do this and so the coefficient of x2y
is 3.
⚫ To obtain xy2, an x must be chosen from of the sums and a y from
the other two . There are ways to do this and so the coefficient
2
Using the Binomial Theorem
Example:

FREE: For Complete Playlist: https://www.youtube.com/c/FahadHussaintutorial/playlists


For Code, Slide and Books: https://fahadhussaincs.blogspot.com/
Using the Binomial Theorem

FREE: For Complete Playlist: https://www.youtube.com/c/FahadHussaintutorial/playlists


For Code, Slide and Books: https://fahadhussaincs.blogspot.com/
Using the Binomial Theorem

x12y13 in the expansion of (2x − 3y)25?


Example: What is the coefficient of

Solution: We view the expression as (2x +


(−3y))25. By the binomial theorem

Consequently, the coefficient of x12y13 in the


expansion is obtained when j = 13.

FREE: For Complete Playlist: https://www.youtube.com/c/FahadHussaintutorial/playlists


For Code, Slide and Books: https://fahadhussaincs.blogspot.com/
A Useful Identity
Corollary 1: With n ≥0,

Proof (using binomial theorem): With x = 1 and y = 1,


from the
binomial theorem we see that:

Proof (combinatorial): Consider the subsets of a set


with n elements. There are subsets with zero
elements, with one element, with two elements, …,
and with n elements.
Therefore the total is

Since, we know that a set with n elements has 2n


subsets, we conclude:
Blaise
Pascal

1662)
(1623-

Pascal’s Identity
≥ k ≥ 0, then
Pascal’s Identity: If n and k are integers with n

1, a ∊T, and
Proof (combinatorial): Let T be a set where |T| = n +

S = T − {a}. There are subsets of T


⚫ contains a with k − 1 other elements, or
containing k elements. Each of these subsets either:

subsets of k elements that contain a, since


⚫ contains k elements of S and not a.

of arek − 1
there
There
⚫ are
subsetsofofS,k elements of T that do not contain a,
⚫ elements
subsets

because there
are
Henc subsets of k elements of S.
e, 19
See Exercise

for an
Pascal’s Triangle
The nth row
in the
triangle
consists of
the binomial
coefficients

, k = 0,1,
….,n.

By Pascal’s identity, adding two adjacent bionomial coefficients


results is the binomial coefficient in the next row between
these two coefficients.
Other Identities Involving
Binomial Coefficients
We conclude this section with combinatorial proofs of two
of the many identities enjoyed by the binomial coefficients.

Remark: This identity was discovered by mathematician


Alexandre-Théophile Vandermonde in the eighteenth
century.

FREE: For Complete Playlist: https://www.youtube.com/c/FahadHussaintutorial/playlists


For Code, Slide and Books: https://fahadhussaincs.blogspot.com/
Other Identities Involving
Binomial Coefficients

Corollary 4 follows from Vandermonde’s identity,


Lets understand this!

FREE: For Complete Playlist: https://www.youtube.com/c/FahadHussaintutorial/playlists


For Code, Slide and Books: https://fahadhussaincs.blogspot.com/
Other Identities Involving
Binomial Coefficients
COROLLARY 4

FREE: For Complete Playlist: https://www.youtube.com/c/FahadHussaintutorial/playlists


For Code, Slide and Books: https://fahadhussaincs.blogspot.com/
6.5 Generalized Permutations and
Combinations

FREE: For Complete Playlist: https://www.youtube.com/c/FahadHussaintutorial/playlists


For Code, Slide and Books: https://fahadhussaincs.blogspot.com/
6.5 Generalized Permutations and
Combinations
Combinations with Repetition

FREE: For Complete Playlist: https://www.youtube.com/c/FahadHussaintutorial/playlists


For Code, Slide and Books: https://fahadhussaincs.blogspot.com/
6.5 Generalized Permutations and
Combinations
Combinations with Repetition

FREE: For Complete Playlist: https://www.youtube.com/c/FahadHussaintutorial/playlists


For Code, Slide and Books: https://fahadhussaincs.blogspot.com/
6.5 Generalized Permutations and
Combinations
Combinations with Repetition

FREE: For Complete Playlist: https://www.youtube.com/c/FahadHussaintutorial/playlists


For Code, Slide and Books: https://fahadhussaincs.blogspot.com/
6.5 Generalized Permutations and
Combinations

FREE: For Complete Playlist: https://www.youtube.com/c/FahadHussaintutorial/playlists


For Code, Slide and Books: https://fahadhussaincs.blogspot.com/
6.5 Generalized Permutations and
Combinations

FREE: For Complete Playlist: https://www.youtube.com/c/FahadHussaintutorial/playlists


For Code, Slide and Books: https://fahadhussaincs.blogspot.com/
6.5 Generalized Permutations and
Combinations
Permutations with Indistinguishable Objects
Some elements may be indistinguishable in counting problems. When this is the case,
care must be taken to avoid counting things more than once.

FREE: For Complete Playlist: https://www.youtube.com/c/FahadHussaintutorial/playlists


For Code, Slide and Books: https://fahadhussaincs.blogspot.com/

You might also like