Elementary Cou - Principle
Elementary Cou - Principle
Ayele B
20/02/2011
Example:
In version of the computer language BASIC the name of the
variable is a string of one or two alpha numeric character more
over the variable name must begin with a letter and must be
different from the 5 strings of two characters that are reserved for
programming use. how many variable name are there in the version
of BASIC?
Example:
Each users in a computer system has a password which is 6 to 8
characters long where each character is an upper case letter or a
digit. Each password must contain at least one digit. how many
possible passwords are there?
Example:- How many integers are there between 0 and 1000 that
have one or more 6’s as digits?
Exercise:- how many odd integers are there between 100 and 1000.
Ayele B Elementary Counting Technique
5
3. The inclusion -Exclusion principle
when two tasks A and B can be done at the same time we can not
use sum rule to count the number of ways to do one of the tasks,
so the number of ways to do one of the two tasks obtained by
adding the number of ways to do each tasks and then subtract the
number of ways to do both tasks.
i.e |A ∪ B| = |A| + |B| − |A ∩ B|
Example: How many bit string of length 8 either starts with the
1’s or ends with the two zeros?
Example: A discrete mathematics class contains 25 students
majoring in CS, 13 in maths and 8 in both. how many students are
in this class if every student is majoring in maths, CS or both?
Generalized Inclusion-Exclusion Principle
Let A1 , A2 , ..., An be finite
P sets, then P
|A1 ∪ A2 ∪ ... ∪ An | = 1≤i≤n |Ai | − 1≤i≤j≤n |Ai ∩ Aj | +
n+1 |A ∩ A ∩ ... ∩ A |
P
1≤i≤j≤k≤n |Ai ∩ Aj ∩ Ak | − ... + (−1) 1 2 n
Example:
1.Find the least number of cables required to connect eight
computers to four printers to guarantee that forevery choice of four
of the eight computers, these four computers can directly access
four different printers.
2.Find the minimum number of students needed to guarantee that
5 of them belong to the same class (freshman, sophomore, junior,
senior)?
Excercise:
1.Find the minimum number of elements that one need to take
from the set S = {1, 2, 3, ..., 8} to be sure that two of the number
add up to 9?
2.Find the least number of cables required to connect 100
computers to 20 printers to guarantee that forevery choice of 20 of
the 100 computers, these 20 computers can directly access 20
different printers.
Ayele B Elementary Counting Technique
1.3 Permutations and Combinations
1.Permutation
Permutation of a set of distinct objects is an ordered arrangement
of these objects.
an ordered arrangement of r-objects of a set is called an
r-permutation
Example: Let S = {1, 2, 3}
The arrangement {3, 1, 2} is a 3-permutation of S.
The arrangement {3, 2} is a 2-permutation of S.
Theorem: The number of r-permutations of a set with n-distinct
element is
nP = n × n − 1 × ... × (n − r + 1) = n!
r (n−r )!
Proof:
There are n - ways to choose the first element
There are n − 1 - ways to choose the second element
...
There are n − r + 1 ways to choose the r th element
so by PR there are n × n − 1 × ... × (n − r + 1) r-permutation
Ayele B Elementary Counting Technique
10
Example:
1. Suppose there are 8 runners in a race. how many different ways
are there to award the gold, silver and bronze medal if all possible
outcomes of the race can occur?
2. How many ways can a president, vice-president and secretary be
selected from a committee of seven people?
3. Suppose that a sales women has to visit eight different cities
she must begin her trip in a specific city, but she can visit the
other in any order she wishes. How many possible orders can the
sales women use when visiting these cities?
Permutations with repetitions:
n!
P(n; n1 , n2 , ..., nr = ) the number of permutations of
n1 !n2 !...nr !
n-objects of which n1 are alike, n2 are alike, ..., nr are
alike(indistinguishable)
Example: Find the number m of seven letter word that can be
formed using the letter of the word ”BENZENE”
Ayele B Elementary Counting Technique
11
Ordered sample:
Choose one element after another r-times we call the choice an
ordered sample of size r.
1.Sample with replacement:
n × n × ... × n = nr , choose r objects from n objects when
repetition allowed.
1.Sample without replacement:
nP = n!
r (n−r )! choose r objects from n objects when repetition
allowed.
Example:
three cards are chosen one after the other from 52-card deck. Find
the number m of ways this can be done.
a)with replacement
b)without replacement
Combination:
An r-combination of elements of a set is an unordered collection of
r-elements from a set
Example: C (4, 2) = 6 since 2-cobination of {a, b, c, d} are the six
subsets {a, b} , {a, c}, {a, d}, {b, c}, {b, d}, {c, d}
Theorem: The number of r-combination of a set with n-elements,
where r , n ∈ Z + and 0 ≤ r ≤ n equals
C (n, r ) = nr = nCr = r !(n−rn!
)! some times called binomial
coefficient
Proof:
P(n, r ) = C (n, r ) × P(r , r )
n!
P(n, r ) (n − r )! n!
C (n, r ) = = =
P(r , r ) r! r !(n − r )!
(r − r )!
Example:
1. Suppose that a cookie shop has four different kinds of cookies.
How many different ways can six cookies be chosen? Assume that
only the type of cookies and not the individual cookies or the order
in which they are chosen matters
2. How many solutions does the equation x1 + x2 + x3 = 11 have
where x1 , x2 and x3 are non-negative integers?
3. How many ways cay you solve k1 + k2 + k3 + k4 = 18 provided
that k1 , k2 , k3 , k4 are integers and k1 , k2 ≥ 0, k3 ≥ 3k4 ≥ 2?
Type Repetition Allowed Formula
n!
r-permutation No
(n − r )!
n!
r-combination No
r !(n − r )!
r-permutation Yes nr
r-combination Yes C (n + r − 1, r )
Note:
1.Distributing n identical objects in to k distinct sets is
C (n + k − 1, k − 1)
2.The number of ways n-distinct elements can be assigneed to n
celles so that exactly one cell is empty is n!C (n, 2)
Example: A data set contains 500 observation. Analysis of the
data is carried out by three programs that together processes the
500 observations such that each program processes at least 100
observations. If the partition of the 500 observations for use by the
three programs is done by arbitrarily choosing the observation for
each program, In how many ways can the data be procesed?
Example: The number of ways 5 elements a, b, c, d, e can be
assigned to three celles so that exactly 1 cell is empty.
Generating Permutation
Any set with n - elements can be placed in 1 − 1
correspondence with the set {1, 2, 3, ..., n}
We can list the permutations of any set of n-elements by
generating the permutations of the n - smallest positive
integers and replace this integers with the corresponding
elements.
For n - elements we have n! permutations.
We use lexicographic (dictionary) ordering of the set of
permutation of {1, 2, 3, ..., n}.
In this ordering the permutation a1 , a2 , a3 , ..., an precedes
b1 , b2 , b3 , ..., bn if for some k 1 ≤ k ≤ n where
a1 = b1 , a2 = b2 , a3 = b3 , ..., ak−1 = bk−1 and ak < bk .
Example: Order the permutations of 3 and 4 elements?
Example:
1. Find the next largest 4-combination of the set {1, 2, 3, ..., 6}
after {1, 2, 5, 6}
2. Find all the 3-combination of the set {1, 2, 3, 4, 5}
3. Find the next largest 5-combination out of a set {1, 2, 3, ..., 7}
in lexicographic order after {1, 5, 2, 6, 7}
1 1
0 1
2 2 2
0 1 2
3 3 3 3
0 1 2 3
4 4 4 4 4
0 1 2 3 4
5 5 5 5 5 5
0 1 2 3 4 5
Ayele B
Elementary
Counting Technique
17
n = 0: 1
n = 1: 1 1
n = 2: 1 2 1
n = 3: 1 3 3 1
n = 4: 1 4 6 4 1
Theorem 8: Let n ≥ r ≥ 0, then
Row sum: C (n, 0) + C (n, 1) + ... + C (n, n) = 2n
Column sum: C (r , r ) + C (r + 1, r ) + ... + C (n, r ) = C (n + 1, r + 1)
Diagonal sum:
C (n, 0) + C (n + 1, 1) + ... + C (n + r , r ) = C (n + r + 1, r )
Example: prove the following identity
1. 1 + 2 + 3 + ... + n = n(n+1)
2
2. 12 + 22 + 32 + ... + n2 = (2n+1)n(n+1)
6
which is equal to = x 4 + 4x 3 y + 6x 2 y 2 + 4x 1 y 1 + y 4
Example:
What is the coefficients of x 12 y 13 in the expression
1 2
a) (x + y )25 b) (2x − 3y )25 c)(− x − y )25 (exercise)
2 3