Professional Documents
Culture Documents
COCS 223
Faculty of Computing & Information Technology- Rabigh
King Abdelaziz University
Prepared by:
Prof. Dr. Salah El-din Behiry
LECTURE LEARNING OUTCOMES
CHAPTER 2
DISCRETE PROBABILITY
CHAPTER 3
GRAPHS AND TREES
CHAPTER 4
MODELING COMPUTATION
CHAPTER 1
COMBINATORICS
1.1 THE COUNTING PRINCIPLE
The calculation of probabilities often involves counting the number of
outcomes in the probability trial and any subset of its results.
n1 x n2 x ... x nt
EXAMPLE
An elementary school teacher, teaching students in grade 4, grade 5 & grade 6. If
the number of students in grade 4 is 25 people & the number of students in grade 5
is 27 people & the number of students in grade 6 is 20.
If teachers want to select 3 students from their students, where a student from each
class, how many ways to select the student composition from three students?
SOLUTION
The number of students:
• in grade 4 = 25
• in grade 5 = 27
• in grade 6 = 20
Then the number of ways that the teachers have to choose the composition of the
three students is
25 x 27 x 20 =13,500 ways
Tree Diagram
It is a visual strategy to list all possible outcome of an event in an organized
manner which can facilitate the calculation of the final outcome of an event.
IN-ACTIVITY CLASS
1. If a woman has 1 skirt & 3 different pairs of shoes, how many different
outfits does she have?
How many strings with length seven are probably generated from two
bits (0 and 1)
SOLUTION
SOLUTION
REMEMBER
“either” n1 or n2 ways, but not both.
37 + 14 = 518
EXAMPLES
1. A telephone number is a 7-digit sequence, but the first digit has to be
different from 0 or 1. How many distinct telephone numbers are there?
2. Compute the number of the outcomes if we first roll a die then toss a coin?
SOLUTION
Q1:
We have a total of 7 stages, and a choice of one out of 10 elements at each stage,
except for the first stage where we only have 8 choices.
Therefore, the answer is No.=
Q2:
Number of outcomes = 6 . 2 = 12
1.2. Permutation and Combination
Factorial Notation
If n is a positive integer , n factorial denoted by n !
Is a product of all positive integers less than or equal to n . It is defined by
n ! = n(n-1)(n-2)…….(2)(1)
EX: The expression 6 × 5 × 4 × 3 × 2 × 1 = can be written as 6!, which is read as
“six factorial.”
As a special case: 0 ! = 1 ! = 1
In general, n! is the product of all the counting numbers beginning with n and
counting backwards to 1. We define 0! to be 1.
Factorial Example
5! = 5 × 4 × 3 × 2 × 1= 120
8 ! / 6 ! = 8 × 7 × 6 ! / 6 ! = 8 × 7 = 56
n! / (n-2) != n(n-1)(n-2) !/ (n-2) != n(n-1)
n+3 ! = 5 n+2 ! = (n+3) (n+2) ! = 5 (n+2) !
Note:
(n-2) ! Find the value of n , n should be bigger or equal to 2
(3-n) ) ! Find the value of n , n should be smaller or equal to 3
The common number will be 2 or 3
1.2.1. Permutation
We start with n distinct objects, and let k be some positive integer, with .
We wish to count the number of different ways that we can pick k out of these
n objects and arrange them in a sequence. By the counting principle, the
number of possible sequences, called k permutations,
k
k
k
permutation
In the special case where k = n , the number of possible sequences,
simply called permutations, is
n ( n − 1) .........3.2.1 = n !
k k k
k k
k
Properties of permutation
A permutation is an order arrangement of distinct objects
• Order matters
• Repetition is not allowed. (different elements)
Examples
1. What is the number of words that consist of four distinct letters?
Solution:
This is the problem of counting the number of 4 permutations of the 26 letters in the
26!
alphabet. Then, No. of words =P 4
26
= = 358800
22!
2. What is the number of ways that we can select two letters from a 4
different letters in the box ?
Solution :
4!
Then, No. of ways = 𝑃24 = = 12
2!
1.2.2. Combinations
Forming a combination is different than forming a permutation, because in a
combination there is no ordering of the selected elements. Hence, the number
of possible combination of k out of n objects is equal to
n n!
n
= k =
k !( n − k )!
Ck
Properties of Combinations
X Y = X + Y − X Y
Note:
If a task can be done in either one of n1 ways or one of n2 ways, then the total
number of ways to do the task is n1 + n2 minus the number of ways that are common
to the two different ways.
It’s a principle of inclusion – exclusion
Example
In a discrete mathematics class every student is a major in computer science or
mathematics, or both. The number of student having computer science as a major
(possibly along with mathematics) is 25. The number of student having
mathematics as a major (possibly along with computer science ) is 13. And the
number of student majoring in both computer science and mathematics is 8.
How many student are in this classes ?
Solution:
X Y = X + Y − X Y
= 25 + 13 - 8 = 30
Example.
How many positive integers ≤ 100 are multiples of either 2 or 5?
Solution:
let A be the set of multiples of 2 and B be the set of multiples of 5.
n( X Y Z ) = n( X ) + n(Y ) + n( Z )
− n( X Y ) − n( X Z ) − n(Y Z )
+ n( X Y Z )