0% found this document useful (0 votes)
12 views14 pages

Counting

Uploaded by

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

Counting

Uploaded by

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

LECTURE # 29

COMBINATORICS

Combinatorics is the mathematics of counting and arranging


objects.

THE SUM RULE

If one event can occur in n1 ways, a second event can occur in n2 (different)
ways, then the total number of ways in which exactly one of the events (i.e.,
first or second) can occur is n1 + n2.
EXAMPLE
Suppose there are 7 different optional courses in Computer Science and 3
different optional courses in Mathematics. Then there are
7 + 3 = 10
choices for a student who wants to take one optional course.

1
EXERCISE

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.

GENERALIZED SUM RULE

If one event can occur in n1 ways,


a second event can occur in n2 ways,
a third event can occur in n3 ways,
……………………………………..
then there are
n1 + n2 + n3 + …
ways in which exactly one of the events can occur.

2
THE PRODUCT RULE
If one event can occur in n1 ways and if for each of these n1 ways, a second
event can occur in n2 ways, then the total number of ways in which both
events occur is n1 · n2.
EXAMPLE

Suppose there are 7 different optional courses in Computer Science and 3


different optional courses in Mathematics. A student who wants to take one
optional course of each subject, there are
7  3 = 21 choices.

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,
(i) Assigning one of the 26 letters: A, B, C, …, Z and
(ii) Assigning one of the 10 digits: 0, 1, 2, …, 9
By product rule, there are
26  10 = 260
different ways that a chair can be labeled by both a letter and a digit.

3
GENERALIZED PRODUCT RULE

If some event can occur in n1 different ways, and if, following this event, a
second event can occur in n2 different ways, and following this second
event, a third event can occur in n3 different ways, …, then the number of
ways all the events can occur in the order indicated is
n 1 · n2 · n3 · …
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 in each set.
If n(Ai) denotes the number of elements in set A i, then
n(A1  A2  … Am) = n (A1) · n(A2) ·… ·n (Am)

EXERCISE

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 the officers.

4
EXERCISE

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.
SOLUTION
(a) 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.

(b) The person will travel from A to B to C to B to A for the


round trip. (A B C B A)
The person can travel 4 ways from A to B and 3 way from B to
C and back.
i.e., 4 A3B 3C 4B A

Thus there are 4 3 3  4 = 144 ways to travel the round trip.

(c) 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. Thus
i.e., 4 A3B 2C B 3 A

Hence there are 4 3 2  3 = 72 ways to travel the round5trip


without using a bus line more than once.
EXERCISE

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
2 2 2 2 = 24 = 16
different bit strings of length four.
EXERCISE

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
1 2 2 2  2 2 2 2 = 27 = 128
different bit strings of length 8 that begin with a 1.
(ii) 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
1 2 2 2 2 2 2 1 = 26 = 64
different bit strings of length 8 that begin and end with a 1.

6
EXERCISE

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.

letters digits

26 ways each 10 ways each

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


26  26  26  10  10  10 = 17,576,000
different license plates possible.

(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.

7
digits
letters

A 0

one way 26 ways each 10 ways each one way

Number of license plates that begin with A and end in 0 are


1  26  26  10  10  1 = 67600

(c) How many license plates begin with PQR


SOLUTION
digits
letters

P Q R

1 way each 10 ways each

Number of license plates that begin with PQR are


1  1  1  10  10  10 = 1000

8
(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 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

(e) How many license plates could begin with AB and have all
three letters and digits distinct.
SOLUTION
digits
letters

A B

one way 24 ways 10 ways 9 ways 8 ways

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 license plates are
1  1  24  10  9  8 = 17280 9
EXERCISE
A variable name in a programming language must be either a letter or a
letter followed by a digit.
How many different variable names are possible?
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.
Finally, by sum rule, there are 26 + 260 = 286 possible variable names in
the programming language.
EXERCISE
(a) How many bit strings consist of from one through four digits?
(b) How many bit strings consist of from five through eight
digits?
SOLUTION
(a) Number of bit strings consisting of 1 digit = 2
Number of bit strings consisting of 2 digits = 2·2 = 22
Number of bit strings consisting of 3 digits = 2·2·2 = 23
Number of bit strings consisting of 4 digits = 2·2·2·2 = 24
Hence by sum rule, the total number of bit strings consisting of one through
four digit is
2+22+23+24 = 2 + 4 + 8 + 16 = 30 10
(b) Number of bit strings of 5 digits = 2 5
Number of bit strings of 6 digits = 2 6
Number of bit strings of 7 digits = 2 7
Number of bit strings of 8 digits = 2 8
Hence, by sum rule, the total number of bit strings consisting of five
through eight digit is
25 + 26 + 27 + 28 = 480

How many three-digit integers are divisible by 5?


SOLUTION
Integers that are divisible by 5, end either in 5 or in 0.
CASE-I (Integers that end in 5)
There are nine choices for the left-most digit (the digits 1 through 9) and
ten choices for the middle digit.
5
(the digits 0 through 9) Hence,
total number of 3 digit integers that
end in 0 is
9 choices one choice
9  10  1 = 90
10 choices
CASE-II (Integer that end in 0)
There are nine choices for the left-most digit 0 and ten
choices for the middle digit
Hence, total number of 3 digit integers 9 choices one choice that
end in 5 is
10 choices
9  10  1 = 90
Finally, by sum rule, the number of 3 digit integers that are divisible by 5 is
11
90 + 90 = 180
EXERCISE

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 = 26
Number of code words of length 2 = 26 2
Number of code words of length 3 = 26 3
Hence, the total number of code words = 26 + 262 + 263
= 18,278

NUMBER OF ITERATIONS OF A NESTED LOOP


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 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. Hence, by product rules the
total number of iterations of inner loop is 4·3=12

12
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
The outer loop is iterated 50 - 5 + 1 = 46 times and during each iteration of
the outer loop there are 20 - 10 + 1 = 11 iterations of the inner loop. Hence
by product rule, the total number of iterations of the inner loop is 46.11 =
506
EXERCISE

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.]
next j
next i

13
SOLUTION
The outer loop is iterated 4 times, but during each
iteration of the outer loop, the inner loop iterates different number of times.
For first iteration of outer loop, inner loop iterates 1 times.
For second iteration of outer loop, inner loop iterates 2 times.
For third iteration of outer loop, inner loop iterates 3 times.
For fourth iteration of outer loop, inner loop iterates 4 times.
Hence, total number of iterations of inner loop = 1 + 2 + 3 + 4 = 10

14

You might also like