You are on page 1of 24

MATHEMATICS FOR COMPUTING

COCS 223
Faculty of Computing & Information Technology- Rabigh
King Abdelaziz University

Prepared by:
Prof. Dr. Salah El-din Behiry
LECTURE LEARNING OUTCOMES

❖List the counting principles.


❖ Define each of counting principles.
❖ Apply basic counting principles to solve problem.
❖ Analysis problem by using the basic counting principles.
CONTENTS
CHAPTER 1
COMBINATORICS

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.

1.1.1 MULTIPLICATION (PRODUCT RULE)


DEFINITION
❖An event can be broken into a sequence of tasks.
❖It is a multiplication of a couple or several smaller tasks.
If an activity can be constructed in t successive steps and step 1 can be done in n1
ways, step 2 can then be done in n2 ways, ... , and step t can be done in nt ways,
then the number of different possible activities is

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?

2. If I have 4 different t-shirts and 3 different pairs of shorts, how


many different outfits do I have ?
EXAMPLE

How many strings with length seven are probably generated from two
bits (0 and 1)

SOLUTION

Every parts in the string has two ways of selection, which is 0 or 1.


Thus, the selection of a long string with seven can be done by:
2 X 2 X 2 X 2 X 2 X 2 X 2 = 27
1.1.2 ADDITION (SUM RULE)
Definition
It is the number of ways that the task can be performed by “either” n1 or n2
ways, but not both.
Ex.: Let us consider two tasks:
• N1 is the number of ways to do task one.
• N2 is the number of way to do task two.
Note: task are independent of each other. On other world, performing task
one does not accomplish task two and vice versa.

|N1˅ N2 ˅ N3 ˅ ……..˅ Nn | = | N1| + | N2| + …….+ | Nn|


EXAMPLE
I want to take a trip to the beach. I can travel to 1 of 37 international beaches or
one of 14 domestic beaches. How many beach vacation choices do I have?

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

A combination is a selection of k items from a collection of n items in which


order does not matter
Examples
1. Let S= {A,B,C}. Find all 2-combinations.
Relate this to the number of 2-permutations ?
Solution:
AB BA AC CA BC CB
3
C (3,2) = 𝐶2 = 3 ! / [2 ! (3-2) !] = [3 × 2 × 1]/ [ 2 × 1 × 1] = 3

2. In how many ways can you draw 3 cards from a deck.


Solution:
You select 3 from 52 elements without arrangement.
52  52  52!
Hence, C (3,2) = 𝐶3 = 3 =
  3!49!
1.2.3. Partitions
We are given an n element set and nonnegative integers , whose sum is
equal to n. We consider partitions of the set into r disjoint subsets, with the
subset containing exactly elements. Let us count in how many ways this can be
done. We form the subsets one at a time. We have ways of forming the first
subset. Having formed the first subset, we are left with elements. We need to
choose of them in order to form the second subset, and we have Choices,
etc. Using the counting principle for this r stage process, the total number of choices
 n   n − n1   n − n1 − n 2   n − n1 − .... − n r −1  n! n − n1 ! n − n1 − ... − n r −1 !
is  n    .......   = . ..... =
 1  n 2   n 3   nr  n1 !( n − n1 )! n 2 !( n − n1 − n 2 )! n r !( n − n1 − ... − n r )!
n!
n1 !n 2 !....n r !
Examples
How many different words (letter sequences) can be obtained by
rearranging the letters in the word TATTOO?
Solution:
There are six positions to be filled by the available letters. Each
rearrangement corresponds to a partition (T of size 3), (O of size 2)
and (A of size 1). Thus,
6!
The number of words = = 60
3!2!1!
1.3. Principles of inclusion and exclusion
Some counting problems simply do not have a closed form solution. In this section
we discuss an counting tool that also does not give a closed form solution. The
inclusion exclusion principle can been seen as a generalization of the sum rule.
Suppose there are n(A) ways to perform task A and n(B) ways to perform task B,
how many ways are there to perform task A or B, if the methods to perform these
tasks are not distinct? We can cast this as a set cardinality problem. Let X be the
set of ways to perform A, and Y be the set of ways to perform B. Then:

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.

Then n( A) = 50 , n( B) = 20 , n( A  B) = 10 (since this is the number of multiples of 10).

By the inclusion-exclusion principle, we have

50+20-10 = 60 multiples of either 2 or 5.


More generally, for three sets, we have

n( X  Y  Z ) = n( X ) + n(Y ) + n( Z )
− n( X  Y ) − n( X  Z ) − n(Y  Z )
+ n( X  Y  Z )

You might also like