psau.edu.sa...8 2.2.12 Maximal and minimal elements: 68 2.2.13 The greater element and the least...
Transcript of psau.edu.sa...8 2.2.12 Maximal and minimal elements: 68 2.2.13 The greater element and the least...
1
.
+
DISCRETE MATHEMATICS AND ITS APPLICATIONS
FOR COMPUTER SCIENCE
DR. AWATIF MOHAMMED ALI ELSIDDIEG
SALMAN BIN ABDULAZIZ UNIVERSITY
FACULTY OF SCIENCE AND HUMANITY STUDIES
HOTAT BANI TAMIM
2014
111
100
111
001
010
101
011
110
2
Dedecated to:
my family , my
mother and friends
3
List of symbols
symbol meaning
¬ p Negation of p
p˄ q Conjunction of p and q
P ˅ q Disjunction of p and q
p ⊕ 풒 Exclusive of p and q
p→ q The implication of p and q
p↔ q Biconditional of p and q
P ≡ q Equivalence of p and q
T Tautology
F Contradiction
P(풙ퟏ, 풙ퟐ , 풙ퟑ, … , 풙풏) Propositional function
∀풙 p(풙) Universal quantification of 풑(풙)
∃풙 풑(풙) Existential quantification of 풑(풙)
풙 ∈ 푺 풙 is a member of 푺
풙 ∉ 푺 풙 is not a member of 푺
ℕ Set of natural numbers
ℤ Set of integers
4
ℤ Set of positive integers
ℚ Set of rational numbers
퓡 Set of real numbers
S=T Set equality
∅ The empty set (or null set)
|S| Cardinality of S
P(S) The power set of S
(a,b) Ordered pair
푺 ⊆ 푻 S is a subset of T
푺 ⊂ 푻 S is a proper subset of T
푨 × 푩 Cartisian product of A and B
푨 ∪ 푩 Union of A and B
푨 − 푩 The difference of A and b
푨 Complement of A
풂 ≡ 풃(풎풐풅 풎) 풂 is congruent to 풃 풎풐풅풖풍풖 풎
a| b 풂 divides 풃
풂 ∤ 풃 풂 풏풐풕 풅풊풗풊풅풆풔 풃
풂 div b Quotient when 풂 풊풔 풅풊풗풊풔풂풃풍풆 풃풚풃
풇(풂) Value of the function 풇 at 풂
5
풇: 푨→ B Function of A and B
풇ퟏ + 풇ퟐ Sum of the functions 풇ퟏ풂풏풅 풇ퟐ
풇ퟏ. 풇ퟐ Product of the functions 풇ퟏ 풂풏풅풇ퟐ
풇°품 Composite of 풇 and 품
gcd(a,b) Greatest common divisor of a and b
Lcm(a,b) Least common multiple of a and b
(풂풌풂풌 ퟏ … 풂ퟏ풂ퟎ)풃 Base b representation
푨 ∨ 푩 Join of A and B
푨˄ b The meet of A and B
푨 ⊙ 푩 Boolean product of A and B
풏! 풏 factorial
C(a,b) Combination of a and b
P(a,b) Permutation of a and b
풊ퟏퟎ
풊 ퟎ
The sum of i from 0 to 10
6
Contents Introduction: 12
Chapter 1 (Logic and Proofs) 13
1.1 Logic: 13
1.1.1 Propositions : 13
1.1 2 Compound propositions: 14
1.1.3 Biconditionals: 16
1.1.4 Logic and Bit Operations : 17
Exercises: 19
1.1.5 Logical Equivalence: 20
1.2 Introduction to Proofs : 21
Introduction : 21
1.2.1 Direct Proofs : 21
1.2.2 Indirect Proofs: 22
1.2.3 Proofs by Contradiction: 23
Exercises: 24
1.2.4 Mathematical Induction: 25
Exercises: 28
Chapter 2
Basic Structures( sets ,Relations and functions)
29
2.1 1 Sets: 29
7
2.1.2 The Power Set: 32
2.1.3 Cartesian Products: 33
2.1.4 Sets Operations: 34
2.1.5 Sets Identities: 37
2.1.6 Computer Representation of Sets: 40
Exercises: 41
2.2. Relations: 42
2.2.1 Relations and their properties: 42
2.2.2 Relations on a set: 43
2 .2. 3 Properties of relations: 44
2.2.4 Combining relations: 47
Exercises: 49
2.2.5 Representing relations using matrices: 50
2.2.6 The matrix for the composite relations: 53
2.2.7 Representing Relations Using Diagraphs: 54
Exercises: 57
2.2.8 Equivalence relations: 58
2.2.9 Equivalence classes: 60
Exercices: 64
2.2.10 Partial ordering: 65
2.2.11 Hasse diagrams: 66
8
2.2.12 Maximal and minimal elements: 68
2.2.13 The greater element and the least element: 68
2.2.14 Lattices: 72
Exercises: 73
2.3 Functions : 74
2.3.1 One-to-one and Onto functions : 77
2.3.2 Inverse functions and compositions of functions : 80
2.3.3 Some important functions: 81
Exercises: 85
Chapter 3
Algorithms ,Integers and Matrices
85
3.1 Algorithms: 85
3.2 Number theory: 87
3.2.1 The integers and division: 87
3.2.2 The division algorithm: 88
3.3 Modular Arithmetic: 89
3.4 Primes and greater common divisor primes: 90
3.5 The Greatest common divisor and the least common multiple: 91
Exercises: 93
3.6 Integers and algorithms: 94
3.6.1 Representation of integers: 94
9
3.6.2 Base conversion: 95
3.6.3 Algorithms for integers operations: 98
3.6.4 The Euclidean algorithm: 101
Exercises: 102
Chapter 4 (Boolean Algebra) 105
4.1.1 Boolean Functions: 105
4.1.2 Boolean Expressions and Boolean Functions: 106
4.1.3 Identities of Boolean algebra: 109
4.2 Duality : 110
4.3 The abstract definition of a Boolean algebra: 111
4.4 Representing Boolean Functions: 111
4.5 Logic Gates: 113
4.6 Combinations of Gates: 115
4.7 Minimization of Circuits: 115
4.8 Karnaugh Maps: 115
Exercises: 117
Chapter 5
An Introduction to Graph Theory
119
5.1 Basic Terminology: 120
5.2 Some special simple graphs: 122
5.3 Bipartite graphs: 123
10
5.4 Representing Graphs and Graph Isomorphism: 125
5.5 Adjacency matrices: 126
5.6 Incidence Matrices: 128
5.7 Isomorphism of Graphs: 129
Exercises: 131
5.8.1 Paths: 132
5.8.2 Connectedness in undirected graphs: 133
5.8.3 Connectedness in directed graphs: 135
5.8.4 Counting path between vertices: 136
5.9.1 Euler and Hamilton Paths: 138
5.9.2 Hamilton Paths and Circuits: 139
5.10 Planar Graphs: 141
Exercises: 143
Chapter 6 (Counting) 145
6.1 Basic Counting Principles: 145
6.2 The sum rule: 145
Exercises: 146
6.3 The Pigeonhole Principle: 147
6.4 Sequences and Summations: 148
6.4.1 Sequences: 148
6.4.2 Summations: 150
11
Exercises: 152
6. 5 Discrete Probability: 154
6.5.1 Random variables and sample Spaces : 154
Exercises: 157
6.6 Permutations and Combinations: 158
6.6.1 Permutations: 158
6.6.2 Combinations: 159
6.7 The Binomial Theorem: 160
6.8 Pascal’s triangle: 165
6.8. 1 Recurrence relations: 165
6.8. 2 Inhomogenious Requrrence Relations : 170
6.8.3 Another method of solving inhomogenous recurrence relations: 172
6.8.4 A formula for Fibonaci numbers : 174
Exercises: 175
References: 177
12
Discrete Mathematics
Introduction
What is discrete mathematics?
Discrete mathematics is the part of mathematics denoted to the
study of discrete objects.
Why We Study Discrete Mathematics?
There are several important reasons for studying discrete
mathematics. First, through this course you can develop your
mathematical maturity: that is, your ability to understand and
create mathematical arguments. You will not get very far in your
studies in the mathematical sciences without these skills.
Second, discrete mathematics is the gate-way to more advanced
courses in all parts of the mathematical sciences. Discrete
mathematics provides the mathematical foundations for many
computer science courses including data structures, algorithms,
database theory, automata theory, formal languages, compiler
theory, computer security and operating systems students find these
courses much more difficult when they have not had the appropriate
mathematical foundations from discrete mathematics.
13
Chapter 1
Logic and Proofs
1.1 Logic:
1.1.1 Propositions:
Def. (1):
A proposition is a declarative sentence (declares a fact) that is
either true or false, but not both.
Example (1): All the following declarative sentences are
propositions
1. Toronto is the capital of Canada.
2. 1 + 1 = 2
3. 2 + 2 = 3
Propositions 1 and 2 are true but 3 is false.
Example (2): Consider the following sentences:
1. What time it is?
2. Read this carefully
3. x + 1 = 2
4. x + y = z
Sentences 1 and 2 are not propositions because they are not
declarative sentences. Sentences 3 and 4 are not propositions because
they are neither true nor false.
Def. (2) : Let p be a proposition. The negation of p denoted by
pp is the statement "It is not the case that p ".
p is read "not p " the truth value of negation of p , p is the
opposite of the truth value of .
Example (3): Find the negation of the proposition:
Today is Friday
14
Solution: Today is not Friday.
Example (4): Find he negation of the proposition
"At least 10 inches of rain fell today in Mekka"
Solution: "Less than 10 inches of rain fell today in Mekka".
1.1.2 Compound Propositons:
Def. (3) : Let p and q be propositions.
The conjunction of p and q denoted by qp is the proposition
"p and q".
The conjunction qp is true when both p and q are true and
false otherwise.
The truth table for the conjunction of two propositions:
p q qp
T
T
F
F
T
F
T
F
T
F
F
F
Def. (4): let p and q be propositions. The disjunction of p and q
denoted by qp , is the proposition "p or q". The disjunction qp
is false when both p and q are false and is true otherwise.
The table for the disjunction of two propositions:
p q qp
T
T
F
F
T
F
T
F
T
T
T
F
15
Def. (5): Let p and q be propositions. The exclusive OR of p
and q denoted by qp , is the proposition that is true when exactly
one of p and q is true and false otherwise.
The truth table for the exclusive or of two propositions:
p q qp
T
T
F
F
T
F
T
F
F
T
T
F
Def. (6): Let p and q be propositions. The conditional
statement qp is the proposition "if p, then q". the conditional
statement qp is false when p is true and q is false, and true
otherwise. In the conditional statement qp , p is called the
hypothesis and q is called the conclusion.
The truth value for the condition statement:
p q qp
T
T
F
F
T
F
T
F
T
F
T
T
The following ways express the conditional statement:
"if p then q "p implies q"
"if p, q "p only if q"
'p is sufficient for q" "a sufficient condition for q is p"
"q if p" "q whenever p"
"q when p" "q is necessary for p"
"a necessary condition for p is q"
"q unless p" "q follows from p"
16
Example (7): Let p be the statement "Maha learns discrete
mathematics" and q the statement Maha will find a good job"
express the statements qp as a statement.
Solution:
If "Maha learns discrete mathematics then she will find a good
job" or "Maha will find a good job when she learns discrete
mathematics" or "for Maha to get a good job, it is sufficient for her
to learn discrete mathematics".
1.1.2 Compound propositions:
The proposition pq is called the converse of qp , the
contrapositive of qp is the proposition pq . The proposition
qp is called the inverse of qp .
Example (8):
What are the contrapositive, the converse, and the inverse of the
conditional statement "The home team wins whenever it is raining".
Solution:
Because " p whenever q" is one of the ways to express the
conditional statement qp , the original statement can be written as
"If it is raining, then the home team wins".
The contrapositive of the conditional statement is "If the home
team does not win, then it is not raining".
The converse is : "If the home team wins, then it is raining"
The inverse is : "If it is not raining, then the home team does not
win".
1.1.3 Biconditionals:
Def. (7): Let p and q be propositions. The biconditional
statement qp is the proposition "p if and only if q". the
biconditional statement qp is true when p and q have the same
17
truth values, and it is false otherwise biconditional statements are
called bi-implications.
The truth table for the biconditional qp
p q qp
T
T
F
F
T
F
T
F
T
F
F
T
Some other common ways to express qp
"p is necessary and sufficient for q"
"If p then q, and conversely"
"p iff q"
So qqqpqp
Example (10):
Construct the truth table of the compound proposition
qpqp
Solution:
P q q qp qp qpqp
T
T
F
F
T
F
T
F
F
T
F
T
T
T
F
T
T
F
F
F
T
F
T
F
1.1.4 Logic and Bit Operations:
Def. (8):
A bit string is a sequence of zero or more bits. The length of
this string is the number of bits in the strings.
18
Example (11):
101010011 is a bit string of length nine.
The table for the Bit operators OR,AND and XOR:
x y yx yx yx
0
0
1
1
0
1
0
1
0
1
1
1
0
0
0
1
0
1
1
0
Truth value Bit
T
F
1
0
Example (12):
Find the bitwise OR, bit wise AND and bitwise XOR of the bit
strings 01 1011 0110 and 11 0001 1101
Solution:
01 1011 0110
11 0001 1101
11 1011 1111 bit wise OR
01 0001 0100 bit wise AND
10 1010 1011 bitwise XOR
19
Exercises:
1) Which of these sentences are propositions? What are the
truth values of those that are propositions?
(a) London is the capital of America
(b) 2 + 3 = 5
(c) x + 2 = 11
(d) 5 + 7 = 10
(e) Answer this question?
2) What is the negation of each of these propositions
(a) Today is Thursday
(b) 2 + 1 = 3
(c) The summer in Khartoum is hot and sunny.
3) Construct a truth table for each of these compound
propositions:
(a) qp (b) qp (c) ppqp
(d) qpqp (e) qpqp
4) Construct a truth table for each of these compound
propositions:
(a) rqp (b) rqp (c) rpqp
(d) rpqp
5) Find the bitwise OR, bitwise AND and bitwise XOR of each
of these pairs of bit strings:
(a) 101 1110 , 010 001
(b) 111 0000 , 1010 1010
(c) 00 0111 0001 , 10 0100 1000
(d) 11 1111 1111 , 00 0000 0000
6) Evaluate each of these expressions
(a) 1 1000˄ (11011 1 1011)
20
(b) (0 1111 1 010) 0 1000
(c) (0 1010 11011) 0 1000
Def.(9):
A Compound proposition that always true is called a tautology,
a compound proposition that is always false is called a contradiction
and a compound proposition that neither a tautology nor
contradiction is called contingency.
Examples of a tautology and a contradiction
p p pp pp
T
F
F
T
T
T
F
F
1.1.5 Logical Equivalence:
Def.(10):
The compound propositions p and q are called logically
equivalent if qp is a tautology. The notation qp denotes that p
and q are logically equivalent.
Example (13):
Show that qp and qp are logically equivalent
Solution:
p q qp qp p q qp
T
T
F
F
T
F
T
F
T
T
T
F
F
F
F
T
F
F
T
T
F
T
F
T
F
F
F
T
Example (14):
Show that qp is logically equivalent to qp
21
Solution:
P q p qp qp
T
T
F
F
T
F
T
F
F
F
T
T
T
F
T
T
T
F
T
T
Example (15):
Show that qpqp is a tautology
P q qp qp qpqp
T
T
F
F
T
F
T
F
T
F
F
F
T
T
T
F
T
T
T
T
1.2 Introduction to Proofs:
Introduction :
In this section we introduce the notation of a proof and describe
methods for constructing proofs. A proof is a valid argument that
establishes the truth of a mathematical statement.
1.2.1 Direct Proofs:
Def(11).: A direct proof of a conditional statement qp is
constructed when the first step is the assumption that p is true;
subsequent steps are constructed using rules of inference with the
final step showing that q must also be true.
Def(12).: The integer n is even if there exists an integer such that
n = 2k and n is odd if there exists an integer k such that
n = 2k + 1.
22
Example (16):
Give a direct proof of the theorem "If n is an odd integer, then
n2 is odd"
Solution:
This theorem states nqnpn where np is "n is an odd
integer" and nq is "n2 is odd",
assume that n is odd Z,12 kkn
22 12 kn
144 22 kkn
1222 2 kk 2n is odd
1.2.2 Indirect Proofs: (Proof by contraposition)
pqqp . This means that the conditional statement
qp can be proved by showing that its contrapositive pq is
true.
Example (17):
Prove that if n is an integer and 3n + 2 is odd, then n is odd.
Solution:
qp means if 3n + 2 is odd, then n is odd its contrapositive
pq that is n is even implies 3n + 2 is even.
Assume that n is even Z,2 kkn
kn 233
22323 kn
26 k
132 k
23 n is even
23
If 23 n is odd, then n is odd.
1.2.3 Proof by Contradiction:
The proof by contradiction does not prove a result directly.
Example (18): Prove that 2 is irrational by giving a proof by
contradiction.
Solution: Let p be the proposition " 2 is irrational" suppose
that p is true.
Suppose 2 is rational
ba 2 where a and b have no common
factors
22
2 ba
222 ab 2a is an even integer
a is an even integer
cca ,2 Z 22 42 cb
22 2cb 2b is an even integer
b is an even integer
This contradicts a and b have no common factor
hence 2 is irrational
Example (19): Give a proof by contradiction of the theorem "if
23 n is odd, then n is odd".
Solution: pqqp
Let p be " 23 n is odd" and q be "n is odd".
24
To construct a proof by contradiction assume that both p and
q` are true
23 n is odd and n is not odd
n is even
kkn ,2 Z
kn 233
22333 kn
26 k
)13(2 k
23 n is even
This contradict our assumption that 23 n is odd,
hence n is odd .
Exercises:
1) Use a direct proof to show that the sum of two odd integers is
even.
2) Use a direct proof to show that the sum of two even integers
is even.
3) Use a proof by contradiction to prove that the sum of an
irrational number and a rational number is irrational.
4) Show that if n is an integer and 풏ퟑ + ퟓ 풊풔 풐풅풅 ,
then n is even using :
a) A proof by contraposition.
b) A proof by contradiction .
5) Prove that if n is an integer and 3n+2 is even , then n is even
using :
a) A proof by contraposition.
b) A proof by contradiction.
25
6) Show that these statements about the integer x are
equivalent;
(i) 3x +5 is even .
(ii) x+5 is odd.
(iii) 풙ퟐ is even.
1.2.4 Mathematical Induction:
Introduction:
In general, mathematical induction can be used to prove
statements that assert that )(np is true for all positive integers n ,
where )(np is a propositional function. A proof by mathematical
induction has two parts, a basis step, where we show that )1(p is true
and inductive step, where we show that for all positive integers k , if
)(kp is true, then )1( kp is true.
Example (1):
Show that if n is a positive integer, then 2
)1(.....21 nnn
Solution:
Let )(np be the proposition that the sum of the first n positive
integers is 2
)1( nn .
Basis step: )1(p is true because 2
)11(1 .
inductive step )(kp holds.
Inductive step:
Assume that 2
)1(.....21
kkk is true ----- (1)
we must show that :
2)2)(1(
21)1)(1()1(.....21 kkkkkk is also true? -----(2)
26
Add )1( k to both sides of equation (1)
2)2)(1(
2)1(2)1()1(
2)1()1(.....21
kkkkkkkkkk
is equal to both sides of equation(2)
Hence )1( kp is true
)(np is true INn .
Example (2):
Use mathematical induction to show that
122...221 12 nn INn
Solution:
Let )(np be the proposition that 122...21 1 nn .
Basis step: )0(p is true because 1122 10 INn
Inductive step: for the inductive hypothesis, we assume that
)(kp is true. That is, we assume that
122...21 1 kk -----(1) is true
To carry out the inductive step using this assumption we must
show that when we assume that )(kp is true, then )1( kp is also true.
That is, we must show that:
121222...21 21)1(1 kkkk -----(2) is true. ????
assuming the inductive hypothesis )(kp is true. Under the
assumption of )(kp , add 12 k to both sides of equation (1)
1212 22...22122...221 kkkk
1212.2
212
2
1
11
k
k
kk
Is equal to both sides of equation (2)
)1( kp is true
Hence )(np is true INn
27
Example(3):
Use mathematical induction to prove
INnn n 2
Solution:
Let )(np be the proposition that
Basis step: )1(p is true, because 221 1
Inductive step: Assume that )(kp is true INn
i.e kk 2 ----(1)
To complete the inductive step, we need to show that if )(kp is
true, then )1( kp = 121 kk is true ----(2)???
We add 1 to both sides of inequality (1) 122.222121 kkkkkk is equal to both sides
of inequality (2)
hence )1( kp is true
)(np is true INn
Example (4):
Use mathematical induction to prove that
4!2 nnn
Solution :
Let )(np be the propositional that !2 nn
Basis step: )4(p is true because 24!41624
Inductive step: Assume that )(kp is true
4!2 kkk
We must show that under this hypothesis )1( kp is also true
)!1(2 1 kk ?
We have kk 2.22 1 (by definition of exponent)
28
!.2 k (by inductive hypothesis)
!)1( kk (because 12 k )
)!1( k (by definition of factorial function)
This shows that )1( kp is true when )(kp is true.
Exercises:
1) Prove that ∀풏 ∈ ℤ
ퟏ. ퟐ + ퟐ. ퟑ + ⋯ + 풏(풏 + ퟏ) = 풏(풏 ퟏ)(풏 ퟐ)ퟑ
2) Let 풑(풏) be the statement that 풏! < 풏풏 where 풏 > 1
a) What is 풑(ퟐ)? b) Show that 풑(ퟐ)
3) Prove that ퟑ풏 < 푛!, ∀푛 > 6
4) Prove that ퟐ풏 > 풏ퟐ, ∀풏 > 4
5) Prove that ퟏퟐ + ퟑퟐ + ퟓퟐ + ⋯ + (ퟐ풏 + ퟏ) = (풏 ퟏ)(ퟐ풏 ퟏ)(ퟐ풏 ퟑ)ퟑ
6) Let 풑(풏) be the statement that ퟏퟐ + ퟐퟐ + 풏ퟐ = 풏(풏 ퟏ)(ퟐ풏 ퟏ)ퟔ
,∀풏 ∈ ℤ
7) Let 풑(풏) be the statement that ퟏퟑ + ퟐퟑ + 풏ퟑ = 풏(풏 ퟏ)ퟐ
ퟐ ,
∀풏 ∈ ℤ
a) What is the statement 풑(ퟏ)?
b) Show that 풑(ퟏ) is true.
29
Chapter 2
Basic Structures
1) Sets
2) Relations
3) Functions
2.1 Sets :
Def. (1): A set is a collction of an unordered of objects.
Def. (2): The objects in a set are called the elements, or
members, of the set. A set is said to contain its elements.
We write Aa to denote a is an element of the set A. the
notation Aa denotes that a is not an element of the set A. We use
a notation where all members of the set are listed between braces {a,
b, c, d} represent the set with four elements a, b, c and d.
Example (1):
1) The set V of all vowels in the English alphabet can be written
as V = {a, e, i, o, u}
2) The set O of odd +ve integers less than 10 can be represented
by O = {1, 3, 5, 7, 9}
3) The set of +ve integers less than 100 can be denoted by {1, 2,
…., 99}
Another way to describe a set is to use set builder notation. We
characterize all those elements in the set by stating the property or
properties they must have to be members.
e.g., the set O of all odd +ve integers less than 10 can be written
as
O = { x | x is an odd positive integer < 10}
O = { Zx | x is odd and x < 10}
Q+ = { x | qpx / , for some +ve in legers p and q}
30
is the set of all +ve rational numbers
IN = {0, 1, 2, 3, ….} the set of natural numbers.
Z = {…, -1, -1, 0, 1, 2, …} the set of integers
Z + = {1, 2, 3, …} the set of +ve integers
Q = {p/q | p ,qZ, q 0} the set of rational numbers
IR, the set of real numbers.
Def (3).
Two sets are equal if and only if they have the same elements.
Example (2):
The set {1, 2, 3} and {3, 2, 1} are equal because they have the
same elements. Note that the order in which the elements of a set are
listed does not matter.
Sets can be represented graphically using Venn diagrams. In
Venn diagrams the universal set U which contains all the objects
under consideration, is represented by a rectangle. In side this
rectangle, circles or other geometrical figures are used to represent
sets.
Example (3):
Draw a Venn diagram that represent V, the set of vowels in the
English alphabet.
Venn diagram for the set of vowels
U ax
ux
ox i.
e.
V
31
Def (4).:
The set A is said to be a subset of B if and only if every element
of A is also an element of B . we use the notation BA to indicate
that A is a subset of the set B .
Venn diagram showing BA
Example (4):
The set of all odd positive integers less than 10 is a subset of the
set of all positive integers less than 10.
The set of rational numbers is a subset of real numbers IRQ
Theorem:
For every set S
(i) S
(ii) SS
Proof:
We will prove (i) and leave the proof of (ii) as an exercise
Let S be a set
)( Sxxx is true because the empty set contains no
elements it follows that x is always false, it follows that the
conditional statement Sxx is always true because its
hypothesis is always false and a conditional statement with a false
hypothesis is true.
BA
A
BA
B
BA
U
BA
32
When we wish to emphasize that a set A is a subset of the set B
but BA we write BA and say that A is a proper subset of B
)()( AxBxxBxAxx .
If A and B are sets with BA and AB , then A = B .
Def. (4):
Let S be a set. If there are exactly n distinct elements in S
where n is a nonnegative integer, we say that S is a finite set and that
n is the cardinality of S.
The cardinality of S is denoted by |S|.
Examples (5):
1) LetA be the set of odd positive integers less than 10. Then |A|= 5.
2) Let S be the set of letters in the English alphabet. Then | S | =
26.
3) 0 .
Def.(6): A set is said to be infinite if it is not finite.
Example (6): The set of positive integers is infinite.
2.1.2 The Power Set:
Def (1).
Given a set S , the power set of S is the set of all subsets of the set
S and is denoted by )(Sp .
Example (7): What is the power set of the set {0, 1, 2}?
Solution:
2,1,0p is the set of all subsets of {0, 1, 2}. Hence
2,1,0,2,1,2,0,1,0,2,1,0,2,1,0 p
Example (8):
What is the power set of the empty set?
What is the power set of the set
33
Solution :
p
{,p
If a set has n elements, then its power set has 2n elements
2.1.3 Cartesian Products:
Def. (7) : The ordered n–tuple naaa ,,, 21 is the ordered
collection that has 1a as its first element 2a as its second element and
na as its nth element.
Def. (8) Let A and B be sets. The Cartesian product of A and
B , denoted by BA , is the set of all ordered pairs ( a ,b ) where Aa
and Bb
BA = {( a , b ) | BbAa }
Example (9):
What is the Cartesian product of A = {1,2} and B = { a ,b , c }?
Solution: ),2(),,2(),,2(),,1(),,1(),,1( cbacbaBA
Def.(9):A subset R of the Cartesian product BA is called a
relation from the set A to the set B . the elements of R are ordered
pairs.
For example )3,(),0,(),2,(),1,(),1,(),0, ccbbaaR is a relation from
the set cba ,, to the set 3,2,1,0 .
Example (10):
Show that the Cartesian product ABBA where A and B
are the sets in example (9)
),2(),,2(),,2(),,1(),,1(),,1 cbacbaBA
)2,(),2,)(2,)(1,(),1,(),1,( cbacbaAB
34
Def. (10): The Cartesian product of nAAA ,...,, 21 denoted by
nAAAA ...311 is the set of ordered n-tuples naaa ,...,, 21 where
niAai ,....,2,1 .
Example (11):
What is the Cartesian product CBA where 2,1,1,0 BA
and 2,1,0C ?
Solution:
)1,1,1(),0,1,1(),2,2,0(),1,2,0(),0,2,0(),2,1,0(),1,1,0(),0,1,0( CBA
)2,2,1(),1,2,1(),0,2,1),2,1,1(
2.1.4 Sets Operations:
Def. (11) : Let A and B sets. The union of the sets A and B,
denoted by BA , is the set that contains those elements are either in
A or in B, BAvxxxBA
BA
Example (12):
The union of the sets 5,3,1 and 3,2,1 is the set 5,3,2,1 .
Def. (12): Let A and B be sets. The intersection of the sets A and
B , denoted by BA , is the set containing those elements in both A and
B .
BxAxxBA
BA
B A
u
B A
u
35
Example (13):
The intersection of the sets 5,3,1 and 3,2,1 is the set 3,1 .
Def. (13):
Two sets are called disjoint if their intersection is the empty set.
Example (14):
Let 9,7,5,3,1A , 8,6,4,2B
BA , A and B are disjoint
BABABA
Def. (14):
Let A and B sets. The difference of A and B , denoted
by A – B , is the set containing those elements that are in A but not in
B .
BxAxxBA
Example (15):
The difference of 5,3,1 and 3,2,1 is the set 5
Def. (15) :
Let U be the universal set. The complement of the set A,
denoted by A , is complement of A with respect to AAU
AxxA
A
A
36
Table (1)
Set identities
AUAAA
Identity laws
AUUA Domination laws
AAAAAA
Idempotent laws
AA Complementation law
ABBAABBA
Commutative laws
CBACBA
CBACBA
Associative laws
CABACBA
CABACBA
Distributive laws
BABA
BABA
Demorgans laws
ABAA
ABAA
Absorption laws
AA
UAA
Complement laws
37
Example (16):
Let uoieaA ,,,, (where the universal set is the set of the letters
of the English alphabet).
Then zyxwvtsrqpnmlkjhgfdcbA ,,,,,,,,,,,,,,,,,,,,
Example (17):
Let A be the set of positive integers greater than 10 (with
universal set the set of all positive integers).
Then 10,9,8,7,6,5,4,3,2,1A .
2.1.5 Sets Identities:
Table 1 list the most important set identities here we prove
several of these identities using three different methods the proofs of
the remaining identities will be left as exercises.
Example (18): Use set builder notation express the reasoning
establish the 2nd demorgan’s law BABA
Proof :
)( BAxxBA (def of complement)
= BAxx (def. of does not belong symbol)
= BxAxx (def . of intersection)
= BxAxx (first demorgan’s law)
= BxAxx (by definition of does not belong symbol)
= BxAxx (by definition of complement)
= )( BAxx (by definition of union)
= BA (by meaning of set building notation).
Example (19):
Prove the first distributive law from table (1), which states that
CABACBA sets A, B and C.
38
Solution:
(i) Suppose CBAx
Ax and )( CBx
Ax and Bx or Cx (or both)
Ax and Bx or Ax and Cx
BAx or CAx
CABAx
CABACBA .
(ii) Suppose that )( CABAx
)( BAx or )( CAx
Ax and Bx or CxAx
Ax and Bx or Cx
Ax and )( CBx
)( CBAx
CBACABA
From (i), (ii) we complete the proof.
Table (2): A membership table for the distributive property
A B C CB CBA BA CA CABA
1 1 1 1 1 1 1 1
1 1 0 1 1 1 0 1
1 0 1 1 1 0 1 1
1 0 0 0 0 0 0 0
0 1 1 1 0 0 0 0
0 1 0 1 0 0 0 0
0 0 1 1 0 0 0 0
0 0 0 0 0 0 0 0
To complete the proof
39
Example (20):
Let A, B and C be sets. Show that ABCCBA .
Solution :
CBACBA (First Demorgan’s law)
= CBA (2nd Demorgan’s law)
= ACB (commutative law for intersections)
= ABC (Commutative law for unions)
Generalized Unions and intersections
Union of A, B and C Intersection of A, B and C
Example (21):
Let 8,6,4,2,0A , 4,3,2,1,0B
and 9,6,3,0C what are CBA and CBA
Solution:
9,8,6,4,3,2,1,0CBA
0CBA
Def. (16):
The union of a collection of sets is the set that contains those
elements that are members of at least one set in the collection
i
n
in AAAA
121
B
C
U
B
A
A
U
40
Def. (17):
The intersection of a collection of sets is the set that contains
those elements that are members of all the sets in the collection
i
n
in AAAA
121
We can extend the notation we have introduce for unions and
intersections to other families can be denoted by
1) ii
n AAAA
1
21
2) ii
n AAAA
1
21
Example (22):
Suppose that iAi ,,2,1 for ,2,1i
Then
,3,2,1,,2,111
i
ii
i
iA
and 1,,2,111
i
ii
i
iiA A
2.1.6 Computer Representation of sets:
There are various ways to represent sets using a computer. One
method is to store the elements of the set in an unordered fashion.
However, if this is done, the operations of computing the union,
intersection or difference of two sets would be time-consuming,
because each of these operations would require a large amount of
searching for elements. We will present a method for storing
elements using an arbitrary ordering of the elements of the universal
set. This method of representing sets makes computing combinations
of sets easy.
41
Assume that the universal set is finite. First, specify an
arbitrary ordering of elements of naaa ,,, 21 . Represent a
subset of with the bit string of length n, where the ith bit in this
string is 1 if ia belongs to A and 0 if ia does not belong to A.
Example (23): Suppose that the universal set U= { 1,2,3,4,…,10}
The bit string for the subsets 6,4,3,2,1 and 9,7,5,3,1 of U are
11 1101 0000 and 10 1010 1010 respectively. Use bit strings to
find the union and intersection of these sets?
Solution:
1) The bit string for the union of these sets is
11 1101 0000 10 1010 1010 = 11 1111 1010 which
corresponds to the set 9,7,6,5,4,3,2,1 .
2) The bit string for the intersection of these sets is
11 1101 0000 10 1010 1010 = 10 1000 000
Which corresponds to the set 3,1
Exercises:
1) Let 푨 = {ퟏ, ퟐ , ퟑ, ퟒ, ퟓ} and 푩 = {ퟎ, ퟑ, ퟔ}
Find (a) 푨 ∪ 푩 (b) 푨 ∩ 푩 (c) 푨 − 푩 (d) 푩 − 푨
2) Find the sets A and B if
푨 − 푩 = {ퟏ, ퟓ, ퟕ, ퟖ}, 푩 − 푨 = {ퟐ, ퟏퟎ} and 푨 ∩ 푩 = {ퟑ, ퟔ, ퟗ}
3) Determine whether these statements are true or false:
(a) ퟎ ∈ ∅ (b) ∅ ∈ {ퟎ} (c) {ퟎ} 풄 ∅ (d) ∅ 풄 {ퟎ}
(e) {ퟎ} ∈ {ퟎ} (f) {ퟎ} 풄 ∅, {∅} (g) {∅} 풄 {∅} , �∅}
4) Use Venn diagram to illustrate the subset of odd integers in
the set of all positive integers not exceeding 10.
5) Use Venn diagram to illustrate the relation ship 푨 ⊆ 푩 and
푩 ⊆ 푪
42
6) What is the Cartesian product 푨 × 푩 × 푪 where 푨 = {풂, 풃, 풄} ,
푩 = {풙, 풚} and 푪 = {ퟎ, ퟏ}
7) Let 푨 = {ퟎ, ퟐ, ퟒ, ퟔ, ퟖ, ퟏퟎ}, 푩 = {ퟎ, ퟏ, ퟐ, ퟑ, ퟒ, ퟓ, ퟔ} and 푪 =
{ퟒ, ퟓ, ퟔ, ퟕ, ퟖ, ퟗ, ퟏퟎ}. Find: (a) 푨 ∩ 푩 ∩ 푪 (b) 푨 ∪ 푩 ∪ 푪 (c)
(푨 ∪ 푩) ∩ 푪 (d) (푨 ∩ 푩) ∪ 푪
8) Suppose that the universal set 푼 = {ퟏ, ퟐ, ퟑ, … , ퟏퟎ}
Express each of these sets with bit strings where the ith in
the string is 1 if i is the set and 0 otherwise. a) {ퟑ, ퟒ, ퟓ}
풃){ퟏ, ퟑ, ퟔ, ퟏퟎ} c) {ퟐ, ퟑ, ퟒ, ퟕ, ퟖ, ퟗ}
9) Using the same universal set in problem (8) find the set
specified by each of these bit strings
(a) 11 1100 1111 (b) 01 0111 1000 (c) 10 0000 0001
2.2.1 Relations and their properties:
Def. (1):
let A and B be sets. A binary relation from A to B is a subset of
BA
We use aRb to denote that IRba ),( and aRb to denote that
Rba ),(
Example (1):
Let A be the set of students in your school, and let B be the set
of courses. Let R be the notation that consists of those pairs ),( ba ,
where a is a student enrolled in course b . For instance, if Ahmed
and Ali and Zeid are enrolled in 518CS , the pairs( Ahmed, 518CS )
and (Ali, 518CS ), belong to R , if Ali also enrolled in 510CS then the
pair (Ali, 510CS ) is also in R , however, if Zeid is not enrolled in 510CS
then the pair (Zeid, 510CS ) is not in R .
43
Example (2):
Let 2,1,0A and baB , . Then
baba ,2(),,1(),,(),0,0( is a relation from A to B , aRa but Rb1 .
Relations can be represented graphically as shown in the figure:
R a b
0 . a 0 x x
1 . 1 x
2 . b 2 x
2.2.2 Relations on a set :
Relations from a set A to itself are of special interest.
Def. (2):
A relation on the set A is a relation from A to A
Example (3):
Let 4,3,2,1A which ordered pairs are in the relation
abaR ),( divides b
Solution :
Rba ),( if and only if a and b are positive integers not
exceeding 4 such that a divides b
)4,4(),3,3(),4,2(),2,2(),4,1(),3,1(),2,1(),1,1(R
R 1 2 3 4
1 1 1 x x x x
2 2 2 x x
3 3 3 x
4 4 4 x
Example (4) :
How many relations are there on a set with n elements?
44
Solution:
A relation on a set AAA since AA has 2n elements when A
has n elements, hence A has n2 subsets.
there are 22n subsets of AA .
Thus there are 2
2n relations on a set of n elements. For example
there are 51222 932
relations on the set cba ,,
2.2.3 Properties of relations:
Def. (3):
A relation R on a set A is called reflexive if AaRaa ,),( .
Example (5):
On 4,3,2,1
)4,4(),1,4(),4,3(),2,2(),1,2(),2,1(),1,1(1 R
)1,2(),2,1(),1,1(2 R
)4,4(),1,4(),3,3(),2,2(),1,2(),4,1(),2,1(),1,1(3 R
)3,4(),2,4(),1,4(),2,3(),1,3(),1,2(4 R
)4,4(),4,3(),3,3(),4,2(),3,2(),2,2(),4,1(),3,1(),2,1(),1,1(5 R
)4,3(6 R
Which of these relations are reflexive?
Solution:
The relations 3R and 5R are reflexive because they both contain
all pairs of the form ),( aa namely )4,4(),3,3(),2,2(),1,1( . The other
relations are not reflexive and because they do not contain all of these
ordered pairs. In particular 421 ,, RRR and 6R are not reflexive
because (3,3) is not in any of these relations.
Example (6):
Is the "divides" relation on the set of positive integers reflexive.
45
Solution:
Since aa whenever a is a positive integer denoted by divR
integer, the "divides" relation is reflexive. If we replace the set of
positive integers with the set of all integers the relation is not
reflexive because 0 does not divides 0 .
Def. (4):
A relation on a set A is called symmetric if Rab ),( whenever
Rba ),( , Aba , . A relation R on a set A Aba , , if Rba ),( and
Rab ),( , then ba is called antisymmetric.
Example (7): Consider the relations on the set of integers:
babaR ),(1
babaR ),(2
borababaR ,),(3
babaR ),(4
1),(5 babaR
3),(6 babaR
Which of these relations contain each of the pairs (1,1) ,(1,2)
,(2,1) ,(1,-1) and (2,2)?
Solution: The pair (1,1) is in 푹ퟏ, 푹ퟑ, 푹ퟒ 풂풏풅 푹ퟔ , (ퟏ, ퟐ) 풊풔 풊풏 푹ퟏ풂풏풅 푹ퟔ, (ퟐ, ퟏ) 풊풔 풊풏 푹ퟐ, 푹ퟓ풂풏풅 푹ퟔ, (ퟏ, −ퟏ)풊풔 풊풏 푹ퟏ, 푹ퟑ 풂풏풅푹ퟔ
and finally, (2,2)is in푹ퟏ , 푹ퟑ , 풂풏풅 푹ퟒ
Example (8):
Which of the relations from example (5) are symmetric and
which are antisymmetric.
Solution :
The relations 2R and 3R are symmetric because in each case ),( ab
belongs to the relation whenever ),( ba does. For 2R both )1,2( and
46
2)2,1( R . For 3R both 3)2,1(),1,2( R and 3)1,4(),4,1( R . 54 , RR and 6R are
antisymmetric.
Example (9):
Which of the relations from example (7) are symmetric and
which are antisymmetric.
Solution:
The relations 43, RR and 6R are symmetric. 3R is symmetric, for
ba or ba , then ab or ab
4R is symmetric because abba .
6R is symmetric because 33 abba .
non of the other relations is symmetric (verify).
The relations 421 ,, RRR and 5R are antisymmetric
1R is antisymmetric because the inequalities ba and baab
2R is antisymmetric because it is impossible for ba and ab .
4R is antisymmetric, because two elements are related with
respect to 4R if and only if they are equal.
5R is antisymmetric because it is impossible that 1 ba and
1 ab .
Example (10):
Is divR on the set of positive integers symmetric? Is it
antisymmetric?
Solution:
divR is not symmetric because 21)2,1( divR but divR)1,2( since 2∤1.
It is antisymmetric, Zba , with ba and ab , then ba .
47
Def. (3):
A relation R on a set A is called transitive if whenever Rba ),(
and Rcb ),( , then AcbaRca ,,.),( .
Using quantifiers Acba ,, RcaRcbRba ),(),(),( .
Example (11):
Which of the relations in example (7) are transitive?
Solution:
The relations 321 ,, RRR and 4R are transitive.
1R is transitive since ba and cacb
2R is transitive since ba and cacb
3R is transitive since ba and cacb
4R is clearly transitive.(verify)?
5R is not transitive since )1,2( and 5)0,1( R but 5)0,2( R
6R is not transitive since )1,2( and 5)2,1( R but 6)2,2( R
Example (12):
Is divR on the set of positive integers is transitive?.
Solution:
Suppose that a divides b and b divides c . Then there are
positive integers k and L akbthatsuch and bLc . Hence )(kLac ,
so a divides c . Hence divR is transitive .
2.2.4 Combining relations:
Example (13):
Let 3,2,1A and 4,3,2,1B
The relation )3,3(),2,2(),1,1(1 R and
)4,1(),3,1(),2,1(),1,1(2 R
Can be combined to obtain:
)3,3(),2,2(),4,1(),3,1(),2,1(),1,1(21 RR
48
)1,1(21 RR
)3,3(),2,2(21 RR
)4,1(),3,1(),2,1(12 RR
Example (14): Let 1R be the "less than" relation on the set of
real numbers and let 2R be the "greater than" relation on the set of
real numbers, that is yxyxR ),(1 and yxyxR ),(2 what are
(1) 21 RR (2) 21 RR (3) 21 RR (4) 12 RR and (5) 21 RR ?
Solution (1) We note that 21),( RRyx iff 1),( Ryx or 2),( Ryx .
Hence 21),( RRyx iff yx or yx . Because the condition yx or
yx is the same as the condition yx it follows that
yxyxRR ),(21
(2) 21),( RRyx since yx and yx is impossible.
Hence 21 RR =흓
(3) 121 RRR
(4) 212 RRR
(5) yxyxRRRRRR ),(212121
Def. (4):
Let R be a relation from a set A to the set B and S be a
relation from B to a set C . The composite of R and S is the relation
consisting of ordered pairs ),( ca where Aa and Cc , and for which
there exists an element Bb such that Rba ),( and Scb ),( . We
denote the composite of R and S by SoR .
Example (15):
What is the composite of R and S where R is a relation from
3,2,1 to 4,3,2,1 with )4,3(),1,3(),3,2(),4,1(),1,1(R and S is a relation
from 4,3,2,1 to 2,1,0 with )1,4(),2,3(),1,3(),0,2(),0,1(S
49
Solution:
)1,3(),0,3(),2,2(),1,2(),1,1(),0,1(SoR
Def. (5):
Let R be a relation on the set A . The powers ,....2,1, nR n are
defined recursively by RR 1 and oRRR nn 1
( RoRoRoRRRRoRR 232 , and so on)
Example (16):
Let )3,4(),2,3(),1,2(),1,1(R find nR for ,....5,4n .
Solution:
Since )2,4(),1,3(),1,2(),1,1(22 RRoRR
)2,4(),1,3(),1,2(),1,1(223 RoRRR 34 RR . Hence 3RR n for ,.......7,6,5n
Theorem(1) :
The relation R on a set A is transitive iff RR n for ,....2,1n
Exercises:
1) List the ordered pairs in the relation R from A={1,2,3,4} to
B={0,1,2,3}, where (a,b) R if and only if :
a) a=b (b) a+b =4 (c) a b (d) a│b
2) For each of these relations on the set {1,2,3,4}, decide whether it
is reflexive ,symmetric ,antisymmetric and whether it is
transitive:
a){(2,2) ,(2,3),(2,4),(3,2),(3,3),(3,4)}
b) {(1,1),(1,2),(2,1) ,(2,2),(3,3) ,(4,4)}
c) {(1,2),(2,3) ,(3,4)}
d) {(2,4),(4,2)}
3) Determine whether the relation R on the set of all people is
reflexive , symmetric ,antisymmetric and /or transitive ,where
50
(a,b) R if and only if :
a) a is taller than b
b) a and b were born on the same day.
c) a has the same first name as b.
d) a and b have a common grandparent.
4) Let 푹ퟏ = { (ퟏ, ퟐ), (ퟐ, ퟑ), (ퟑ, ퟒ)}
And 푹ퟐ = { (ퟏ, ퟏ), (ퟏ, ퟐ), (ퟐ, ퟏ), (ퟐ, ퟐ), (ퟐ, ퟑ), (ퟑ, ퟏ), (ퟑ, ퟐ), (ퟑ, ퟒ)}
be relations from {1,2,3} to {1,2,3,4} find:
a) 푹ퟏ ∪ 푹ퟐ
b) 푹ퟏ ∩ 푹ퟐ
c) 푹ퟏ ⨁ 푹ퟐ
d) 푹ퟏ − 푹ퟐ
e) 푹ퟐ − 푹ퟏ
5) Let R be the relation {(1,2),(1,3),(2,3),(2,4),(3,1)} and S be the
relation {(2,1),(1,3),(2,3),(2,4),(3,1)} find SR
2.2.5 Representing Relations Using Matrices:
A relation between finite sets can be represented using a zero –
one matrices. Suppose that R is a relation from naaaA ,...,, 21 to
nbbbB ,...,, 21 (Here the elements of the sets A and B have been
listed in a particular, but arbitrary, order. Furthermore when BA
we use the same ordering from A and B .
The relation R can be represented by the matrix ijR mM
where
RbaifRbaif
mji
jiij ,0
,1
51
Example (17):
Suppose that 3,2,1A and 2,1B let R be the relation from A to
B containing ),( ba if Aa , Bb , and ba . What is the matrix
representing R if 3,2,1 321 aaa and 2,1 2 bb ?
Solution:
Because )2,3(),1,3(),1,2(R , the matrix for R is
110100
RM
Example (18):
Let 321 ,, aaaA and 54321 ,,,, bbbbbB represented by the
matrix
101010110100010
RM
Solution:
Since R consists of those ordered pairs ji ba , with 1ijm , it
follows that ,,,,,,,, 42321221 babababaR 533313 ,,,,, bababa
If the matrix of R is square matrix, we say that R is reflexive if
niRaa ii ,...,2,1,, (the elements in the diagonal of the matrix are
S1 ).
The relation R is symmetric if Rba , implies Rba ,
nimm jiij ,....,2,1 . The relation R is antisymmetric if and only if
Rba , and ( baRab ), . Consequently, the matrix of an
antisymmetric relation has the property that if 1jim with ji then
0jim . Or, in other words, either 0jim or 0ijm when ji
52
Symmetric relation antisymmetric matrix
Example (19):
Suppose that the relation R on a set is represented by the
matrix.
110111011
RM
Is R reflexive, symmetric, and/or antisymmtric.
Solution:
Because all the diagonal elements of the matrix are equal to 1, R
is reflexive. Moreover, because RM is symmetric, it follows that R is
symmetric. It is also easy to see that R is not antisymmetric.
The Boolean operations join and meet , can be used to find
the matrices representing the union and intersection of two relations.
Suppose that 1R and 2R are relations on a set A represented by the
matrices 1RM and
2RM respectively. The matrix representing the
union of these relations has a 1 in the position where both 1RM and
2RM have 1. Thus the matrices representing the union and
intersection of these relations are 2121 RRRR MMM and
2121 RRRR MMM
1
1
1
1
0
1
0
0 0
1
53
Example (20):
Suppose that the relations 1R and 2R on a set A are represented
by the matrices:
,010001101
1
RM
001110101
2RM
What are the matrices representing 21 RR and 21 RR
Solution:
The matrices of these relations are
011111101
2121 RRRR MMM
000000101
2121 RRRR MMM
2.2.6 The matrix for the composite relations:
Suppose that BA, and C sets have pnm ,, elements, respectively
let the zero – one matrices for SoR ( R is a relation from A to B and
S is a relation from B to C ), R and S be
ijRijSoR rMtM , and ijS SM resp, (these matrices have
sizes pm , nm and pn and resp). The ordered pairs SORji ca , if
and only if there is an element Rbathatsuchb kik , and Scb jk , . It
follows that 1ijt iff 1 kjik sr for some k . From the definition of
the Boolean product, this means that:
RSoR MM • SM
Example (21):
Find the matrix representing the relations SoR , where the
matrices representing R and S are
54
,000011101
RM
101100010
SM
Solution:
The matrix for SoR is
RSoR MM •
000110111
SM
The matrix representing the composite of two relations can be
used to find the matrix for nRM in particular nRR MM n
Example (22): Find the matrix representing the relation 2R ,
where the matrix representing R is
001110010
RM
Solution: The matrix for 2R is
010111110
22 RR MM
2.2.7 Representing Relations Using diagraphs:
Def. (6):
A directed graph or diagraph consists of a set V of vertices
(nodes) together with a set E of ordered pairs of elements of V called
edges (arcs). The vertex a is called the initial vertex of the edge ba,
and the vertex b is called the terminal vertex of this edge.
An edge of the form aa, is represented using an arc from the
vertex, a back to itself. Such an edge is called a loop.
55
Example (23): The directed graph with vertices cba ,, and d ,
and edges ba, , da, , bb, , db, , ac, , bc, , and bd , is displayed
as in the figure:
Example (24): The directed graph of the relation
)1,4(),2,3(),1,3(),4,2(),3,2(),1,2(),3,1(),1,1(R on the set 4,3,2,1 is
shown in the figure:
Example (25):
What are the ordered pairs in the relation R represented by the
directed graph shown in the figure.
a
d
c
b
1 2
3 4
1 2
3 4
56
Solution :
The ordered pairs yx, in the relation are:
)3,4(),1,4(),3,3(),1,3(),3,2(),2,2(),1,2(),4,1(),3,1(R
Each of these pairs corresponds to an edge of the directed graph
with 2,2 and 3,3 corresponding to loops.
The directed graph representing a relation can be used to
determine whether the relation has various properties. A relation is
reflexive if and only if there exist a loop at every vertex of the
directed graph, so that every ordered pair of he form xx, occurs in
the relation.
A relation is symmetric if and only if for every edge between
distinct vertices in its diagraph there is an edge to the opposite
direction, so that xy, is in the relation whenever yx, is in the
relation. Similarly a relation is antisymmetric if and only if there are
edges in opposite direction between distinction vertices. A relation is
transitive if and only if whenever there is an edge from a vertex x to
a vertex y and an edge from a vertex y to a vertex z , there is an
edge from x to z.
Example (26):
Determine whether the relations for the directed graph shown in
the given figure are reflexive, symmetric, antisymmetric, and/or
transitive.
R S
a
b c c
d
a b
57
Solution :
There are loops at every of the directed graph of R , it is
reflexive, R is neither symmetric nor antisymmetric because there is
an edge from a to b but not one from b to a , but there are edges in
both directions connecting b and c .
R is not transitive because there is an edge from a to b and an
edge from b to c but no edge from a to c .
The loops are not present at all the vertex of the directed graph
of S , this relation is not reflexive. It is symmetric and not
antisymmetric because every edge between distinct vertices is
accompanied by an edge in the opposite direction. It is also S is not
transitive because Sabac ),(),,( but Sbc ),( .
Exercises:
Represent each of these relations on {ퟏ, ퟐ, ퟑ} with
(a) {(ퟏ, ퟏ), (ퟏ, ퟐ), (ퟏ, ퟑ)} (b) {(ퟏ, ퟐ), (ퟐ, ퟏ), (ퟐ, ퟐ), (ퟑ, ퟑ)}
(b) {(ퟏ, ퟏ), (ퟏ, ퟐ), (ퟏ, ퟑ), (ퟐ, ퟐ), (ퟐ, ퟑ), (ퟑ, ퟑ)} (c)
{(ퟏ, ퟑ), (ퟑ, ퟏ)}
2) List the ordered pairs in the relations on {ퟏ, ퟐ, ퟑ}
corresponding to these matrices
(a) ퟏ ퟎ ퟏퟎ ퟏ ퟎퟏ ퟎ ퟏ
(b) ퟎ ퟏ ퟎퟎ ퟏ ퟎퟎ ퟏ ퟎ
(c) ퟏ ퟏ ퟏퟏ ퟎ ퟏퟏ ퟏ ퟏ
3) List the ordered pairs in the relations represented by the
directed graphs
(a) (b) (c)
a
b c
58
4) Draw the directed graph that represents the relation
{(풂, 풂), (풂, 풃), (풃, 풄), (풄, 풃), (풄, 풅), (풅, 풂), (풅, 풃)}
2.2.8 Equivalence Relations:
Def. (7):
A relation on a set A is called an equivalence relation if it is
reflexive, symmetric and transitive.
Equivalence relations are important throughout mathematics
and computer science. One reason for this is that are equivalence
relation, when two elements are related it makes sense to say they are
equivalent.
Def. (8):
Two elements a and b that are related by an equivalence
relation are called equivalent the notation ba ~ is often used to
denote that a and b that are equivalent elements with respect to a
particular equivalence relation.
Example (27):
Let R be a relation on the set of real numbers aRb if and
only if Zba .
Is R an equivalence relation?
Solution:
1) R is reflexive since ZaaRa 0: IRaaRa
2) R is symmetric since ZbaRba :, and Zab bRaaRb ,
3) R is transitive let aRb and bRc
ZcbZba . Therefore Zcbbaca )()(
aRc
Hence R is an equivalence relation.
One of the most widely used equivalence relations is conqurence
modulo m , where 1mZm .
59
Example (28):
Let m be a positive integer 1m . Show that the relation
)(mod),( mbabaR is an equivalence relation on Z
Solution:
1) We have seen that mba mod if and only if m divides ba .
Note that 0 aa is divisible by m , because m.00 . Hence
)(mod maa R is reflexive.
2) Suppose that )(mod mba . Then ba is divisible by m , so
kmba where Zk . It follows that mkab )( , so
)(mod mab . hence is symmetric.
3) Suppose that )(mod mba and )(mod mcb . Then m divides
ba and cb . Therefore, there are integers k and L with
kmba and Lmcb . Adding these two equations mLkLmkmcbbaca )()()(
Hence )(mod mca R is transitive form (1) , (2) and (3) R is
an equivalence relation.
Example (29):
Show that the "divides" relation divR of the set of positive
integers is not an equivalence relation.
Solution:
By example (6) and example (12), we show that the "" divR is
reflexive and transitive and by example (10) divR is not symmetric
(for instance 2│4 but 4∤2. Hence "" divR on Z is not an equivalence
relation.
60
Example (30):
Let R be the relation on the set of real numbers such that xRy if
and only if IRyx , (real numbers) such that 1yx . show that R is
not an equivalence relation.
Solution :
1) R is reflexive since 10 xx
2) R is symmetric since, for if 1,,, yxIRyxxRy , which tells us
that 1yxxy so yRx
3) R is not transitive. Take 9.1,8.2 yx and 1.1Z ,
so that ,19.09.18.2 yx 18.01.19.1 zy but
17.11.18.2 zx . That is, 1.19.1,9.18.2 RR but 1.18.2 R R
is not an equivalence relation.
2.2.9 Equivalence Classes:
Def. (9):
Let R be an equivalence relation on a set A . The set of all
elements that are related to an element Aa is called the equivalence
class of a . The equivalence class of with respect to R is denoted by
Ra . When only one relation is under consideration, we can delete
the subscript R and write a for this equivalence class.
3,2,1
Example (31):
What are the equivalence classes of 0 and 1 for congruence module
4?
Solution:
The equivalence class of 0 contains all integers a such that
)4(mod0a . The integers in this class are those divisible by 4
,...8,4,0,4,8...,0
61
The equivalence class of 1 contains all the integers a such that
)4(mod1a . The integers in this class are those that have a
remainder of 1 when divided by 4. Hence
,...9,5,1,3,7...,1
The equivalence classes of the relation congruence modulo are
called the congruence classes modulo m. The congruence class of an
integer a modulo m is denoted by ma , so
,...2,,,,2..., mamaamamaa m
For instance, it follows that :
,...8,4,0,4,8...,0 4 and
,...9,5,1,3,7...,1 4
Theorem(2) :
Let R be an equivalence relation on a set A . These statements
for elements Aba , are equivalent:
(i) aRb (ii) ba (iii) ba
Proof :
1) (i) implies (ii) Assume that aRb . We will prove that
ba by showing ba and ab . Suppose ac .
Then aRc . Since aRb and R is symmetric )(bRa .
Furthermore, since R is transitive and bRa and aRc , it
follows that bRc . Hence babc , ab is left and
exercise for the reader.
2) (ii) implies (iii). Assume that ba . It follows that
ba because Raaa is reflexive.
3) (ii) implies (i): suppose that ba = Then ac and
bc . ( aRc and bRc ). By the symmetric property, cRb .
Then by transivity, aRc and aRbcRb . Because (i) implies
62
(ii), (ii) implies (iii), and (iii) implies (i), the three statements,
(i), (ii) and (iii) are equivalent.
The union of the equivalence classes of R is all of A
(1) Aa RAa
(2) RR ba when RR ba
These two observations show the equivalence classes from a
partition of A , because they split A into disjoint subsets. More
precisely, a partition of a set S is a collection of disjoint nonempty
subsets of S that have S as their union. In other words, the
collection of subsets IiAi , (I is an index set) forms a partition of S
if and only if.
1) IiAi ,
2) jiAA ji ,
3) SAiIi
Figure 1 illustrates the concept of a partition of a set
Example (32):
Suppose that 6,5,4,3,2,1S . The collection of the sets 3,2,11 A ,
5,42 A and 6 forms a partition of S because these sets are disjoint
and their union is S .
A4 A5 A7
A1 A2
A3
A6
A9 A8
63
Theorem (3) :
Let R be an equivalence relation on a set S . Then the
equivalence classes of R form a partition of S . Conversely, given a
partition { }IiAi of the set S , there is an equivalence relation R that
has the sets IiAi , , as its equivalence classes.
Example (33):
List the ordered pairs in the equivalence relation R produced by
the partition 3,2,11 A , 5,42 A and 63 A of 6,5,4,3,2,1S in
example (32).
Solution:
The subsets in the partition are the equivalence classes of R .
The pair Rba ),( iff a and b are in the same subset of the partition.
The pairs )2,3(),3,2(),2,2(),1,2(),3,1(),2,1(),1,1( and R)3,3( because
3,2,11 A is an equivalence class.
The pairs )4,5(),5,4(),4,4( and R)5,5( , because 5,42 A is an
equivalence class. The pair R)6,6( , because 6 is an equivalence
class. No pair other than those listed belong to R .
Example (34):
What are the sets in the partition of the integers arising from
congruence modulo 4?
Solution:
There are four congruence classes, corresponding to 444 2,1,0
and 43 . They are the sets:
,...8,4,0,4,8...,0 4
64
,...9,5,1,3,7...,1 4
,...10,6,2,2,6...,2 4
,...11,7,3,1,5...,3 4
These congruence classes are disjoint, and every integer is
exactly one of them. In other words, as theorem (2) says, these
congruence classes form a partition.
Exercises :
Which of these relations on {ퟎ, ퟏ, ퟐ, ퟑ} are equivalence relations
(a) {(ퟎ, ퟎ), (ퟏ, ퟏ), (ퟐ, ퟐ), (ퟑ, ퟑ)}
(b) {(ퟎ, ퟎ), (ퟎ, ퟐ), (ퟐ, ퟎ), (ퟐ, ퟐ), (ퟐ, ퟑ), (ퟑ, ퟐ), (ퟑ, ퟑ)}
(c) {(ퟎ, ퟎ), (ퟏ, ퟏ), (ퟏ, ퟐ), (ퟐ, ퟏ), (ퟐ, ퟐ), (ퟑ, ퟑ)}
2) Which of these relations on the set of all functions from ℤ to ℤ are
equivalence relations? Determine the properties of an
equivalence relation that the others lack
(a) {�(풇, 품)|풇(ퟏ) = 품(ퟏ)}
(b) {�(풇, 품)|풇(ퟎ) = 품(ퟎ) 퐨퐫 풇(ퟏ) = 품(ퟏ)}
(c) {�(풇, 품)|풇(풏) − 품(풙) = ퟏ, ∀풙 ∈ ℤ }
3) Determine whether the relations represented by these matrices
are equivalence relations:
(a) ퟏ ퟏ ퟏퟎ ퟏ ퟏퟏ ퟏ ퟏ
(b) ퟏ ퟎퟎ ퟏ ퟏ ퟎ
ퟎ ퟏퟏ ퟎퟎ ퟏ ퟏ ퟎ
ퟎ ퟏ
(c) ퟏ ퟏퟏ ퟏ ퟏ ퟎ
ퟏ ퟎퟏ ퟏퟎ ퟎ ퟏ ퟎ
ퟎ ퟏ
4) Which of these collections of subsets are partions of
{ퟎ, ퟏ, ퟐ, ퟑ, ퟒ, ퟓ, ퟔ}?
(a) {ퟏ, ퟐ}, {ퟐ, ퟑ, ퟒ}, {ퟒ, ퟓ, ퟔ}
(b) {ퟏ}, {ퟐ, ퟑ, ퟔ}, {ퟒ}, {ퟓ}
65
(c) {ퟐ, ퟒ, ퟔ}, {ퟏ, ퟑ, ퟓ}
5) What is the congruence class (a) [ퟒ]풎 when m is
(a) 2? (b) 3? (c) 6? (d) -3?
2.2.10 Partial ordering:
Def. (1): A relation R on a set S is called partial ordering if it is
reflexive, antisymmetric, and transitive. A set S together with a
partial ordering R is called a partially ordered set, or poset, and is
denoted by RS, . Members of S are called elements of the poset.
Example (1): Show that the "greater than or equal" relation
is a partial ordering on the set of integers.
Solution:
1) Because Zaaa , hence "" is reflexive
2) If bA and ab , then ba , hence "" is antisymmetric.
3) "" is transitive since cbba implies ca . Hence "" is
a partial ordering on the set of integers ),( Z is a poset.
Example (2):The divisibility relation | is a partial ordering
relation on Z , because it is reflexive, antisymmetric and transitive
( 풁 , | ) is a poset.
Example (3): Show that the inclusion relation "" is a partial
ordering on the power set of a set S .
Solution
1) Since AA when ever, "", SA is reflexive.
2) It is antisymmetric because ABBA imply that BA .
66
3) "" is transitive, because CBBA imply that CA .
Hence "" is a partial ordering on )),(().( spSp is a poset.
Def. (2): The elements a and b of a poset ),( S are called
comparable if either ba or ab . When a and b are elements of S
such that neither ba nor ab , a and b are called incomparable.
Example (4): In the poset ),( Z are the integers 3 and 9
comparable? Are 5 and 7 comparable.
Solution : 3 and 9 are comparable since 3|9 .
The integers 5 and 7 are incomparable because ퟓ ∤ ퟕ
and ퟕ ∤ ퟓ
2.2.11 Hasse diagrams: The resulting diagram contains sufficient
information to find the partial ordereing is called a Hasse diagram
Example (5): Draw the Hasse diagram representing the partial
ordering aba ),( divides b on 12,8,6,4,3,2,1 .
Solution : Begin with the diagraph for the partial order as
shown in the figure.
2)Remove all loops, as
shown in figure 1(b)
1 (a)
1
2
4
8
3
6
12
1(b) 1
2
4
8
3
6
1
67
Then delete all the edges implied by the transitive property.
These are (1,4), (1,6) (1,8),
(1,12), (2,8), (2,12) and (3,12)
Arrange all edges to point upward
And delete all arrows to obtain the
Hasse diagram as shown in the figure
(c)
Example (6): Draw the Hasse diagram for the partial ordering
{(푨, 푩)|푨 푩�} on the power set 푷(푺) where 푺 = {풂, 풃, 풄}.
Solution: The Hasse diagram for this partial ordering is
obtained from the associated diagraph by deleting all the loops and
all the edges that occur from transitivity, namely (∅, {풂, 풃}),
(∅, {풂, 풄}), (∅, {풃, 풄}), (∅, {풂, 풃, 풄}), ({풂}, {풂, 풃, 풄}), ({풃}, {풂, 풃, 풄}),
({풄}, {풂, 풃, 풄}). Finally all edges point upward, and arrows are
deleted as shown in figure 2.
Hasse diagram of (푷 {풂, 풃, 풄}, )
8
4
2
1
12
6
3
68
2.2.12 Maximal and Minimal Elements:
Def.(3): 1)An element of a poset is called maximal if it is not less
than any element of the poset.
1) An element of a poset is called minimal if it is not greater
than any element of the poset. Maximal and minimal
elements are easy to spot using Hasse diagram. They are
“top” and “bottom” in the diagram.
Example (7): Which elements of the poset
{ퟐ, ퟒ, ퟓ, ퟏퟎ, ퟏퟐ, ퟐퟎ, ퟐퟓ}, │ are maximal, and which are minimal?
Solution:
For this poset shows that
the maximal elements
are 12, 20 and 25 and
the minimal elements
are 2 and 5.
2.2.13 The greatest element and the least element:
Def.(8):1) An element 풃 in the poset (푺, ≤) is called the greatest
element of (푺, ≤) if 풃 ≤ 풂 ∀ 풂 ∈ 푺. The greatest element is
unique.
2)An element 풂 in the poset (푺, ≤) is called the least element of
(푺, ≤) if 풂 ≤ 풃 ∀ 풃 ∈ 푺. The least element is unique.
5 2
4
12 20
10 25
69
Example (8): Determine whether the posets represented by each of
the Hasse diagram in the figure have greatest element and least
element.
b c d d e d
a a b a b
(a) (b) (c) (d)
Solution:
1) The least element of the poset with Hasse diagram (a) is a. this
poset has no greatest element.
2) The poset with Hasse diagram (b) has neither a least nor a
greatest element.
3) The poset with Hasse diagram (c) has no least element. Its
greatest element is d.
4) The poset with Hasse diagram (d) has least element a and
greatest element d.
Example (9): Let 푺 be a set. Determine whether there is a
greatest element and a least element in the poset (푷(푺), .)
Solution: The least element is the empty set, because
∅ T , ∀T∈S. The set 푺 is the greatest element in this poset, because
푻 푺 whenever 푻 is a subset of 푺.
d
c
a
b
70
Example (10): Is there a greatest element and least element in
the poset ℤ , │ .
Solution: The integer 1 is the least element because 1│풏,
∀ 풏 ∈ ℤ , there is not integer that divide all positive integers, there is
no greatest element.
Def.(4): 1) An element 풖 ∈ 푺 is called an upper bound of 푨 푺
if 풂 ≤ 풖 ∀풂 ∈ 푨.
2) An element 푳 ∈ 푺 is called a lower bound of 푨 if
∀풂∀∈ 푨 푳 ≤ 풂.
Example (11): Find the lower and upper bounds of the subsets
{풂, 풃, 풄}, {풋, 풉} and {풂, 풄, 풅, 풇} in the poset with the given Hasse
diagram.
Solution:
1) The upper bounds of
{풂, 풃, 풄} are 풆, 풇, 풋 and and
its only lower bound is 풂.
2) There are no upper bounds
of {풋, 풉}, and its lower
pounds are 풂, 풃, 풄, 풅, 풆 and
풇.
3) The upper bounds of
{풂, 풄, 풅, 풇} are 풇, 풉 and 풋,
and its lower bound is 풂.
h
g f
e
c
a
b
d
j
71
Def.(5):
1) The element 풙 is called the least upper bound of the subset 푨
if 풙 is an upper pound that is less than every other upper
pound of 푨.
2) The element 풚 is called the greatest lower bound of 푨 if 풚 is
the lower bound of 푨.
Example (12): Find the greatest lower bound and the least upper
bound of {풃, 풅, 품}, if they exist in the poset shown in example (11).
Solution:
1) The upper bounds of 풃, 풅, 품 are 품 and because 품 < ℎ, 품 is the
least upper bound.
2) The lower bounds of {풃, 풅, 풅} are 풂, and 풃, because 풂 < 푏, 푏 is the
greatest lower bound.
Example (13):
Find the greatest lower bound and the least upper bound of the
sets {ퟑ, ퟗ, ퟏퟐ} and {ퟏ, ퟐ, ퟒ, ퟓ, ퟏퟎ} if they exist, in the poset ℤ , │ .
Solution:
1) An integer is a lower bound of {ퟑ, ퟗ, ퟏퟐ} if ퟑ, ퟗ and ퟏퟐ is
divisible by this integer. The only such integers are 1 and 3.
Since 1│3, 3 is the greatest lower bound of {ퟑ, ퟗ, ퟏퟐ}.
2) The only lower bound for the set {ퟏ, ퟐ, ퟒ, ퟓ, ퟏퟎ} with respect
to │ is the element 1. Hence 1 is the greatest lower bound for
{ퟏ, ퟐ, ퟒ, ퟓ, ퟏퟎ}.
72
3) An integer is an upper bound for {ퟑ, ퟗ, ퟏퟐ} iff it is divisible by
3, 9 and 12. The integers with this property are those
divisible by LCm (3, 9, 12) which is 36. Hence 36 is the least
upper bound of {ퟑ, ퟗ, ퟏퟐ}.
4) A positive integer is an upper bound for {ퟏ, ퟐ, ퟒ, ퟓ, ퟏퟎ} iff it is
divisible by 1, 2, 4, 5 and 10. The integers with this property
are those integers divisible by LCm (1, 2, 4, 5, 10) which is
20. Hence 20 is the least upper bound of {ퟏ, ퟐ, ퟒ, ퟓ, ퟏퟎ}.
2.2 .14 Lattices :
Def.(6): A partially ordered set in which every pair of elements
has both least upper bound and greatest lower bound is called a
lattice.
Example (14): Determine whether the posets represented by
each of the Hasse diagrams in the figure are lattices.
Solution:
(a) (b) (c)
1) The posets represented by the Hasse diagrams in (a), (c) are
both lattices because in each poset every pair of elements has
a
b
d
f
e
c
f
d c
b
a
e
e
h
b d d
a
73
both a least upper bound and a greatest lower bound.
(verify).
2) The poset with the Hasse diagram in (b) is not lattice, because
the elements b and c have no least upper bound.
Example (15): Is the poset ℤ , │ a lattice?
Solution: Let 풂, 풃 ∈ ℤ . the least upper bound and greatest
lower bound of these two integers are the least common multiple and
the greatest common divisor of these integers resp. (verify). Hence
ℤ , │ is a lattice .
Example (16): Determine whether (푷(풙),) is a lattice where 푺
is a set?
Solution: Let 푨 and 푩 be two subsets of 푺. The least upper
bound and the greatest lower bound of 푨 and 푩 are 푨푩 and 푨푩
respectively. Hence (푷(푺),) is a lattice.
Exercises:
1) Which of these are posets?
(a) (ℤ, =) (b) (ℤ, ≠) (c) (ℤ, ≥) (d) (ℤ, ∤)
2) Which of these pairs of elements in these posets?
(a) 푷({ퟎ, ퟏ, ퟐ},) (b) {ퟏ, ퟐ, ퟒ, ퟔ, ퟖ}, │
3) Draw the Hasse diagram for the “less than or equal to relation on
{ퟎ, ퟐ, ퟓ, ퟏퟎ, ퟏퟏ, ퟏퟓ}
4) answer these questions for the poset ({ퟑ, ퟓ, ퟗ, ퟏퟓ, ퟐퟒ, ퟒퟓ}, │)
(a) Find the maximal elements.
(b) Find the minimal elements.
(c) Is there a greater elements.
74
(d) Is there a least element?
(e) Find all upper bounds of {ퟑ, ퟓ}
(f) Find the least upper pound of {ퟑ, ퟓ}, if it exists
(g) Find all lower bounds of {ퟏퟓ, ퟒퟓ}
(h) Find the greatest lower pound of {ퟏퟓ, ퟒ ퟓ}, if it exists
5) Determine whether the posets with these Hasse diagrams are
lattices.
(a) (b)
2.3 Functions:
Def. (1):
Let A and B be non empty sets, a function f from A to B is an
assignment of exactly one element of B to each element of A . We write f(a) = b if b is the unique element of B assigned by the
function f to the element a of A . If f is a function from A to B , we
write BAf :
Remark : Functions are sometimes also called mappings or
transformations
A function BAf : can also be defined in terms of a relation
from A to B. A relation from A to B is just a subset of BA . A
a
b
d e
f
g
c b
d
c
g f
h
e
a
A
b
B
f
75
relation from A to B that contains one and only one, ordered pair
Aaba ),,( defines a function from A to B.
baf )( , where ),( ba is the unique ordered pair in the relation
that has a as its first element.
Def. (2): If a function from A to B, we say that A is the domain
of f. If baf )( we say that b is the image of a and a is a preimage of
b. The range of f is the set of all images of elements of A. also, if f is
a function from A to B, we say that f maps A to B.
Two functions are equal when they have the same domain, have
the same codomain, and map elements of their common domain to
the same elements in their common codomain.
Example(1):
What are the domain, codomain and range of the function that
assigns grades to students shown in the figure
Ahmed A
Ali B
Fahad C
Omer D
Osman F
Solution: Let g be the function that assigns a grade to a student
1) The domain f of g is {Ahmed, Ali, Fahad, Omer,
Osman}
2) The codomain of g is {A, B, C, D, F}
3) The range of g is {A, B, C, F}
Example(2):
Let f be the function that assigns the last two bits of length 2 or
greater to that string e.g. f(11010) = 10. Then, the domain of f is the
76
set of all bit strings of length 2 or greater, and both the codomain and
range are the set {00, 01, 10, 11}.
Example(3):
Let, :f Z→ Z assigns the square of an integer to this integer.
Then 2)( xxf the domain of f is the set of all integers the codomain
of f to be the set of all integers and the range of f is the set of all
integers that are perfect squares namely ,9,,4,1,0 .
Example(4):
The domain and codomain of functions are often specified in
programming languages. For instance, the Java statement in t floor
(float real) ( …..) and the pascal statement function floor (x : real):
integer both state that the domain of the floor function is the set of
real numbers and its codomain is the set of integers.
Def.(3):
Let f1 + f2 be functions from A to IR then f1 + f2 and f1f2 are also
functions from A to IR defined by
(1) xfxfxff 2121 (2) xfxfxff 2121
Example(5):
Let f1 and f2 be functions from IR to IR such that
22
21 , xxxfxxf what are the functions
(1) 21 ff (2) 21 ff
Solution:
(1) xxxxxfxfxff 222121
(2) 43222121 ... xxxxxxfxfxff
Def.(4): Let f be a function from the set A to the set B and let S
be a subset of A . the image of S under the function f is the subset of
77
B that contains of the images of the elements of S we denote the
image of S by Sf
SssfsftSstSf )()(
Example(6):
Let edcbaA ,,,, and 4,3,2,1B with 2)( af , 1)( bf , 4)( cf
, 1)( df and 1)( ef . The image of the subset S={b,c,e} is the set
4,1)( Sf .
2.3.1 One-to-one and Onto functions:
Some functions never assign the same value to two different
domain elements.
These functions are said to be on-to-one
Def.(5): A function f is said to be one-to-one or injective, if and
only if baf )( implies that ba for all a and fDb . A function is
said to be injection if it is one-to-one. Note that a function f is one-
to-one if and only if )()( bfaf whenever ba
Remark:
We can express that f is one-to-one using quantifiers as
babfafba )()( or equivalently )()( bfafbaba
where the universe of discourse is the domain of the function.
Example(7):
Determine whether the function f from dcba ,,, to 5,4,3,2,1
with 4)( af , 5)( bf , 1)( cf and 3)( df is one-to-one.
78
Solution:
The function f is one-to-one because f takes on different values
at the four elements of the domain as shown in the figure
a .1
b 2
c 3
d 4
5
Example(8):
Determine whether the function 1)( xxf from IR to IR is one-
to-one function.
Solution:
The function 1)( xxf is a One-to-One function , note that x+1
≠ y +1 when x≠y.
Def.(6):
A function f whose domain and codomain are subsets of the set
of real numbers is called increasing if )()( yfxf and stricktly
increasing if )()( yfxf whenever yx and x and y are in the
domain of f . Similarly f is called decreasing if )()( yfxf and
stricktly decreasing if )()( yfxf and stricktly decreasing if
)()( yfxf where yx and x and y are in the domain of f .
Def.(7):
A function from A to B is called onto or surjective if and only if
AaBb with baf )( . A function is called surjective if it is
onto.
.
. .
. .
. . .
79
Example(9) :
Let f be the function from dcba ,,, to 3,2,1 defined by 3)( af
, 2)( bf , 1)( cf and 3)( df is onto function
a . . 1
b . . 2
c . . 3
d .
An onto function
Example(10):
Is the function 2)( xxf from the set of integers to the set of
integers onto?
Solution:
The function f is not onto because there is integer x with 12 x
for instance.
Example (11):
Is the function 1)( xxf from the set of integers to the set of
integers onto?
Solution:
This function is onto, because ZxZy yxf )( . To sec
this, note that yxf )( if and only if yx 1 , which holds if and only
if 1 yx .
Def.(8): The function is a one-to-one correspondence or
bijective, if it is both one-to-one and onto.
Example(12):
Let f be the function from dcba ,,, to 4,3,2,1 with 4)( af ,
2)( bf , 1)( cf and 3)( df is f a bijection?
80
Solution:
The function is one-to-one and onto. It is one-to-one because no
two values in the domain are assigned the same function value. It is
onto because all four elements of the codomain are integers of
elements in the domain.
Hence f is a bijection.
Example(13):
Let A be a set. The identity function on A is the function
AAI A : where xxI A )( the function AI is bijection function.
2.3.2 Inverse functions and compositions of functions:
Def.(9):
let f be a one-to-one correspondence from the set A to the set
B . The inverse function of is the function assigns to an element
the unique element Aa baf )( . The inverse function of f is
denoted by abf )(1 when baf )( .
Example(14):
Let f be the function from cba ,, to 3,2,1 2)( af , 3)( bf
and 1)( cf is f invertable, and if it is what is its inverse.
Solution:
The function f is invertable because it is one-to-one
correspondence. The inverse function 1f reverses the
correspondence given by so cf )1(1 , af )2(1 and bf )3(1 .
Example(15) :
Let f : R R be such that 1)( xxf . Is f invertable, and if
it is what is its inverse?
81
Solution:
The function f has an inverse because it is a one-to-one
correspondence, as we have shown in example (10) it is invertible. To
find its inverse let
1)(11
yyfyxxy
Def.(10).:
Let g be a function from the set A to the set B and let f be a
function from the set B to the set C . The composition of the function
and denoted by ))(())(( agfafog is defined by .
Example(16):
Let g be the function from the set cba ,, to itself bag )( ,
cbg )( and acg )( let f be the function from the set cba ,, to the
set 3,2,1 3)( af , 2)( bf and 1)( cf what is the composition of
f and g , and what is the composition of g and f ?
Solution:
The composition is denoted by ))(())(( agfafog of 2)( b ,
))(( bfog 1)())(( cfbgf and 3)())(())(( afcgfcfog .
Example(17):
Let gf , be the functions from to defined by 32)( xxf and
g(x)=3x+2 what is the composition of f and g and what is the
composition of g and f ?
Solution:
(1) (풇°품)(풙) = 풇 품(풙) = 풇(ퟑ풙 + ퟐ) = ퟐ(ퟑ풙 + ퟐ) = ퟔ풙 + ퟒ
(2) 1162)32(3)32())(())(( xxxgxfgxgof
82
Remark:
Note that goffog if abfaffaff )())(()( 111 if baf )(
and bafbffbfof )()()( 11
2.3.3 Some important functions:
Def.(11):
The floor function assigns to the real number x the largest
integer that is less than or equal to x and is defined by x . The
ceiling function assigns to the real number x the smallest integer that
is greater than or equal to x .
The value of the ceiling function at x is denoted by ⌈풙⌉
The graph of a floor function The graph of the ceiling function.
3
2
1
-1
-2
-3
-3 -2 -1 1 2 3 o
o
o
o
o
o 3
2
1
-1
-2
-3
-3 -2 -1 1 2 3
o
o
o
o
o
83
Example(18) :
There are some values of the floor and ceiling functions
021
, 1
21
, 1
21
, 0
21
,
31.3 , 41.3 , 77
Example(19) :
Data stored on a computer disk or transmitted over a data
network are usually represented as a string of bytes. Each byte is
made up of 8 bits. How many bytes are required to encode 100 bits
of data?
Solution:
To determine the number of bytes needed, we determine the
smallest integer that is at least as large as the quotient when 100 is
divided by 8, the number of bits is a byte. Consequently,
135.128100 bytes are required.
Exercises :
1) Why is 풇 not a function from ℝ 풕풐ℝ if :
a) 풇(풙) = ퟏ풙
? ( b) 풇(풙) = √풙 ? (c) 풇(풙) = ±√풙ퟐ + ퟏ
2)Determine whether each of these functions from Z to Z is
one- to-one
a) 풇(풏) = 풏 − ퟏ (b) 풇(풏) = 풏ퟐ + ퟏ (c) 풇(풏) = 풏ퟑ (d) 풇(풏) = 풏ퟐ
3) Find these values :
풂)⌊ퟏ. ퟏ⌋ (b) ⌈ퟏ. ퟏ⌉ ( c) ⌊−ퟎ. ퟏ⌋ (d) ⌈−ퟎ. ퟏ⌉
(e) ퟑퟒ
(f) ퟕퟖ
(g) ⌈ퟑ⌉ (h) ⌊−ퟏ⌋
4) Find 풇°품 where풇(풙) = 풙ퟐ + ퟏ and 품(풙) = 풙 + ퟐ, are functions
from R to R.
84
5) Find 풇 + 품 and 풇. 품 for the functions 풇 풂풏풅 품 given in Exercise
(4).
6) Let 풇 be the function from R to R denoted by풇(풙) = 풙ퟐ .Find :
a) 풇 ퟏ({ퟏ}) (b) 풇 ퟏ({풙|ퟎ < 푥 < 1})
85
Chapter 3
Algorithms, the integers and matrices
3.1 Algorithms:
Def.(1): An algorithm is a finite set of precise instructions for
performing a computation or for solving a problem.
Example(1):
Describe an algorithm for finding the maximum (largest) value
in a finite sequence of integers.
Solution:
We perform the following steps :
1- Set the temporary maximum equal to the first integer in the
sequence.
2- Compare the next integer in the sequence to the temporary
maximum, and if it is larger than temporary maximum, set
the temporary maximum equal to this integer.
3- Repeat the previous step if there are more integers in the
sequence.
4- Stop when there are no integers left in the sequence. The
temporary maximum at this point is the largest integer in the
sequence.
Algorithm (1): Finding the maximum element in a finite
sequence.
Procedure max ( naaa ,,, 21 : integers)
max : = 1a
for i: = 2 to n
if max < ia then max : = ia
{max is the largest element}
86
There are several properties that algorithms generally share.
They are useful to keep in mind when algorithms are describes these
properties are:
Input. An algorithms has input values from a specified set.
Output. From each set of input values an algorithm
produces output values from a specified set. The output
values are the solution to the problem.
Definiteness. The steps of an algorithm must be defined
precisely.
Correctness. An algorithm should produce the correct
output values for each set input values.
Finiteness. An algorithm should produce the described
output after a finite (but perhaps large) number of steps for
any input in the set.
Effectiveness. It must be possible to perform each step of an
algorithm exactly and into a finite amount of time.
Generality. The procedure should be applicable for all
problems of the desired farm, not just for a particular set of
input values.
87
3.2 Number Theory
3.2.1 The integers and division:
Def. (2):
if a and b are integers with 0a , we say a that divides b if
there is an integer c (such that acb when a divides b we say that a
is a factor of b and that b is a multiple of a . The notation ba
denoted that a divides b . We write 풂 ∤ 풃 when a doesnot divide b .
Example(2):
Determine whether 73 and 123 .
Solution:
1) ퟑ ∤ ퟕ because 37 is not an integer
2) 123 because 4312 .
Example(3) :
Let n and d be positive integers. Howmany positive integers not
exceeding n are divisible by d ?
Solution:
The positive integers divisible by d are all integers of the form
dk , where k is a positive integer. Hence, the number of positive
integers divisible by d that donot exceed n equals the number of
integers k with ndk 0 or with dnk 0 . Therefore, there are
positive integer not exceeding n that are divisible by d .
Theorem (1):
Let ba, , and c be integers. Then
1- if ba and ca , then )( cba
2- if ba , then bca for all integers c .
3- if ba and cb , then ca .
88
Proof:
Using direct proof of (1) suppose that ba and ca . Then, from
the definition of divisibility, it follows that ths
ere are integers s and t with b = as and c = st hence )( tsaatascb
Therefore, a divides cb .
The proof of (2) and (3) are left as exercise for the reader.
Corollary(1):
If ba, and c are integers such that ba and ca , then ncmba
whenever m and n are integers.
Proof:
We will give a direct proof. By part (2) of theorem (1) it follows
that mca and nca whenever m and n are integers. By part (1) of
theorem (1) it follows that ncmba .
3 .2.2 The division algorithm:
Theorem (2): The division algorithm let a be an integer and d a
positive integer. Then there are unique integers q and r with
dr 0 such that rdqa .
Def.(3): In the equality in the division algorithm, d is called the
divisor, a is called the divided, q is called the quotient, and r is
called the remainder. This notation is used to express the quotient
and remainder. aq Divd, ar modd
Example (4): What are the quotient and remainder when 101 is
divisible by 11?
Solution: We have 101 = 11.9 + 2
9 = 101 div 11
2 101 mod 11
89
Example (5):
What are the quotient and remainder when is divisible by 3.
Solution: -11 = 3(-4) + 1
q = - 4 and r = 1 - 4 = - 11 div 3
1 -11 mod 3
3.3 Modular Arithmetic:
Def.(4):
If a and b are integers and m is a positive integer, then a is
congruent to b modulo m if m divides ba . we use the notation
ba mod m to indicate that a is congruent to b modulo m . If a
and b are not congruent modulo m , we write ba mod m .
Theorem( 3):
Let a and b be integers, and let m be a positive integer. then
mod if and only if a mod = b mod .
Example (6):
Determine whether 17 is congruent to 5 modulo 6 and whether
24 and 14 are not congruent modulo 6.
Solution:
Since 6 divides 17-5 = 12, we say that 17 ≡ 5 mod 6.
Since 24 – 14 = 10 is not divisible by 6
24 ≢ 14 mod 6.
Theorem (4):
Let m be a positive integer. The integers a and b are congruent
modulo m iff there is an integer k such that kmba .
Theorem (5):
Let m be a positive integer if ba mod and dc (mod m ), then
dbca (mod m ) and bdac (mod m ).
90
Proof;
Since ba (mod m ) and
dc (mod m ) ts, with smab and tmcd .
Hence
tsmcatmcsmadb .
and stmcsatmactmcsmabd .
Hence dbca (mod m ) and bdac (mod m ).
Example(7) :
Since 7 ≡ 2 mod 5 and 11 ≡ 1 mod 5
hence 18 = 7 + 11 ≡ 2 + 1 = 3 (mod 5)
and 77 = 7*11 , 2.1 ≡ 2 (mod 5)
Corollary (2);
Let m be a positive integer and let a and b be integers. Then
ba mod m = ((a mod m ) + (b mod m ))
and abmod m = ((a mod m ) (b mod m )) mod m .
Proof:
By the definition mod m and the definition of congruence
modulo m , we know that
ba (a mod m ) (mod m ) and b (b mod m ) (mod m )
Hence, from theorem (5) tells us that
ba (a mod m ) + (b mod m ) (mod m )
and ab (a mod m ) (b mod m ) (mod m )
3.4 Primes and greater common divisor primes:
Def.(4):
A positive integer p greater than 1 is called prime if the only
positive factors of p are 1 and p . A positive integer that is greater
than 1 and is not prime is called composite.
91
Example(8):
The integer 7 is prime since its only positive factors are 1 and 7,
where the integer 9 is composite because it is divisible by 3.
The primes less than 100 are
2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73,
79, 83, 89 , and 97.
Theorem (6): ( The fundamental theorem of arithmetic)
Every positive integer greater than 1 can be written uniquely in
a prime or as the product of two or more primes where the prime
factors are written in order of non decreasing size.
Example(9): Give the prime factorizations of 100, 64, 999 and
1024
Solution: 1. 100 = 2.2.5.5 = 22.52
2. 641 = 641
3. 999 = 3.3.3.37 = 33.37
4. 1024 = 2.2.2.2.2.2.2.2.2.2 = 210
Theorem (7): If n is a composite integer, then has a prime less
than or equal to n .
Example(10): Show that 101 is prime
Solution:
The only are exceeding 101 are 2, 3, 5 and 7. Because 101 is
not divisible by 2, 3, 5 and 7 it follows that 101 is prime.
3.5 Greatest common divisor and least common multiple:
Def.(5):
Let a and b be integers, not both zero. The largest integer
such that ad and bd is called the greatest common divisor of a and
b and is denoted by ),gcd( ba .
92
Example(11) :
What is the greatest common divisor of 24 and 36?
Solution:
The positive common divisors of 24 and 36 are
1, 2, 3, 4, 6 and 12,
Hence gcd (24, 36) = 12.
Example(12) :
What is the greatest common divisor of 17 and 22?
Solution:
The integers 17 and 22 have no positive common divisors other
than 1, so that gcd (17, 22) = 1.
Def.(6):
The integers a and b are relatively prime of their greatest
common divisor is 1. gcd (17, 22) = 1
Example(12):
Determine whether the integers 10, 17 and 21 are pairwise
relatively prime and whether the integers 10, 19 and 24 are pairwise
relatively prime?
Solution:
gcd (10, 17) = 1, (10, 21) = 1,
gcd (17, 21) = 1 hence 10, 17 and 21 are pairwise relatively prime.
Example (13):
1)gcd(300,18)= gcd(12,18)= gcd(12,6)=6
2)gcd(101,100)=gcd(1,100)=1
3)gcd(89,55)=gcd(34,55)= gcd(34,21)=gcd(13,21)=gcd(13,8)
=gcd(5,8 )=gcd(5,3)=gcd(2,3)=gcd(2,1)=1
You can check in each case (using a prime factorization of
the numbers ).
93
Example(14):
The prime factorization of 120 and 500 are 120 = 23 . 3 . 5 and
500 = 22. 53.
the gcd (120, 500) = )3,1min()0,1min()2,3min( 5.3.2 = 22.30.51 = 20
Def.(7):
The least common multiple of the positive integers a and b is
the smallest positive integer that is divisible by both a and b . The
least common multiple of a and b denoted by
),( baLcm nn ban
baba PPP ,max,max2
,max1 ..... 2211
Example(15):
Find Lcm (23.35.72, 24.33) = 2max(3,4).3max(5,3).7max(0,2) = 24.35.72
Theorem(8) :
Let a and b be positive integers. Then ),().,gcd( baLcmbaab
Exercises:
1) Does 17 divides each of these numbers :
a) 68 (b) 84 (c) 357 (d) 1001
2) Show that if a is an integer other than 0 , then :
a) 1 divides a (b) a divides 0
3) What are the quotient and remainder when :
a) 19 is divisible by 7?
b) -111 is divisible by 11 ?
c) 789 is divisible by 23 ?
d) 1001 is divisible by 13 ?
4) Evaluate these quantities:
a) – 17mod 2 (b) 144mod 7 (c) -101mod13 (d) 199mod19
5) List five integers that are congruent to 4modulo12
6) Decide whether which each of these integers is congruent to
5 modulo17 :
94
a) 80 (b)103 (c)-29 (d) -122
7) Determine whether each of these integers is prime :
a) 21 (b) 29 (c) 71 (d) 97 (e) 111 (f) 143 (g) 113 (h) 107.
8) Determine whether the integers in each of these sets are
pairwise relatively prime :
a) 21 , 34 , 55 (b) 14 , 17 ,85 (c) 25 ,41,49 ,64 (d) 17 ,18 ,19 ,23.
9) Find gcd(1000,625) and lcm(1000,625) and verify that
gcd(1000,625).lcm(1000,625)= 1000.625.
10) What are the greatest common divisors of these pairs of
integers:
a) ퟑퟕ. ퟓퟑ. ퟕퟑ, ퟐퟏퟏ. ퟑퟓ. ퟓퟗ
b) 2.3.5.7.11.13, ퟐퟏퟏ. ퟑퟗ. ퟏퟏ. ퟏퟕퟏퟒ
c) 17, ퟏퟕퟏퟕ
d) ퟐퟐ. ퟕ, ퟓퟑ. ퟏퟑ
3.6 Integers and algorithms:
3.6.1 Representation of integers:
In everyday life we used decimal notation to express integers.
For example, 965 is used to denote 9.102 + 6.10 + 5.
However, it is often convenient to use bases other than 10. In
particular computers usually use binary notation (with 2 as a base)
when carrying out arithmetic, and octal (base 8) or hexadecimal
(base 16).
Theorem(9) :
Let b be a positive integer greater than 1. Then if n is positive
integer, it can be expressed uniquely in the form
011
1 abababan kk
kk
95
Example(16):
What is the decimal expansion of the integer that has (1 0101 111)2
as its binary expansion?
Solution: (1 0101 111)2 = 1.28 + 0.27 + 1.26 + 0.25 + 1.24 + 1.23 +1.22 + 1.21
+ 1.20 = 351
Usually, the hexadecimal digits used are 0, 1, 2, 3, 4, 5, 6, 7, 8, 9,
EDCBA ,,,, and F , where the letters A through F represent the
digits corresponding to the numbers 10 through 15 (in decimal
notation).
Example(17):
What is the decimal expansion of the hexadecimal expansion
162AEOB
Solution:
We have
162AEOB = 2.164 + 10.163 + 14. 162 + 0.161 + 11 = (175627)10
3.6.2 Base conversion:
We will now describe an algorithm for constructing the base
expansion of an integer n . First, divide n by b to obtain a quotient
and remainder, that is to obtain
baabqq 1110 0
We see that 1a is the second digit from the right in the base b
expansion of n . Continue this process, successively dividing the
quotient by b , obtaining additional base b digits as the remainders.
This process terminates when we obtain a quotient equal to zero.
Example(18) :
Find the base 8, or octal, expansion of (12345)10
96
Solution:
First, divide 12345 by 8 to obtain 12345 = 8.1543 + 1
1543 = 8.192 + 7
192 = 8.24 + 0
24 = 8.3 + 0
3 = 8.0 + 3
(12345)10 = (30071)8 Example(19) :
Find the hexadecimal expansion of (177130)10
Solution: 177130 = 16.11070 + 10
11070 = 16.691 + 14
691 = 16.43 + 3
43 = 16.2 + 11
2 = 16.0 + 2
(177130)10 = 1632 EAB
Example(20):
Find the binary expansion of (241)10
Solution: 241 = 2.120 + 1
120 = 2.60 + 0
60 = 2.30 + 0
30 = 2.15 + 0
15 = 2.7 + 1
7 = 2.3 + 1
3 = 2.1 + 1
1 = 2.0 +1
(241)10 = (111 1001)2
Example(21): Find the binary form of the non negative integers
up to 10 ?
97
Solution:
0 = (0)2
1 = (1)2
2 = (10)2
3 = 2+ 1 = (11)2
2 = 3 + 1 = (100)2
3 = 4+ 1 = (101)2
4 = 4+2+1 = (110)2
5 = 4 + 2 + 1 =(111)2
6 = 7+1 = (1000)2
7 = 8 + 1 = (1001)2
8 = 8 + 2 = (1010)2
Example(22) :
Find the hexadecimal expansion of (11 1110 1011 11 00)2 and binary
expansion of 168DA
Solution:
To convert (11 1110 1011 1100)2 into hexadecimal notation we
group the binary digits into blocks of four adding initial zeros at the
start of the leftmost block if necessary. These blocks are 0011, 1110,
1011 and 1100 which correspond to the hexadecimal digits BE ,,3 and
C respectively consequently (11 110 1011 1100)2 = )3( EBC
Algorithm(1): constructing base expansion procedure base
expansion ( n : positive integer) nq :
0:k
While 0q
Begin
qak : mod b
98
bLqq /:
1: kk
end {the base b expansion of n is bk aaa 011 }
Hexadecimal octal and binary representation of the integers 0 -15 Decimal 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
Hexadecimal 0 1 2 3 4 5 6 7 8 9 A B C D E F
Octal 0 1 2 3 4 5 6 7 10 11 12 13 14 15 16 17
Binary 0 1 10 11 100 101 110 111 1000 1001 1010 1011 1100 1101 1110 1111
3.6.3 Algorithms for integers operations:
The algorithms for performing operations with integers using
their binary expansions are extremely important in computer
arithmetic. We will describe algorithms for the additional and
multiplication of two integers expressed in binary notation. We will
also analyze the computational complexity of these algorithms, in
terms of the actual number of bit operations used. Throughout this
discussion, suppose that the binary expansion of a and b are
2012120121 , bbbbbaaaaa nnnn
So that a and b each have bits (putting bits equal to 0 at the
beginning of one of these expansions if necessary).
To add a and b , first add their right most bits 0000 2. scba
Where 0s is the rightmost bit in the binary expansion of ba
and 0c is the carry, which is either 0 or 1.
Then 11011 2. sccba
Where 1s , is the next bit (from the right in the binary expansion
of ba and 1c is the carry. Continue this process, adding the
corresponding bits in the two binary expansions and the carry to
determine the next bit from the right in the binary expansion of ba .
99
At the last stage, add 11, nn ba and 2nc to obtain 11 2. nn sc . The
leading bit of the sum is 1 nn cs . This procedure produces the
binary expansion of the sum, namely, 011 ssssba nn
Example(23) : Add 211101a and 211101b
Solution :
12.01000 ba
So that 00 c and 10 s
02.1011111 cba
11 c and 01 s
02.1111222 cba
12 c and 02 s
12.1111333 cba
it follow that 13 c and 13 s
134 cs
211001 bas
111
1110
1011
11001
Algorithm (2) Addition of integers:
Procedure add ( :,ba positive integers)
{ the binary expansions of a and b are 20121 aaaa nn and
20121 bbbb nn respectively}
0:c
for 0:j to 1n
begin
100
2/: cbaLd jj
dcbas jjj 2:
dc :
end
csn :
{the binary expansion of the sum is 201 sss nn }
Multiplication of two n -bit integers a and b
The conventional algorithm (used when multiplying with pencil
and paper) works as follows:
11
11
00 222
nnbbbaab
11
11
00 222
nnbababa
Algorithm (3) Multiplying integers:
Procedure multiply ( :,ba positive integers)
{the binary expansions of a and b are 20121 aaaa nn and
20121 bbbb nn , respectively}
for 0:j to 1n
begin
if 1jb then ac j : shifted j places
else 0jc
end
{ 110 ,,, nccc and partial products}
0:p
for 0:j to 1n
jcpp :
{ p is the value of ab}
Example (24): Find the product of 2110a and 2101b
101
Solution ;
202
00 1102.1.1102. ab
212
11 00002.0.1102. ab
222
22 110002.1.1102. ab
To find the product add 2110 and 211000
21110.1ab
3.6.4 The Euclidean Algorithm:
The method described in section 3.5 for computing the greatest
common divisor of two integers , using the prime factorization of
these integers is inefficient. We will give a more efficient method of
finding the greatest common divisor ,called the Euclidean algorithm .
Before describing the Euclidean algorithm , we will show how it
is used to find gcd(91,287). First ,divide 287 by 91 (the larger of the
two integers by the smaller) to obtain
287 = 91*3+14
Any divisor of 91 and 287 must also be a divisor of 287- 91*3 =
14. Also,any divisor of 91 and 14 must also be a divisor of 287 = 91*3
+ 14. Hence , the greatest common divisor of 91 and 287 is the same
as the greatest common divisor of 91 and 14 . This means that the
problem of finding gcd(91 ,287) has been reduced to the problem of
finding gcd(91,14).
Next ,divide 91 by 14 to obtain
91 = 14*6 + 7
Because any common divisor of 91 – 14*6 = 7 and any common
divisor of 14 and 7 divides 91 , it follows that gcd(91,14) = gcd(14,7)
Continuing by dividing 14 by 7, to obtain
14 = 7*2
Because 7 divides 14 ,it follows that gcd(14,7 ) = 7
102
Hence gcd(287,91) = gcd(91,14) = gcd(14,7) = 7
Lemma:
Let a = bq +r , where a ,b and r are integers . Then
gcd(a,b) = gcd(b,r).
Example (25):
Find gcd(414,662) using the Euclidean algorithm.
Solution:
662 = 414*1+ 248
414 = 248*1 + 166
248 = 166*1 + 82
166 = 82*2 + 2
82 = 2*41
Hence , gcd(414,662) = 2
Algorithm (4) The Eculidean Algorithm:
Procedure gcd(a,b: positive integers )
x :=a
y :=b
while y ≠ 0
begin
r := x mod y
x := y
y := r
end {gcd(a,b) is x }
Exercises:
1) Convert these integers from decimal notation to binary
notation :
a) 231 (b) 4532 (c) 97644 (d) 321 (e) 1023 (f) 100632
103
2) Convert these integers from binary notation to decimal
notation :
a) 1 1111 (b) 10 0000 0001 (c) 1 0 101 0101
d) 110 1001 0001 (e) 1 1011 (f) 10 1011 0101
3) Convert these integers from hexadecimal notation to binary
notation :
a) 80E (b) 135AB (c) ABBA (d) DEFACED
4) Convert (푩푨푫푭푨푪푬푫)ퟏퟔ from its hexadecimal expansion to
its binary expansion .
5) Convert these integers from binary notation to its
hexadecimal notation :
a) 1111 0111
b) 1010 1010 1010
c) 111 0111 0111 0111
6)Convert (a) (ퟏퟎퟏퟏ ퟎퟏퟏퟏ ퟏퟎퟏퟏ)ퟐ (b) (ퟏ ퟏퟎퟎퟎ ퟎퟏퟏퟎ ퟎퟎퟏퟏ)ퟐ
to their hexadecimal expansions.
7) Convert (ퟕퟑퟒퟓퟑퟐퟏ)ퟖ to its binary expansion and
(ퟏퟎ ퟏퟎퟏퟏ ퟏퟎퟏퟏ)ퟐ to its octal expansion .
8) Convert (ퟏퟐퟑퟒퟓퟔퟕퟎ)ퟖ to its hexadecimal expansion and
(푨푩푩ퟎퟗퟑ푩푨푩푩푨)ퟏퟔ to its octal expansion .
9) Use the Euclidean algorithm to find :
(a) gcd(12,18)
(b) gcd(111,201)
104
(c) gcd(1001,1331)
( d) gcd(12345,54321)
(e) gcd(1000,5040)
(f) gcd(9888,6060)
105
Chapter 4
Boolean Algebra
4.1.1 Boolean Functions:
Introduction :
Boolean algebra provides the operations and the rules for
working with the set (0, 1). Electronic and optical switches can be
studied using this set and the rules of Boolean algebra. The three
operations in Boolean algebra that will use most are
complementation, the Boolean sum, and the Boolean product. The
complement of an element, denoted with a bar, is defined by ō = 1
and I = 0. The Boolean sum, denoted by + or by OR, has the
following values:
1+1 = 1, 0+0=0 , 0+1=1+0 =1
1.1= 1, 1.0 = 0 = 0.1 = 0, 0.0 = 0 ,
Example (1):
Find the value of ퟏ. ퟎ + (ퟎ + ퟏ)
Solution:
Using the definitions of complementation, the Boolean sum, and
the Boolean product, it follows that :
ퟏ. ퟎ + (ퟎ + ퟏ) = ퟎ + ퟏ = ퟎ + ퟎ = ퟎ
The complement, Boolean sum, and Boolean product
correspond to the logical operators, , and respectively where 0
corresponds to F (false) and 1 corresponds to T (true) Equalities in
Boolean algebra can be directly translated into equivalences of
compound propositions can be translated into equalities in Boolean
algebra.
106
Example (2): Translate ퟏ. ퟎ + (ퟎ + ퟏ) = ퟎ, into a logical
equivalence.
Solution:
We obtain a logical equivalence when we translate each 1 into a
T, each 0 into a F, each Boolean sum into disjunction, each Boolean
product into a conjunction and each complementation into negation,
we obtain ퟏ. ퟎ + (ퟎ + ퟏ) = ퟎ 푻 푭 (푻 푭) 푭
Example (3): Translate the logical equivalence
(푻 푻) F T into an identity in Boolean algebra.
Solution: (푻 푻) F (1.1) + ō = 1
4.1.2 Boolean Expressions and Boolean Functions:
Def.(1): Let B = (0,1). Then is the set of all possible n-tuples
of 0s and 1s. The variable x is called a Boolean variable if it assumes
values only from B, that is, if its only possible values are 0 and 1. A
function from to is called a Boolean function of degree 풏.
풇: 푩ퟐ → 푩
Example (4): The function 풇(풙, 풚) = 풙풚 from the set of ordered
pairs of Boolean variables to the set {ퟎ, ퟏ} is a Boolean function of
degree 2 ,풇(ퟏ, ퟏ) = ퟏ. 푻 = ퟏ. ퟎ = ퟎ, 풇(ퟏ, ퟎ) = ퟏ. 풐 = ퟏ. ퟏ = ퟏ
풇(ퟎ, ퟏ) = ퟎ. 푻 = ퟎ. ퟎ = ퟎ and 풇(ퟎ, ퟎ) = ퟎ. 풐 = ퟎ. ퟏ = ퟎ
풙 풚 풇(풙, 풚)
1
1
0
0
1
0
1
0
0
1
0
0
107
Example (5): Find the values of the Boolean function
represented by 풇(풙, 풚, 풛) = 풙풚 + 풛.
Solution: The values of this function are displayed in the given
table
Example (6): The function 풇(풙, 풚, 풛) = 풙풚 + 풛 from 푩ퟑ to 푩 can
be represented by distinguishing the vertices that correspond to the
five 3-tuples (1,1,1) , (1,1,0), (1,0,0), (0,1,0) and (0,0,0) where is
shown in the given figure
풙 풚 풛 풙풚 풛 풇(풙, 풚, 풛) = 풙풚 + 풛
1
1
1
1
0
0
0
0
1
1
0
0
1
1
0
0
1
0
1
0
1
0
1
0
1
1
0
0
0
0
0
0
0
1
0
1
0
1
0
1
1
1
0
1
0
1
0
1
108
These vertices are displayed using solid black circles. The Boolean
sum of they function 풇 and 품 and Boolean product of 풇 and 품 are given
by
1) (풇 + 품)(풙ퟏ, 풙ퟐ, … , 풙풏) = 풇(풙ퟏ, 풙ퟐ, … , 풙풏) + 품(풙ퟏ, 풙ퟐ, … , 풙풏)
2) (풇 + 품)(풙ퟏ, 풙ퟐ, … , 풙풏) = 풇(풙ퟏ, 풙ퟐ, 풙풏) + 품(풙ퟏ, 풙ퟐ, … , 풙풏)
100
000
010
110
001
101
011
111
109
4.1.3 Identities of Boolean algebra:
Boolean identities:
Identity Name
풙 = 풙 Law of the double complement
풙 + 풙 = 풙 , 풙. 풙 = 풙 Idempotent lows
풙 + ퟎ = 풙, 풙. ퟏ = 풙 Identity laws
풙 + ퟏ = ퟏ, 풙. ퟎ = ퟎ Domination laws
풙 + 풚 = 풚 + 풙, 풙풚 = 풚풙 Commutative laws
풙 + (풚 + 풛) = (풙 + 풚) + 풛
풙. (풚. 풛) = (풙. 풚). 풛
Associative laws
(풙 + 풚풛) = (풙 + 풚)(풙 + 풛)
풙(풚 + 풛) = 풙풚 + 풙풛
Distributive laws
(풙풚) = 풙 + 풚, (풙 + 풚) = 풙. 풚 Deomorgan’s laws
풙 + 풙풚 = 풙
풙(풙 + 풚) = 풙
Absorption laws
풙 + 풙 = ퟏ Unit property
풙. 풙 = ퟎ Zero property
110
Example (7):
Translate the distributive law풙 + 풚풛 = (풙 + 풚)(풙 + 풛) into a
logical equivalenc
Solution :
풙 + 풚풛 = (풙 + 풚)(풙 + 풛) ≡ 풑(풒풓) ≡ (풑풒)(풑 풓)
Example (8):
Prove the absorption law 풙(풙 + 풚) = 풙 using the other identities
of Boolean algebra.
Solution:
풙(풙 + 풚) = (풙 + ퟎ)(풙 + 풚) identity law for the Boolean sum
= 풙 + ퟎ. 풚 distributive law
= 풙 + 풚. ퟎ commutative law
= 풙 + ퟎ domination law
= 풙 identity law
4.2 Duality:
Def.(2) The dual of a Boolean expression is obtained by
interchanging Boolean sums and Boolean products and
interchanging ퟎ풔 and ퟏ풔.
Example (9):
Find the duals of (1) 풙(풚 + ퟎ) (2) 풙. ퟏ + (풚 + 풛)
Solution:
1) 풙 + (풚. ퟏ)
2) (풙 + ퟎ)(풚. 풛)
Example (10): Construct an identity from the absorption law
풙(풙 + 풚) = 풙 by taking duals.
Solution : 풙 + 풙 . 풚 = 풙
111
4 .3 The abstract definition of a Boolean algebra:
Def. (3): A Boolean algebra is a set 푩 with two binary
operations 풗 and 풏, elements 0 and 1, and a unary operation such
that these properties hold
∀풙, 풚∀, 풛 ∈ 푩
�풙 ∨ 풙 = 풙풙 ∧ 풙 = 풙 identity law.
�풙 ∨ 풙 = ퟏ풙 ∧ 풙 = ퟎ Commutative laws.
�(풙풚)풛 = 풙(풚풛)(풙풚)풛 = 풙(풚풛) Associative laws.
�풙풚 = 풚풙풙풚 = 풚풙 Commutative laws.
�풙(풚 풛) = (풙 풚) (풙풛)풙(풚 풛) = (풙 풛) (풙풛) Distributive laws.
4.4 Representing Boolean Functions:
Example (11): Find Boolean expressions that represent the
functions 풇(풙, 풚, 풛) and 품(풙, 풚, 풛), which are given in the table
풙 풚 풛 풇 품
1 1 1 0 0
0
1 0 1 1 0
1 0 0 0 0
0 1 1 0 0
0 1 0
0 0 1 0 0
0 0 0 0 0
1 1 0 1
0 1
112
Solution :
1) An expression that has the value 1 when 풙 = 풛 = ퟏ and
풚 = ퟎ and value otherwise, is needed to represent 풇. Such
an expression can be formed by taking the Boolean product
of 풙, 풚 and 풛. This product, 풙풚풛 has the value if 풙 = 풚 =
풛 = ퟏ which holds iff 풙 = 풛 − ퟏ and 풚 = ퟎ.
2) To represent 품, we need an expression that equals 1 when
풙 = 풚 = ퟏ and 풛 = ퟎ or when 풙 = 풛 = ퟎ and 풚 = ퟏ. We can
form an expression with these values by taking the Boolean
sum of two different Boolean products. the Boolean product
풙풚풛 has the value 1 iff 풙 = 풚 = ퟏ and 풛 = ퟎ. Similarly, the
product 풙풚풛 has the value 1 iff 풙 = 풛 = ퟎ and 풚 = ퟏ. The
Boolean sum of these two products 풙풚풛 + 풙풚풛 represents 품.
Def.(4): A literal is a Boolean variable or its complement. A
minterm of the Boolean variables 풙ퟏ, 풙ퟐ, … . , 풙풏 is the Boolean
product 풚ퟏ풚ퟐ …. 풚풏 where 풙풊 = 풚풊 or 풚풊 = 풙i. Hence a minterm is
a product of n literals, with one literal for each variable.
Example (12):
Find a minterm that equals 1 if 풙ퟏ = 풙ퟑ = ퟎ
and 풙ퟐ = 풙ퟒ = 풙ퟓ = ퟏ, and equals 0 otherwise.
Solution:
The minterm 풙ퟏ풙ퟐ풙3.풙ퟒ풙ퟓ has the correct set of values.
Example (13):
Find the sum-of-products expansion of the function
풇(풙, 풚, 풛) = (풙 + 풚)풛.
Solution:
풇(풙, 풚, 풛) = (풙 + 풚)풛
113
= 풙풛 + 풚풛 distributive law
= 풙ퟏ풛 + ퟏ풚풛 identity law
= 풙(풚 + 풚)풛 + (풙 + 풙)풚풛 unit property
= 풙풚풛 + 풙풚풛 + 풙풚풛 + 풙풚풛 distributive
law.
= 풙풚풛 + 풙풚풛 + 풙풚풛 idempotent law퐬.
4.5 Logic gates:
Introduction: Boolean algebra is used to model the circuitry
electronic devices. Each input and each output of each device can be
thought of as a member of the set {ퟎ, ퟏ}. A computer, or other
electronic device, is made up of a number of circuits.
x
y
Inverter OR gate AND gate
X1
X2x
Xn
gates with n inputs
4.6 Combinations of Gates:
Example (14):
Construct circuits that produce the following out puts:
(a) (풙 + 풚)풙 (b) 풙 (풚 + 풛) (c) (풙 + 풚 + 풛) (풙풚풛)
X1+x2+..+xn
114
Solution:
a)
b)
c) x+y+z
(x ( x.y)푥̅
(
115
4.7 Minimization of Circuits:
Example (15):
Minimize and construct the out put circuit 풙풚풛 + 풙풚풛
Solution: 풙풚풛 + 풙풚풛 = (풚 + 풚)풙풛
= ퟏ. 풙풛
= 풙풛
4.8 Karnaugh Maps:
To reduce the number of terms in a Boolean expression
representing a circuit, it is necessary to find terms to combine. There
is a graphical method, called a Karnaugh map or K-map for finding
terms to combine for Boolean functions involving a relatively small
number of variables.
Example (2): Find the K-maps for:
(a) 풙풚 + 풙풚
(b) 풙풚 + 풙풚
(c) 풙풚 + 풙풚 + 풙풚
116
Solution:
풚 풚 풚 풚 풚 풚
풙 1 1 풙
1 풙 1
풙 1 풙 1 풙 1 1
(a) (b) (c)
Example (16): Simplify the sum-of-products expansion for
(a) 풙풚 + 풙풚 (b) 풙풚 + 풙풚 (c) 풙풚 + 풙 풚 + 풙풚
Solution : (a) 풙풚 + 풙풚 = (풙 + 풙)풚 = ퟏ. 풚 = 풚
b) 풙풚 + 풙풚 = 풙풚 + 풙풚
c) 풙풚 + 풙풚 + 풙풚 = 풙풚 + 풙(풚 + 풚)
= 풙풚 + 풙. ퟏ
= 풙 + 풚
Example (17): Use the K-maps to minimize these sum-of-
products expansions
a) 풙풚풛 + 풙풚풛 + 풙풚풛 + 풙풚풛
b) 풙풚풛 + 풙풚풛 + 풙풚풛 + 풙풚풛 + 풙풚풛
c) 풙풚풛 + 풙풚풛 + 풙풚풛 + 풙풚풛 + 풙풚풛 + 풙풚풛 + 풙풚풛
d) 풙풚풛 + 풙풚풛 + 풙풚풛 + 풙풚풛
Solution:
풚풛 풚풛 풚풛 풚풛 풚풛 풚풛 풚풛 풚풛
풙 1 1 풙 1 1
풙 1 1 풙 1 1 1
(a) 풙풛 + 풚풛 + 풙풚풛 (b) 풚 + 풙풛
117
풚풛 풚풛 풚풛 풚풛 풚풛 풚풛 풚풛 풚풛
풙 1 1 1 1 풙 1 1
풙 1 1 1 풙 1 1
(c) 풙 + 풚 + 풛 (d) 풙풛 + 풙풚
Exercises:
1) Find the output of the given circuits:
a)
b)
c)
2) Construct circuits from inverters, AND gates and OR gates to
produce these out puts.
(a) 풙 + 풚 (b) (풙 + 풚)풙 (c) 풙풚풛 + 풙풚풛 (d) (풙 + 풛)(풚 + 풛)
x
y
y
x
y
y
x
x
z
118
3) Draw a k–map for a function in two variables and put a 1 in the
cell representing 풙풚
4) Draw the k–maps of these sum-of-products expansions in two
variables:
(a) 풙풚 (b) 풙풚 + 풙풚 (c) 풙풚 + 풙풚 + 풙풚 + 풙풚
119
Chapter 5
An Introduction to Graph Theory
Def.(1): A graph 푮 = (푽, 푬) consists of 푽, a nonempty set of vertices
(nodes) and 푬, a set of edges. Each edge has either one or two vertices
associated with it , called its endpoints. An edge is said to connect the end
points.
Remark: The set of vertices 푽 of a graph 푮 may be finite. A
graph with an infinite vertex set is called an infinite graph, and in
comparison, a graph with a finite vertex set is called a finite graph,
here we consider only finite graphs.
Now suppose that a network is made up of data centers and
communication links between computers. We can represent the
location of each data center by a point and each communication link
by a line segment as shown in the figure
This computer network can be modeled using a graph in which
the vertices of the graph represent the data centers and edges
represent communication links. A graph in which each edge
connects two different vertices and where no two edges connect the
same pair of vertices is called a simple graph.
Jedda
Mekka
Medina
Riadh
Hafoof
Demam
Hafralbatin
120
Def.(2): A directed graph (diagraph) (푽, 푬)consists of nonempty
set of vertices 푽 and a set of directed edges (or arcs) 푬, each directed
edge is associated with an ordered pair of vertices. The directed edge
associated with the ordered pair (풖, 풗) is said to start a 풖 and end at
풗.
A graph with no loops and has no simple directed edges is called
a simple directed graph.
5 .1 Basic Terminology:
Def.(3):
Two vertices 풖 and 풗 in an undirected graph 푮 are called
adjacent (neighbours) in 푮 if 풖 and 풗 are endpoints of an edge of 푮.
If 풆 is associated with {풖, 풗} the edge e is called incident with the
vertices 풖 and 풗. The edge 풆 is also said to connect 풖 and 풗. The
vertices 풖 and 풗 called end points of an edge associated with {풖, 풗}.
Def.(4):
The degree of a vertex in an undirected graph is the number of
edges incident with it, except that a loop at a vertex contributes twice
to the degree of that vertex. The degree of the vertex 풗 is denoted by
deg (풗).
Example (1):
What are the degrees of the vertices in the graphs 푮 and 푯 in the
given figures
G H
a f e
c d b
e d
b c a
121
Solution:
In 푮 ∶ deg (풂) = 2, deg (풃) = deg (풄)= deg (풇)= 4 , deg (풅) = 1
and deg (품) = 0.
In 푯 ∶ deg (풂) = 4, deg (풃) = deg (풆)= 6, deg (풄) = 1 and deg (풅) =
5.
A vertex of degree zero is called isolated, a vertex is pendant iff it
has degree one.
Example (2):
What does the degree of a vertex in a niche overlap graph
represents? Which vertices in this graph are pendant and which are
isolated in the given figure
Solution:
There is an edge between two vertices in a niche overlap graph
iff the two species represented by these vertices complete. Hence, the
degree of a vertex in a niche overlap graph is the number of species
in the ecosystem that complete with the species represented by this
vertex.
The degree of the vertex representing the squirrel is 4 because
the squirrel competes with four other species: the crow, the
Crow
Owl Raccoon
Opossum Squirrel
Hawk
Wood pecker Shrew Mouse
122
opossum, the raccoon and the wood pecker. The mouse is the only
species represented by a pendant vertex. The vertex representing a
species is pendant if this species competes with only one other species.
There are no isolated vertices.
Theorem(1): (The handshaking theorem)
Let 푮 = (푽, 푬) be an undirected graph with 풆 edges. Then
ퟐ풆 = 퐝퐞퐠(풗)풗∈푽
Example (3): How many edges are there in a graph with 10
vertices each of degree 6?
Solution: Because the sum of the degrees of the vertices is 6.10
= 60, it follows that 2e = 60 e = 30.
Theorem(2): An undirected graph has an even number of
vertices of odd degrees.
5 .2 Some Special Simple Graphs:
Example (4): (Complete graphs) The complete graph on n
vertices, denoted by 풌풏, is the simple graph that contains exactly one
edge between each pair of district vertices as shown in the figures:
. . .
k1 k2
k3 k4 k5 k6
Example (5): (cycles)
The cycles 푪풏, 풏 ≥ ퟑ, consists of n vertices 풗ퟏ, 풗ퟐ … , 풗풏 and
edges {풗ퟏ, 풗ퟐ} , {풗ퟐ, 풗ퟑ} … , {풗풏 ퟏ, 풗풏} 풂풏풅 {풗풏, 풗ퟏ} .The cycles
푪ퟑ, 푪ퟒ, 푪ퟓ, 풂풏풅 푪ퟔ, are displayed in the figure:
123
c3 c4 c5 c6
Example (6): (wheels) We obtain the wheel 푾풏 when we add
additional vertex to the cycle 풄풏 풇풐풓 풏 ≥ ퟑ and connect this new
vertex to each of n vertices in 풄풏, by new edges th wheels
푾ퟑ, 푾ퟒ, 푾ퟓ, 푾ퟔ, are displayed in the figure:
푾ퟑ 푾ퟒ 푾ퟓ 푾ퟔ
Example (7): (n-cubes)
The n-dimentional hypercuble or n-cube, denoted by 푸풏 is the
graph that has vertices representing the ퟐ풏 bit strings of length n.
푮ퟏ
푮ퟐ
푮ퟑ
5.3 Bipartite graphs:
Def.(5): A simple graph 푮 is called bipartite if its vertex set V
can be partitioned into two disjoint sets 푽ퟏ and 푽ퟐ such that every
edge in the graph connects a vertex in 푽ퟏ and a vertex in 푽ퟐ. When
1 0
100
000 001
011
111 110
101
010
00
10 11
01
124
this condition holds, we call the pair (푽ퟏ, 푽ퟐ) a bipartition of the
vertex set 푽 of 푮.
In example (3) 풄ퟔ is a bipartite.
Example (8):
풄ퟔ in the given figure is
bipartite because its vertex
set can be partitioned into
the two sets 푽ퟏ = {풗ퟏ, 풗ퟑ, 풗ퟓ}
and 푽ퟐ = {풗ퟐ, 풗ퟒ, 풗ퟔ} and
every edge of 풄ퟔ connects a
vertex in 푽ퟏ and a vertex in
푽ퟐ.
Theorem(3):
In every graph , the number of nodes with odd degree is even .
Proof: We start with a graph with no edges in which every degree is 0
And so the number of nodes with odd degree is 0 , which is an even
number.
(1) If we connect two nodes by a new edge , we change the parity of
the degrees at these nodes . In particular, if both endpoints of
the new edge have even degree , we increase the number of
nodes with odd degree by 2 .
(2) If both endpoints of the new edge had odd degree , we decrease
the number of nodes with odd degree by 2. ,
(3) If one endpoint of the new edge had even degree and the other
had odd degree.
125
Thus if the number of nodes with odd degree was even before
adding the new edge, it remained even after this step .This proves
the theorem.
Theorem (4): (a) A graph G is a tree if and only if it is connected , but
deleting any of its edges , results in a disconnected graph .
(b) A graph G is a tree if and only if it contains no cycle , but
adding any new edge creates a cycle.
Theorem (5): Every tree on n nodes has n-1 edge.
5. 4 Representing Graphs and Graph Isomorphism:
Representing Graphs ; One way to represent a graph without
multiple edges is to list all the edges of this graph. Another way to
represent a graph with no multiple edges is to use adjacency lists,
which specify the vertices that are adjacent to each vertex of the
graph.
Table ( 1)An adjacency list for a simple graph
vertex Adjacency
vertices
a
b
c
d
e
b, c, e
a
a, d, c
c, e
a, c, d
e
c
d
b
a
126
Example (9):
Use adjacency lists to describe the simple graph given in the
above figure.
Solution: Table 1 lists those vertices adjacent to each of the
vertices of the graph.
Example (10): Represent the directed graph shown in figure (2)
by listing all the vertices that are the terminal vertices of edges
starting at each vertex of the graph
directed graph
Figure (2)
Solution: Table (2) represent the directed graph shown in figure
(2) above.
5.5 Adjacency Matrices:
The adjacency matrix 푨 of 푮 with respect to the listing of
vertices, is the 풏 × 풏 zero-one matrix with 1 as its (풊, 풋)풕풉 entry
when 풗풊 and 풗풋 are adjacent, and 0 as its (풊, 풋)풕풉entry when they are
not adjacent 푨 = 풂풊풋 , then 풂풊풋 = ퟏퟎ
� if 풗풊, 풗풋 is edge of 푮
otherwise
Initial vertex Terminal
vertices
a
b
c
d
e
b, c, d, e
b, d
a, c, e
b, c, d
a
b
c
d e
127
Example (11): Use an adjacency matrix to represent the graph
shown in the figure :
a b
c d
Solution:
We order the vertices as a, b, c, d. The matrix representing this
graph is
⎣⎢⎢⎢⎡
0001001101011110
⎦⎥⎥⎥⎤
Example (12):
Draw the graph with this adjacency matrix
⎣⎢⎢⎢⎡
0110100110010110
⎦⎥⎥⎥⎤
with respect to the ordering of vertices a, b, c, d.
a b
c d
Figure (4)
128
Example (13):
Use an adjacency matrix to represent the pseudograph shown in
figure (5)
Figure (5)
A Pseudograph
Solution:
The adjacency matrix using the ordering of vertices a, b, c, d is
⎣⎢⎢⎢⎡
0212211011032030
⎦⎥⎥⎥⎤
5.6 Incidence Matrices:
Another common way to represent graphs is to use incidence
matrices. Let 푮 = (푽, 푬) be an undirected graph. Suppose that
풗ퟏ, 풗ퟐ, … , 풗풏 are vertices and 풆ퟏ, 풆ퟐ, … , 풆풎 are the edges of 푮. Then
the incidence matrix with respect to this ordering of 푽 and 푬 is the
풏 × 풎 matrix 푴 = 풎풊풋 , where
풎풊풋 = ퟏ 퐰퐡퐞퐧 퐞퐝퐠퐞 풆풋 퐢퐬 퐢퐧퐜퐢퐝퐞퐧퐭 퐰퐢퐭퐡 풗풊 ퟎ 퐨퐭퐡퐞퐫퐰퐢퐬퐞
�
Example (14):
Represent the graph shown in figure 6 with an incidence matrix.
a
d
b
c
129
Solution:
The incidence matrix is:
풆ퟏ 풆ퟐ 풆ퟑ 풆ퟒ 풆ퟓ 풆ퟔ
⎣⎢⎢⎢⎡ퟏ ퟏ ퟎퟎ ퟎ ퟏퟎ ퟎ ퟎ
ퟎ ퟎ ퟎퟏ ퟎ ퟏퟎ ퟏ ퟏ
ퟏ ퟎ ퟏퟎ ퟏ ퟎ ퟎ ퟎ ퟎ
ퟏ ퟏ ퟎ⎦⎥⎥⎥⎤
Figure 7
A Pseudo graph
Example (15):
Represent the pseudo graph shown in the figure using incidence
matrix
풆ퟏ 풆ퟐ 풆ퟑ 풆ퟒ 풆ퟓ 풆ퟔ 풆ퟕ 풆ퟖ
⎣⎢⎢⎢⎡ퟏ ퟏ ퟏퟎ ퟏ ퟏퟎ ퟎ ퟎ
ퟎ ퟎ ퟎퟏ ퟎ ퟏퟏ ퟏ ퟎ
ퟎퟏퟎ
ퟎퟎퟎ
ퟎ ퟎ ퟎퟎ ퟎ ퟎ ퟎ ퟎ ퟎ
ퟎ ퟏ ퟏ ퟏ ퟎ
ퟏퟎ⎦
⎥⎥⎥⎤
A Pseudograph
5.6 Isomorphism of Graphs:
Def.(6): The simple graphs 푮ퟏ = (푽ퟏ, 푬ퟏ) and 푮ퟐ = (푽ퟐ, 푬ퟐ)
are isomorphic if there is a one-to-one and onto function from 푽ퟏ to
푽ퟐ with the property that 풂 and 풃 are adjacent in 푮ퟏ iff 풇(풂) and
풇(풃) are adjacent in 푮ퟐ ∀풂, 풃 ∈ 푽ퟏ. such function f is called
isomorphism.
v1 v2
e1 e3
e2 e4 v3
v5
e5 e6
e7
v4 e8
130
Example (16):
Show that the graphs 푮 = (푽, 푬) and 푯 = (푾, 푭), displayed in
figure 8, are isomorphic.
Solution:
The function f with 풇(풖ퟏ) = 풗ퟏ, 풇(풖ퟐ) = 풗ퟒ , 풇(풖ퟑ) =
풗ퟑ, 풇(풖ퟒ) = 풗ퟐ is one-to-one correspondence between V and W. To
see that this correspondence presents adjacency, note that adjacent
vertices in 푮 are 풖ퟏ and 풖ퟐ, 풖ퟏ and 풖ퟑ, 풖ퟐ and 풖ퟒ, and 풖ퟑ and 풖ퟒ,
and each of the pairs 풇(풖ퟏ) = 풗ퟏ and 풇(풖ퟐ) = 풗ퟒ, 풇(풖ퟏ) = 풗ퟏ and
풇(풖ퟑ) = 풗ퟑ, 풇(풖ퟐ) = 풗ퟒ and 풇(풖ퟒ) = 풗ퟐ and 풇(풖ퟑ) = 풗ퟑ and
풇(풖ퟒ) = 풗ퟐ are adjacent in H .
Example (17):
Show that the graphs displayed in the figure are not
isomorphic.
G
G
H
131
Solution:
Both G and H have five vertices and six edges. However, H has
a vertex of degree one, namely e, whereas G has no vertices of degree
one. It follows that G and H are not isomorphic.
Exercises:
In exercise 1 – 3 find the number of vertices, the number of edges,
and the degree of each vertex in the given undirected graph
1) 2)
3)
4) Draw these graphs:
(a) 푲ퟕ (b) 푲ퟏ,ퟖ (c) 푲ퟒ,ퟒ
(d) 푪ퟕ (e) 푾ퟕ (f) 푸ퟒ
a b c
f e . d
a b
e d c
a
i . f
. d
h g
b c
132
5) In Exercises 1 – 4 use an adjacency list to the given graph
1) 2)
3) 4)
6) Draw a graph with the given adjacency matrices
a) ퟎ ퟏ ퟎퟏ ퟎ ퟏퟎ ퟏ ퟎ
(b) ퟎ ퟎퟎ ퟎ ퟏ ퟏ
ퟏ ퟎퟏ ퟏퟏ ퟏ ퟎ ퟏ
ퟏ ퟎ
5.8.1 Paths: A path is a sequence of edges that begins at a vertex
of a graph and travels from vertex to vertex along edges of the graph.
Def. (7): Let n be a nonnegative integer and G an undirected
graph. A path of length n from u to v in G is a sequence of n edges
풆ퟏ, 풆ퟐ, … , 풆풏 of G such that 풆ퟏ is associated with {풙ퟎ, 풙ퟏ}, 풆ퟐ is
associated with {풙ퟏ, 풙ퟐ} and so on, with 풆풏 associated with {풙풏 ퟏ, 풙풏}
where 풙ퟎ = 풖 and 풙풏 = 풗. When the graph is simple we denote this
path by its vertex sequence 풙ퟎ, 풙ퟏ, … , 풙풏. The path is a circuit if it
begins and end at the same vertex, that is, if u = v, and has length
greater than zero. The path or circuit is said to pass through the
vertices 풙ퟏ, 풙ퟐ, … , 풙풏 ퟏ or traverse the edges 풆ퟏ, 풆ퟐ, … , 풆풏. A path or
circuit is simple if it does not contain the same edge more than once.
a c
d
b
e
a
c d
b
a
c d
b a c
d
b
e
133
Example (18):
In the simple graph in the figure
a b c
d e f
Simple graph
a, d, c, e, f is a simple path of length 4, because {풂, 풅}, {풅, 풄},
{풄, 풇} and {풇, 풆} are all edges.
However, d, e, c, a is not a path, because {풆, 풄} is not an edge. Note
that b, c, f, e, b is a circuit of length 4 because {풃, 풄}, {풄, 풇}, {풇, 풆} and
{풆, 풃} are edges, and this path begins and ends at b. The path a, b, e, d,
a, b which is of length 5, is not simple because it contains the edge
{풂, 풃} twice.
5.8.2 Connectedness in Undirected Graphs:
Def. (8): An undirected graph is called connected if there is a
path between every pair of distinct vertices of the graph.
Thus, any two computers in the network can communicate iff
the graph of this network is connected.
134
Example (19):
The graph 푮ퟏ in the given figure:
is connected, because for every pair of d distinct vertices there is a
path between them. However, the graph 푮ퟐ in the figure is not
connected. There is no path in 푮ퟐ between vertices a and d.
Theorem (3):
There is a simple path between every pair of distinct vertices of
a connected undirected graph.
A connected component of a graph G is a connected subgraph of
G that is not proper subgraph of another connected subgraph of G.
That is, a connected component of a graph G is a maximal connected
subgraph of G. a graph G that is not connected has two or more
connected components that are disjoint and have G as their union.
a b
e
f d
c
a b
f d
e
c
135
Example (20):
What are the connected components of the graph H shown in the
figure:
The connected components 푯ퟏ, 푯ퟐ and 푯ퟑ
Solution:
The graph H is the union of three disjoint connected subgraphs
푯ퟏ, 푯ퟐ and 푯ퟑ. These three subgraphs are the connected
components of H.
5.8.3 Connected in directed graphs:
Def. (9): A directed graph is strongly connected if there is a
path from a to b and from b to a whenever a and b are vertices in the
graph.
Def. (10): A directed graph is weakly connected if there is a
path between every two vertices in the underlying undirected graph.
That is, a directed graph is weakly connected iff there is always
a path between two vertices when the directions of the edges are
disregarded. Any strongly connected directed graph is also weakly
connected.
d e
퐻
b
a c
퐻
e g
f 퐻
136
Example (21):
Are the directed graphs G and H shown in the figure:
The directed graphs G and H.
Strongly connected?. Are they weakly connected?
Solution:
G is strongly connected because there is a path between any two
vertices in this directed graph (verify). Hence, G is also weakly
connected. The graph H is not strongly connected. There is no
directed path from a to b in this graph. However, H is weakly
connected, because there is a path between any two vertices in the
underlying undirected graph of H (verify).
5.8.4 Counting paths between vertices:
The number of paths between two vertices in a graph can be
determined using its adjacency matrix.
Example (22):
Let G be a graph with adjacency matrix A with respect to the
ordering 풗ퟏ, 풗ퟐ, … , 풗풏 (with directed or undirected edges, with
multiple edges and loops allowed). The number of different paths of
length 풓 from 풗풊 to 풗풋, where 풓 is a positive integer, equals the (i, j)th
entry of 푨풓.
a b
c
e G d
a b
c
e d H
137
Example (23):
How many paths of length 4 are there from a to d in the simple
graph G in the figure
Figure
Solution:
The adjacency matrix of G (ordering the vertices as a, b, c, d) is
푨 =
⎣⎢⎢⎢⎡
0110100110010110
⎦⎥⎥⎥⎤
Hence, the number of paths of length 4 from a to d is the (1,4)th
entry of A4.
푨ퟒ =
⎣⎢⎢⎢⎡
8008088008808008
⎦⎥⎥⎥⎤
Because there are exactly eight paths of length 4 from a to d. By
inspection of the graph, we see that a, b, a, b, d; a, b, a, c, d; a, b, d, b,
d; a, b, d, c, d; a, c, a, c, d; a, c, d, b, d; and a, c, d, c, d are the eight
paths from a to d.
a b
c d
138
5.9 .1 Eulr and Hamilton Paths:
Def. (11): An Euler circuit in a graph G a simple circuit
containing every edge of G. An Euler path in G is a simple path
containing every edge of G.
Example(24):Which of the undirected graphs in the figure have
an Euler circuit? Of those that do not, which have an Euler path?
Solution: The graph 푮ퟏ has an Euler circuit, for example, a, e, c,
d, e, b, a. Neither of the graphs 푮ퟐ or 푮ퟑ has an Euler circuit
(verify). However, 푮ퟑ has an Euler path, namely, a, c, d, e, b, d, a, b.
푮ퟐ does not have an Euler path (verify).
a b
d c
e
d c
b a
e
b a
d c e
139
Example (25): Which of the directed graphs in the figure have
an Euler circuit? Of those that do not, which have an Euler path?
Solution:
The graph H2 has an Euler circuit, for example, a, g, c, b, g, e, d,
f, a. Neither H1 nor H3 has an Euler circuit (verify). H3 has an Euler
path namely, c, a, b, c, d, b, but H1 does not (verify)
5.9.2 Hamilton Paths and Circuits:
Def.(12):
A simple path in a graph G that passes through every vertex
exactly once is called a Hamilton path, and a simple circuit in a
graph G that passes through every vertex exactly once is called a
Hamilton circuit. That is, the simple path 풙ퟎ, 풙ퟏ, … , 풙풏 in the graph
푮 = (푽, 푬) is a Hamilton path if 푽 = {풙ퟎ, 풙ퟏ, … , 풙풏} and 풙풊 ≠ 풙풋 for
ퟎ ≤ 풊 < 푗 ≤ 푛, and the simple
circuit풙ퟎ, 풙ퟏ, … , 풙풏 , (풏 > 0)퐢퐬 퐚 퐇퐚퐦퐢퐥퐭퐨퐧 퐜퐢퐫퐜퐮퐢퐭 if 풙ퟎ, 풙ퟏ, … , 풙풏 is
a Hamilton path.
Example (26):
Which of the simple graphs in the figure have a Hamilton circuit
or, if not, a Hamilton path?
f
a
b
d e
a b
d c
c d
b a
140
Simple graphs
Solution: 푮ퟏ has a Hamilton circuit a, b, c, d, e, a. There is no
Hamilton circuit in 푮ퟐ (this can be seen by noting that any circuit
containing every vertex must contain the edge {풂, 풃} twice), but
푮ퟐdoes have a Hamilton path, namely, a, b, c, d. 푮ퟑhas neither a
Hamilton circuit nor a Hamilton path, because any path containing
all vertices must contain one of the edges {풂, 풃}, {풆, 풇} and {풄, 풅} more
than once.
Example (27):
Show that neither graph displayed in the given figure has a
Hamilton circuit.
Solution:
There is no Hamilton circuit in G because G has a vertex of
degree one, namely, e. Now consider H. Because the degrees of
vertices a, b, d and e are all two, every edge incident with these
vertices must be part of any Hamilton circuit. It is now easy to see
that no Hamilton circuit can exist in H, for any Hamilton circuit
would have to contain four edges incident with c, which is impossible.
a b a b a b
e c d c d c e f
d
a
b
G c
d e a
e b H
c
d
141
Theorem (4): (Dirac’s Theorem) If G is a simple graph with n
vertices with 풏 ≥ ퟑ such that the degree of every vertex in G is at
least 풏/ퟐ, then G has a Hamilton circuit.
Theorem (5): (Ore’s Theorem)
If G is a simple graph with n vertices with 풏 ≥ ퟑ such that
deg(u) + deg(v) n for every pair of nonadjacent vertices u and v in
G, then G has a Hamilton circuit.
5.10 Planar Graphs:
Def. (13):
A graph is called planar if it can be drawn in the plane without
any edges crossing (where a crossing of edges is the intersection of the
lines or arcs representing them at a point other than their common
endpoint). Such a drawing is called a planar representation of the
graph.
A graph may be planar even if it is usually drawn with
crossings, because it may be possible to draw it in a different way
without crossings.
Example (28):
Is K4 (shown in the given figure with two edges crossing) planar?
K4 K4
drawn with no crossings.
Solution: K4 is planar because it can be drawn without crossings.
Example (29): Is Q3, shown in the given figure, planar?
142
Q3 Aplanar
representing of Q3
Solution:
Q3 is planar, because it can be drawn without any edges
crossing.
Theorem(6): (Euler’s Formula):
Let G be a connected planar simple graph with e edges and v
vertices. Let r be the number of regions in a planar representation of
G. Then r = e – v + 2.
Example (30):
Suppose that a connected planar simple graph has 20 vertices,
each of degree 3. Into how many regions does a representation of this
planar graph split the plane?
Solution:
This graph has 20 vertices, each of degree 3, so v = 20. Because
of the sum of the degrees of the vertices, 3v = 3.20 = 60, is equal to
twice the number of edges, 2e we have 2e = 60 e = 30.
Consequently, from Euler’s formula, the number of regions is:
r = e – v + 2 = 30 – 20 + 2 = 12.
Corollary (1):
If G is a connected planar simple graph with e edges and v
vertices, where 풗 ≥ ퟑ, then 풆 ≤ ퟑ풗 − ퟔ.
143
Corollary (2):
If G is a connected planar simple graph, then G has a vertex of
degree not exceeding five.
Example (31): Show that K5 is nonplanar using corollary (1)
Solution: The graph K5 has vertices and 10 edges. However, the
inequality 풆 ≤ ퟑ풗 − ퟔ is not satisfied for this graph because e = 10
and ퟑ풗 − ퟔ = ퟗ (ퟏퟎ ≤ ퟗ). Therefore, K5 is not planar.
Corollary (3): If a connected planar simple graph has e edges
and v vertices with 풗 ≥ ퟑ and no circuits of length 3 , then
풆 ≤ ퟐ풗 − ퟒ
Example (32): Use corollary( 3) to show that K3.3 is nonplanar.
Solution: Because K3.3 has no circuits of length 3 (this is easy to
see because it is bipartite), corollary (3) can be used. K3.3 has 6
vertices and 9 edges. Because e=9 and 2v-4 = 8
K3.3 is non planar.
Exercises:
1) Does each of these lists of vertices form a path in the following
graphs? Which paths are simple? Which are circuits? What
are the lengths of those that are paths?
(a) a, e, b, c, b (b) a, e, a, d, b, c, a
(c) e, b, a, d, b, e (d) c, b, d, a, e, c
2) Determine whether the given graph is connected
144
3) Determine whether the given graph has an Euler circuit.
construct such a circuit when one exists. If no Euler circuit
exists, determine whether the graph has an Euler path and
construct such a path if one exists.
4) Does the graph have a Hamilton path? If so find, such a path.
If it doesnot, give an argument to show why no such path exists
a
e
d
c
b
a
b
c f
e
d
145
Chapter (6)
Counting 6.1 Basic Counting Principles:
We will present two basic counting principles, the product rule
and the sum rule.
The Production Rule: The product rule applies when a
procedure is made up to separate tasks.
Example (1)
There are 32 microcomputers in a computer centre. Each
microcomputer has 24 parts. How many different parts to a
microcomputer in the center are there?
Solution:
Because there are 32 ways to choose the microcomputer and 24
ways to choose the part no matter which microcomputer has been
selected, the product rule shows that there are 32*24 = 768 parts.
Example (2)
How many functions are there from a set with m elements to a
set with n elements?
Solution:
A function corresponds to a choice of one of the n elements in
the codomain for each of the m elements in the domain. Hence by
the product rule there are n.n. ….. n = nm functions
From a set with m elements to one with n elements.
6.2 The Sum Rule:
If a task can be done either in one of n1 ways or in one of n2
ways, where none of the set of n1 ways is the same as any of the set of
n2 ways, there are n1 + n2 ways to do the task.
146
Example (3):
Suppose that either a member of the mathematics faculty or a
student who is a mathematics major is chosen as a representive to a
university committee. How many different choices are there for this
representive if there are 37 members of the mathematics faculty and
83 mathematics majors and no one is both a faculty member and a
student?
Solution:
There are 37 ways to choose a member of the mathematics
faculty and there are 83 ways to choose a student who is mathematics
major. Choosing a member of the mathematics faculty is never the
same as choosing a student who is a mathematics major because no
one is both a faculty member and a student. By the sum rule it
follows that there are 37 + 83 = 120 possible ways to pick this
representive.
Example (4):
A student can choose a computer project from one of three lists.
The three lists contain 23, 15 and 19 possible projects respectively.
No project is on more than one list. How many possible projects are
there to choose from?
Solution:
The student can choose a project by selecting a project from the
first list, the second list, or the third list. Because no project on more
than one list, by the sum rule there are 23 + 15 + 19 = 57 ways to
choose a project.
Exercises:
1) How many +ve integers between 50 and 1000
(a) are divisible by 7? Which integers are these?
147
(b) are divisible by 11? Which integers are there?
(c) are divisible by both 7 and 11? Which integers
2) How many +ve integers less than 1000 are there?
(a) are divisible by 7?
(b) are divisible by 7 but not by 11?
(c) are divisible by both 7 and 11?
3) How many +ve integers between 100 and 999
(a) are divisible by 7?
(b) are odd?
(c) Have the same three decimal digits?
(d) Are not divisible by 4?
(e) Are divisible by 3 or 4.
6.3 The Pigeonhole Principle:
Theorem(1):
If k is a positive integer and k+1 or more objects are placed into
k boxes, then there is at least one box containing two or more of the
objects.
Proof:
We will prove the pigeonhole principle using a proof by
contraposition.
Suppose that none of the k boxes contains more than one object.
Then the total number of objects would be at most k. this
contradiction, because there are at least k+1 objects.
Example (5):
Among any group of 367 people, there must be at least two with
the same birthday, because there are only 366 possible birthdays.
148
Example (6):
In any group of 27 English words, there must be at least two that
begin, with the same letter, because there are 26 letters in the English
alphabet.
Example (7):
How many students must be in a class to guarantee that at least
two students receive the same score on the final exam, if the exam
graded in a scale from 0 to 100 points.
Solution:
There are 101 possible scores on the final. The pigeonhole
principle show that among any 102 students there must be at least 2
students with same score.
6. 4. Sequences and Summations:
6.4.1. Sequences:
A sequence is a discrete structure used to represent an ordered
list . For example ,1,2,3,5,8 is a sequence with five terms and
1,3 9,27,81,…is an infinite sequence .
Def.(1): A Sequence is a function from a subset of integers (usually
either the set {0,1,2,…} or the set {1,2,3,…}to the set S. We use the
notation 풂풏 to denote the image of the integer n . We call 풂풏 a term
of the sequence .
Example(1):
Consider the sequence {풂풏} ,where 풂풏 = ퟏ풏
The list of the terms of this sequence ,beginning with 풂풏 ,namely ,
풂ퟏ, 풂ퟐ , 풂ퟑ, …
Def.(2): A geometric progression is a sequence of the form
풂, 풂풓 , 풂풓ퟐ, 풂풓ퟑ, … , 풂풓풏, …
149
Where the initial term 풂 and the common ratio 풓 are real numbers.
Example (2):
The sequence {풃풏} with 풃풏 = (-1)풏 , {풄풏} with
풄풏 = ퟐ. ퟓ풏 and {풅풏} with 풅풏 = 6 . (ퟏퟑ)풏 are geometric progressions
with initial term and common ratio equal to 1 and -1 ; 2and 5 ; and 6
and ퟏퟑ , respectively , if we start at n=0 . The list of terms
풃ퟎ, 풃ퟏ , 풃ퟑ, 풃ퟒ ,…. begins with 1,-1, 1 ,-1 ,1,…;
The list of terms 풄ퟎ, 풄ퟏ, 풄ퟐ, 풄ퟑ, … begins with 2, 10, 50, 250, 1250, …;
And the list of terms 풅ퟎ, 풅ퟏ, 풅ퟐ, 풅ퟑ, … 풃풆품풊풏풔 풘풊풕풉
6, 2, ퟐퟑ , ퟐ
ퟗ , ퟐ
ퟐퟕ ,…
Def.(3): An arithmetic progressions is a sequence of the form :
풂, 풂 + 풅, 풂 + ퟐ풅, 풂 + ퟑ풅, … , 풂 + 풏풅, …
Where the initial term 풂 and the common difference 풅 are real
numbers.
Example(3):
The sequence {풔풏} with 풔풏 = -1+4n and {풕풏} with
풕풏 =7-3n are both arithmetic progressions with initial terms and
common differences equal to -1 and 4 ,and 7 and -3, respectively, if
we start at n=0 . The list of terms 풔ퟎ, 풔ퟏ, 풔ퟐ, 풔ퟑ, … begins with
-1,3,7,11,…
And the list of terms 풕ퟎ, 풕ퟏ, 풕ퟐ, 풕ퟑ, … begins with 7 ,4 ,1 ,-2,…
Example(4):
Find formula for the sequences with the following first five terms: (a)
1, ퟏퟐ , ퟏ
ퟒ , ퟏ
ퟖ , ퟏ
ퟏퟔ (b) 1 ,3 ,5 ,7 ,9 (c) 1 ,-1 , 1 ,-1 ,1.
150
Solution:
(a) We recognize that the denominators are powers of 2.
The sequence with 풔ퟎ = ퟏퟐ풏 , n = 0 ,1 ,2 , … is a possible match . The
proposed sequence is a geometric progression with 풂 = ퟏ 풂풏풅 풓 = ퟏퟐ
(b)We note that each term is obtained by adding 2 to the
previous term . The sequence with 풂풏 = 2n +1 , n= 0 ,1, 2 ,… is
a possible match . This proposed sequence is an arithmetic
progression with 풂 = ퟏ 풂풏풅 풅 = ퟐ.
(c) The terms alternate between 1 and -1 . The sequence with
풂풏 = (-1)풏,n= 0 ,1, 2 ,… is possible match . This proposed
sequence is a geometric progression with 풂 = ퟏ 풂풏풅 풓 = −ퟏ.
Some Useful Sequences
nth Term First 10 Terms
풏ퟐ 1, 4 , 9 , 16 , 49 , 64 , 81 , 100 ,…
풏ퟑ 1 , 8 ,27 , 64 , 125 , 216 , 343 , 512 , 729 , 100 ,…
풏ퟒ 1 , 16 , 81 , 256 , 625 , 1296 , 2401 , 4096 , 6561 , 10000,…
ퟐ풏 2, 4 , 8 , 16 , 32 , 64 , 128 , 256 , 512 , 1024,…
ퟑ풏 3 , 9 , 27 , 81 , 243 , 729 , 2187 , 6561 , 19683, 59049,…
n! 1 , 2 , 6 , 24 , 120 , 720 , 5040 , 40320 , 362880, 3628800,…
6.4.2 Summations:
The sum of terms : 풂풎, 풂풎 ퟏ, 풂풎 ퟐ,, 풂풎 ퟑ, … , 풂풏 form the
sequence {풂풏}. We use the notation : ∑ 풂풋풏풋 풎 , 풐풓 ∑ 풂풋풊 풋 풏
to represent:
151
풂풎+풂풎 ퟏ + 풂풎 ퟐ, + 풂풎 ퟑ + ⋯ + 풂풏 . The variable j is called the
index of summation , and the choice of the letter j as the variable is
arbitrary ; that is , we could have used any other letter ,such as I or
k, in notation ∑ 풂풋풏풋 풎 = ∑ 풂풊
풏풊 풎 = ∑ 풂풌
풏풌 풎
Here , the index of summation runs through all integers starting with
lower limit m and ending with its upper limit n.
Example(1):
Express the sum of the first 100 terms of the sequence {풂풏},
where 풂풏 = ퟏ풏 , for n = 1 ,2 , 3, …
Solution:
The lower limit for the index of summation is 1 , and the
upper limit is 100 .We write the sum as: ∑ ퟏ풋
ퟏퟎퟎ 풋 ퟏ .
Example(2):
What is the value of : ∑ 풋ퟐퟓ 풋 ퟏ ?
Solution: ∑ 풋ퟐퟓ 풋 ퟏ = ퟏퟐ + ퟐퟐ + ퟑퟐ + ퟒퟐ + ퟓퟐ= 1+4+9+16+25 =55.
Example (3):
What is the value of : ∑ (−ퟏ)풌ퟖ 풌 ퟒ ?
Solution : ∑ (−ퟏ)풌ퟖ 풌 ퟒ = (−ퟏ)ퟒ + (−ퟏ)ퟓ + (−ퟏ)ퟔ + (−ퟏ)ퟕ + (−ퟏ)ퟖ
= 1+(-1 )+1+(-1)+ 1
= 1.
Example (4):
Suppose we have the sum : ∑ 풋ퟐퟓ 풋 ퟏ
But we want the index of summation to run from 0 and 4 rather
than 1 to 5 . To do this ,we let k= j-1 . Then the new summation
index runs from 0 to 4 , and the term 풋ퟐ becomes (풌 + ퟏ)ퟐ .
Hence ,
152
∑ 풋ퟐퟓ 풋 ퟏ = ∑ (풌 + ퟏ)ퟐퟒ
풌 ퟎ .
It is easily checked that both sums are 1+4+9+16+25 = 55.
Theorem(1): (Formula for the sum of terms of geometric progression).
∑ 풂풓풋풏풋 ퟎ =
풂풓풏 ퟏ 풂풓 ퟏ
, 풊풇 풓 ≠ ퟏ(풏 + ퟏ)풂 , 풊풇 풓 = ퟏ
�
Example(5):(Double summations)
∑ ∑ 풊 풋.ퟑ풋 ퟏ
ퟒ풊 ퟏ
To evaluate the double sum, first expand the inner summation and
then continue by computing the outer summation :
풊 풋 = (풊 + ퟐ풊 + ퟑ풊)ퟒ
풊 ퟏ
ퟑ
풋 ퟏ
ퟒ
풊 ퟏ
= ퟔ풊 = ퟔ + ퟏퟐ + ퟏퟖ + ퟐퟒ = ퟔퟎ ퟒ
풊 ퟏ
.
Exercises:
1) What are the terms 풂ퟎ , 풂ퟏ, 풂ퟐ, 풂풏풅 풂ퟑ of the sequence { 풂풏}
Where 풂풏 equals :
(a) ퟐ풏 + ퟏ?
(b) (n +1)풏 ퟏ?
(c) 풏ퟐ ?
(d) 풏ퟐ + 풏
ퟐ ?
2) What are the terms 풂ퟎ , 풂ퟏ, 풂ퟐ , and 풂ퟑ of the sequence :
{ 풂풏} Where 풂풏 equals :
(a) (-2)풏? (b) 3 ? (c) 7 + ퟒ풏 ? (d) ퟐ풏 + (− ퟐ)풏 ?
3) List the first 10 terms of each of these sequences :
(a) The sequence that begins with 2 and in which each
successive term is 3 more than preceding term.
(b) The sequence that lists each positive integer three times ,
in increesing order .
153
(c) The sequence that lists the odd positive integers in
increasing order , listing each odd integer twice .
(d) The sequenc whose nth term is 풏! − ퟐ풏 .
4) List the first 10 terms of these sequences :
(a) The sequence obtained by starting with 10 and obtaining
each term by subtracting 3 from the previous term.
(b) the sequence whose nth term is the sum of the first n positive
integers .
(c) The sequence whose nth term is ퟑ풏 − ퟐ풏 .
(d) The sequence whose terms are constructed sequentially as
follows : start with 1 , then add 1 , then multiply 1 , then add 2 ,
then multiply by 2 , and so on.
5) What are the values of these sums :
(a)∑ (풌 + ퟏ)ퟓ풌 ퟏ (b) ∑ (−ퟐ)풋ퟒ
풋 ퟎ (c) ∑ ퟑퟏퟎ풊 ퟏ
(d) ∑ (ퟐ풋 ퟏ − ퟐ풋)ퟖ풋 ퟎ
6) Compute each of these double sums:
(a) ∑ ∑ ( 풊 + 풋)ퟑ풋 ퟏ
ퟐ풊 ퟏ (b) ∑ ∑ ( ퟐ풊 + ퟑ풋)ퟑ
풋 ퟎퟐ풊 ퟎ
(c) ∑ ∑ 풊ퟐ풋 ퟎ
ퟑ풊 ퟏ ∑ ∑ 풊풋ퟑ
풋 ퟏퟐ풊 ퟎ
154
6. 5. Discrete Probability:
6.5.1: Random variables and sample spaces:
Def.(1):
Suppose we have an experiment whose outcome depends on
chance .We represent the outcome of the experiment by a capital
letter ,such that as X called a random variable . The sample space of
the experiment is the set of all possible outcomes . If the sample
space is either finite or countable infinite , the random variable is
called discrete .
We generally denote a sample space by the capital Greek letter 훀 .
Example(1):
A die is rolled once , let X denote the out come of this
experiment is the 6- element set , 훀 = { 1 , 2 , 3 , 4 , 5 , 6 } where
each outcome i , for i = 1 , … ,6 correspond to the number of dots
on the face which turns up . The event E = { 2 ,4 , 6 }corresponds to
the statement that the result is an even number . The event E can
also be described by saying that X is even . Unless there is
reason to believe the die is loaded , the natural assumption is
that every outcome is equally likely . A dopting this convention
means that we assign a probability of ퟏퟔ to each of the outcomes,
i. e , m(i) = ퟏퟔ for 1≤ 풊 ≤ ퟔ.
Example (2):
Consider an experiment in which a coin is tossed twice .
Let X be the random variable which corresponds to theis
experiment . We note that there are several ways to record the
155
outcomes of this experiment . We could , for example record the
two tosses , in the order in which they occurred . In this case ,
we have
훀 = { HH , HT , TH , TT }. We also could record the outcomes by
simply noting the number of heads that appeard. In this case ,
we have 훀 = { 0 , 1 , 2 }. Finally , we could record the two
outcomes , outcomes , without regard to the order in which they
occurred . In this case , we have 훀 = { HH , HT , TT }.
We will use , for the moment , the first of the sample spaces
given above , we will assume that all four outcomes are
generally likely , and define the distribution function m( 풘) by :
m(HH) = m(HT) = m(TH) = m(TT) = ퟏퟒ
Let E = { HH , HT, TH } be the event that at least one head
comes up .. Then , the probability of E can be calculated as
follows:
P(E) = m(HH) + m(HT) +m(TH) = ퟏퟒ + ퟏ
ퟒ + ퟏ
ퟒ = ퟑ
ퟒ
Similarly , if F = { HH , HT } is the event that heads comes up
on the first toss , then we have :
P(F) = m(HH) + m(HT) = ퟏퟒ + ퟏ
ퟒ = ퟏ
ퟐ
Example (3):
Three people A, B and C , are running for the office ,
and we assume that one and only one of them wins . The sa
sample space may be taken as the 3- element set 훀= { A , B , C}.
156
Where each element corresponds to the outcome of that
candidates winning , suppose that A and B have the same
chance of winning , but C has only ퟏퟐ the chance of A and B .
Then we assign :
m(A) = m(B) =2 m( C)
since m(A) + m(B)+m(C)= 1, we see that 5m(C) =1 .
Hence m(A) = ퟐퟓ , m(B) = ퟐ
ퟓ , m(C) = ퟏ
ퟓ .
Let E be the event that either A or C wins , then E = { A ,C }
and P(E) = m(A) + m(C) = ퟐퟓ + ퟏ
ퟓ = ퟑ
ퟓ .
Theorem(1) :
The probabilities assigned to events by a distribution
function on a sample space 훀 satisfy the following properties :
(1) ퟎ ≤ 푷(푬) ≤ ퟏ , ∀ 푬 ⊂ 훀 .
(2) P(훀) = ퟏ.
(3) If E ⊆ 푭 ⊆ 훀 , then P(E) ≤ P(F) .
(4) If A and B are disjoint subsets of 훀 , then
P(A∪ 푩) = P(A) + P(B).
(5) P( 푨) = 1 – P(A) , ∀ 푨 ⊂ 훀 .
Theorem(2):
If 푨ퟏ , 푨ퟐ , 푨ퟑ , … , 푨풏 are pairwise disjoint subsets of 훀 ,
then P( 푨ퟏ ∪ 푨ퟐ ∪ 푨ퟑ ∪ … ∪ 푨풏) = ∑ 푷(푨풊)풏풊 ퟏ .
157
Theorem(3):
Let 푨ퟏ , 푨ퟐ , 푨ퟑ , … , 푨풏 be pairwise disjoint events with
훀 = 푨ퟏ ∪ 푨ퟐ ∪ 푨ퟑ ∪ … ∪ 푨풏 and let E be any event . Then
P(E) = ∑ 푷(푬 ∩ 푨풊)풏풊 ퟏ .
Corrllary:
For any two event A and B
P(A) = P(푨 ∩ 푩) + P(푨 ∩ 푩) .
Theorem(4):
If A and B are subsets of 훀 , then
P( A∪ 푩) = P(A) + P(B) – P(푨 ∩ 푩).
Exercises:
1) Let 훀 = { a , b , c } be a sample space , let m(a) = ퟏퟐ , m(b) = ퟏ
ퟑ
and m(c) = ퟏퟔ . Find the probabilities of all eight subsets of 훀 .
2) Describe in words the events specified by the following subsets
of 훀 = { HHH , HHT , HTH , HTT, THH , THT, TTH , TTT }
a) E = { HHH , HHT , HTH , HTT}.
b) E = { HHH, TTT}.
c) E = { HHT, HTH , THH}.
d) E = { HHT, HTH , HTT, THH, THT ,TTH}.
3) What are the probabilities of the events described in
158
exercise (2)?
4) Let A and B be events such that P(푨 ∩ 푩) = ퟏퟒ , 푷(푨) = ퟏ
ퟑ
and P(B) = ퟏퟐ .What is P( A∪ 푩) ?
6.6 Permutations and Combinations:
6.6.1 Permutations:
Example (8):
In how many ways can we select three students from a group of
five students to stand in line for a picture?
Solution:
There are 5 ways to select the first student to stand at the start
of the line there are 4 ways to select the 2nd student there are 3 ways
to select the 3rd student in the line. Hence there are 5 – 4 – 3 = 50
ways to select three students from a group of 5 students to stand for a
picture.
Example (9):
Let S = {1, 2, 3}. There 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 elements is
denoted by P(n,r).
Theorem(2):
If n and r are integers with ퟎ ≤ 풓 ≤ then 푷(풏, 풓) = 풏!(풏 풓)!
Example (10):
How many ways are there to select a first-prize winner, a
second-prize winner, and a third-prize winner from 100 different
people who have entered a contest?
159
Solution :
The number of 3-permutations of a set of 100 elements.
푷(ퟏퟎퟎ, ퟑ) = ퟏퟎퟎ!(ퟏퟎퟎ ퟑ)!
= ퟏퟎퟎ!ퟗퟕ!
= ퟏퟎퟎ.ퟗퟗ.ퟗퟗ.ퟗퟖ.ퟗퟕ!ퟗퟕ!
= ퟗퟕퟎퟐퟎퟎ
Example (11):
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 a word these medals, if all possible
outcomes of the race can occur and there are no ties?
Solution:
The number of different ways to a word the medals is the
number of 3-penmutations of a set with 8 elements. Hence there are
푷(ퟖ, ퟑ) = ퟖ!ퟓ!
= 336 possible ways to a ward the medals.
6.6.2 Combinations:
Def .(1): The number of r-combinations of a set with n distinct
elements is denoted by 푪(풏, 풓) = 풏풓 .
Example (12): c(4,2) = 4!
Theorem (3):
The number of r-combinations of a set with n elements, where n
is a nonnegative integer and r is an integer ퟎ ≤ 풓 ≤ 풏 equals
푪(풏, 풓) =풏!
풓! (풏 − 풓)!
Proof :
푷(풏, 풓) = 풏!풓!(풏 풓)!
160
푪(풏, 풓) = 푷(풏,풓)푷(풓 풓) = 풏!(풏 풓)!
풓!/(풓 풓)!= 풏!
풓!(풏 풓)!
Example (13):
How many poker hands of five cards can be dealt from a
standard deck of 52 cards? Also, How many ways are there to select
37 cards from a standard deck of 52 cards?
Solution:
The order in which the 5 cards are dealt from a deck of 52 cards
does not matter, are
1) 푪(ퟓퟐ, ퟓ) = ퟓퟐ!ퟓ!.ퟒퟕ!
= ퟓퟐ.ퟓퟏ.ퟓퟎ.ퟒퟗ.ퟒퟖ.ퟒퟕ!ퟓ.ퟒ.ퟑ.ퟐ.ퟏ.ퟒퟕ! = ퟐퟓퟗퟖퟗퟔퟎ
2) 푪(ퟓퟐ, ퟒퟕ) = ퟓퟐ!ퟒퟕ!.ퟓ!
= = ퟐퟓퟗퟖퟗퟔퟎ
Corollary(1): Let n and r be nonnegative integers 풓 ≤ 풏. Then
풄(풏, 풓) = 풄(풏, 풏 − 풓)
Proof: From theorem (2) it follows that
풄(풏, 풓) =풏!
풓! (풏 − 풓)
and 풄(풏, 풏 − 풓) = 풏!(풏 풓!) 풏 (풏 풓) !
= 풏!(풏 풓)!.풓!
Hence, 풄(풏, 풓) = 풄(풏, 풏 − 풓)
Example (14):
How many ways are there to select 5 players from a 10-member
tennis team to make a trip to match at another school?
Solution:
By theorem (2)
풄(ퟏퟎ, ퟓ) =ퟏퟎ!
ퟓ! ퟓ!= ퟐퟓퟐ
6.7. The Binomial Theorem:
The expansion of (풙 + 풚)ퟑ = (풙 + 풚)(풙 + 풚)(풙 + 풚)
= 풙ퟑ + 풙ퟐ풚 + 풙ퟐ풚 + 풙풚ퟐ + 풚풙ퟐ + 풙풚ퟐ + 풙풚ퟐ + 풚ퟑ
161
= 풙ퟑ + ퟑ풙ퟐ풚 + ퟑ풙풚ퟐ + 풚ퟑ
Theorem (4): (The Binomial Theorem)
Let x and y be variables, and let n be a non negative integer.
Then
(풙 + 풚)풏 =풏풋 풙풏 풋풚풋
풏
풋 ퟎ
= 풏ퟎ 풙풏 + 풏
ퟏ 풙풏 ퟏ풚 + 풏ퟐ 풙풏 ퟐ풚ퟐ + ⋯ + 풏
풏 풚풏
Proof:
Using the mathematical induction form:
Let p(n)= (풙 + 풚)풏 , 풑(풏) = ∑풏풋
풏풋 ퟎ 풙풏 풋풚풋
Basic step:
1) Let n = 1, p(1) = (풙 + 풚)ퟏ = 풙 + 풚
p(1) is true.
2) Assume that 퐩(퐦) = (퐱 + 퐲)퐦 = ∑퐦퐣 퐱퐦 퐣퐲퐣퐦
퐣 ퟎ is true
3) The inductive step 풑(풎) → 풑(풎 + ퟏ)
풑(풎 + ퟏ) = (풙 + 풚)풎 ퟏ = (풙 + 풚)(풙 + 풚)풎
= (풙 + 풚)풎풋 풙풎 풋풚풋
풎
풋 ퟎ
=풎풋 풙풎 풌 ퟏ풚풋 +
풎풋 풙풎 풋풚풋 ퟏ
풎
풋 ퟎ
풎
풋 ퟎ
= 풎ퟎ 풙풎 ퟏ 풎
풋 풙풎 ퟏ 풋풚풋풎
풋 ퟏ
+풎풋 풙풎 풋풚풋 ퟏ + 풎
풎 풚풎 ퟏ풎 ퟏ
풋 ퟏ
= 풙풎 ퟏ 풎풋 풙풎 ퟏ 풋풚풋 +
풎풋 − ퟏ 풙풎 ퟏ 풋풚풋 + 풚풎 ퟏ
풎
풋 ퟏ
풎
풋 ퟏ
162
= 풙풎 ퟏ 풎풋 ∗
풎풋 − ퟏ 풙풎 ퟏ 풋풚풋 + 풚풎 ퟏ
풎
풋 ퟏ
= 풎 + ퟏ풐 풙풎 ퟏ + 풎 + ퟏ
풋 풙풎 ퟏ 풋 + 풎 + ퟏ풎 + ퟏ 풚풎 ퟏ
풎
풋 ퟏ
= 풎 + ퟏ풋 풙풎 ퟏ 풋풚풋
풎 ퟏ
풋 ퟎ
Hence p(m+1) is true
P(n) is true, ∀풏 ∈ 휨
Example (15): What is the expansion of (x+y)4?
Solution: From the Binomial theorem
(풙 + 풚)ퟒ = ퟒ풋 풙ퟒ 풋풚풋
ퟒ
풋 ퟎ
= ퟒퟎ 풙ퟒ + ퟒ
ퟏ 풙ퟑ풚 + ퟒퟐ 풙ퟐ풚ퟐ + ퟒ
ퟑ 풙풚ퟑ + ퟒퟒ 풚ퟒ
= 풙ퟒ + ퟒ풙ퟑ풚 + ퟔ풙ퟐ풚ퟐ + ퟒ풙풚ퟑ + 풚ퟒ
Example (16):
What is the coefficient of 풙ퟏퟐ풚ퟏퟑ in the expansion of (풙 + 풚)ퟐퟓ?
Solution:
From the Binomial theorem it follows that this coefficient is
ퟐퟓퟏퟑ =
ퟐퟓ!ퟏퟑ!. ퟏퟐ!
= ퟓퟐퟎퟎퟑퟎퟎ
Example (17):
What is the coefficient of 풙ퟏퟐ풚ퟏퟑ in the expansion of (ퟐ풙 −
ퟑ풚ퟐퟓ?
Solution:
(ퟐ풙 − ퟑ풚)ퟐퟓ = ퟐ풙 + (−ퟑ풚) ퟐퟓ
163
∴ ퟐ풙 + (−ퟑ풚) ퟐퟓ= ퟐퟓ
풋
ퟐퟓ
풋 ퟎ
(ퟐ풙)ퟏퟐ(−ퟑ풚)ퟏퟑ
The coefficient of 풙ퟏퟐ풚ퟏퟑ in the expansion is obtained when j =
13, namely
ퟐퟓퟏퟑ ퟐퟏퟐ(−ퟑ)ퟏퟑ = −
ퟐퟓ!ퟏퟑ!. ퟏퟐ!
ퟐퟏퟑ. ퟑퟏퟑ
Corollary (2): Let n be nonnegative integer, then
풏풌
풏
풌 ퟎ
= ퟐ풏
Proof: Using the Binomial theorem with x = 1 and y = 1, we see
that
ퟐ풏 = (ퟏ + ퟏ)풏 = 풏풌 ퟏ풌
풏
풌 ퟎ
. ퟏ풏 풌 = 풏풌
풏
풌 ퟎ
Corollary (3): Let n be a positive integer, then
(−ퟏ)풌 풏풌
풏
풌 ퟎ
= ퟎ
Proof: Using the Binomial theorem with x = -1 and y = 1, we see
that ퟎ = ퟎ풏 = (ퟏ − ퟏ) + ퟏ풏
= ∑ 풏풌 (−ퟏ)풌ퟏ풏 풌풏
풌 ퟎ
= 풏풌 (−ퟏ)풌
풏
풌 ퟎ
Corollary (4): Let n be a nonnegative integer, then
ퟐ풌 풏풌 = ퟑ풏
풏
풌 ퟎ
Proof: ퟑ풏 = (ퟏ + ퟐ)풏 = ∑ 풏풌 ퟏ풏 풌풏
풌 ퟎ ퟐ풌 = ∑ 풏풌
풏풌 ퟎ ퟐ풌
164
Theorem (5) : ( Pascal’s identity)
Let n and k be positive integers with 풏 ≥ 풌, then 풏 + ퟏ
풌 = 풏풌 − ퟏ + 풏
풌
Example(18):
Prove the identity: 풏ퟎ + 풏 ퟏ
ퟏ + 풏 ퟐퟐ + ⋯ + 풏 풌
풌 = 풏 풌 ퟏ풌 ……..(*)
Proof:
We use the mathematical induction on k.
(Basis step): If k = 0
The identity just says 1=1
So it is trivially true.( we can check it also for k =
1).
n+1 = n+1
The inductive step:
Assume that the identity (*) is true for a given value
k
We want to prove that it also holds for k+1 in place
of k , we want to prove that: 풏ퟎ + 풏 ퟏ
ퟏ + 풏 ퟐퟐ + ⋯ + 풏 풌
풌 + 풏풌 ퟏ = 풏 풌 ퟐ
풌 ퟏ
Here the sum of the first k terms on the left hand
side is: 풏 풌 ퟏ풌 by induction hypothesis , and so the
left hand side equal to 풏 풌 ퟏ풌 + 풏 풌 ퟏ
풌 ퟏ
But this is indeed equal to 풏 풌 ퟐ풌 ퟏ
165
By the fundamental property of Pascal triangle this
complete the proof by induction.
6.8. Pascal’s triangle:
6.8. 1 Recurrence Relations: Def.(1):
A recurrence relation for the sequence {풂풏} is an equation
that express 풂풏 in terms of one or more of the previous
terms of the sequence , namely , 풂ퟎ, 풂ퟏ, 풂ퟐ, … , 풂풏 ퟏ, for all
integers n with
n ≥ 풏ퟎ, where 풏ퟎ is non negative integer . A sequence is
called a solution of a recurrence relation if its terms satisfy
the recurrence relation .
(a)
1
1 1
1 2 1
1 3 3 1
1 4 6 4 1
1 5 10 10 5 1
1 6 15 20 15 61
1 7 21 35 35 21 71
1 8 28 36 70 56 2881
(b)
166
Example(1):
Let {풂풏} be a sequence that satisfies the recurrence relation
풂풏 = 풂풏 ퟏ − 풂풏 ퟐ 풇풐풓 풏 = ퟐ, ퟑ , ퟒ , … , and suppose that
풂ퟎ = ퟑ 풂풏풅 풂ퟏ = ퟓ . What are 풂ퟐ 풂풏풅 풂ퟑ ?
Solution :
We see from the recurrence relation that
풂ퟐ = 풂ퟏ − 풂ퟎ = ퟓ − ퟑ = ퟐ 풂풏풅 풂ퟑ = 풂ퟐ − 풂ퟏ = ퟐ − ퟓ =
−ퟑ
We can find 풂ퟒ 풂풏풅 풂ퟓ , and each successive term in a
similar way.
Example (2):
The recurrence relation 푷풏 = (ퟏ. ퟏퟏ)푷풏 ퟏ is a linear
homogenous relation of degree one . The recurrence relation
푭풏 = 푭풏 ퟏ + 푭풏 ퟐ The recurrence relation 풂풏 = 풂풏 ퟓ is a
linear homogenous recurrence relation of degree five.
Example(3):
Determine whether the sequence {풂풏} , where
풂풏 = ퟑ풏 풇풐풓 풆풗풆풓풚 nonnegative integer n , is a solution of
the recurrence relation 풂풏 = ퟐ 풂풏 ퟏ – 풂풏 ퟐ 풇풐풓 풏 =
ퟐ , ퟑ , ퟒ ….
푨풏풔풘풆풓 the same question where 풂풏 = ퟐ풏 and 풂풏 = ퟓ.
Solution:
Suppose that 풂풏 = ퟑ풏 for every nonnegative integer n.Then ,
for n ≥ ퟐ , we see that 2 풂풏 ퟏ − 풂풏 ퟐ = ퟐ [ퟑ(풏 − ퟏ)] − ퟑ (풏 − ퟐ) =
ퟑ풏 = 풂풏
Therefore, {풂풏} , where 풂풏 = ퟑ풏 , 퐢퐬 퐚 퐬퐨퐥퐮퐭퐢퐨퐧 for the recurrence
relation .
167
Suppose that 풂풏 = ퟐ풏 for every nonnegative integer n . Note
that 풂ퟎ = ퟏ, 풂ퟏ = ퟐ , 퐚퐧퐝 풂ퟐ = ퟒ. Because ퟐ풂ퟏ − 풂ퟎ = 2.2 -1=3 ≠
풂ퟐ ,
we see that {풂풏}, where 풂풏 = ퟐ풏 , is not a solution of the recurrence
relation.
Suppose that 풂풏 = ퟓ for every nonnegative integer n . Then for
n ≥ ퟐ , we see that 풂풏 = ퟐ풂풏 ퟏ − 풂풏 ퟐ = ퟐ. ퟓ − ퟓ = ퟓ = 풂풏 .
Therefore , {풂풏}, where 풂풏 = ퟓ ,is a solution of the recurrence
relation.
Example (4):The recurrence relation 풂풏 = 풂풏 ퟏ − 풂ퟐ풏 ퟐ is non
linear . The recurrence relation 푯풏 = ퟐ푯풏 ퟏ + ퟏ is not
homogeneous. The recurrence relation 푩풏 = 풏푩풏 ퟏ does not have
constant coefficients.
= 1 1= a 0and a 2-n+ 3 a 1-n= 2 a na: Example(5)
by use of the characteristic equation: Solution
1. Substitute rn for an (rn-1 for an-1, etc.) and simplify the result. For this
example the characteristic equation is rn = 2rn-1 + 3rn-2 which
simplifies to: r2 = 2r + 3
2. Find the roots of the characteristic equation:
r2 - 2r - 3 = 0 factors as (r - 3)(r + 1) giving roots r1 = 3 and r2 = -1
When there are two distinct roots, the general form of the solution is:
an = 1•r1n + 2•r2
n
where 1 and 2 are constants. In this case, we have:
an = 1•3n + 2•(-1)n
168
3. Using the initial conditions we can find the constants 1 and 2
a0 = 1 = 1 + 2
a1 = 1 = 31 - 2
so 1 = 1/2 and 2 = 1/2 and the final solution is
an = (1/2)•3n + (1/2)•(-1)n.
If a characteristic equation has equal roots, (i.e. r1 =r2), then the general
solution has the form:
an = 1•rn + 2•n•rn
4.-= 3= 4 and a 22, a-= 1= 0, a 0with a 4-na – 2-n= 2a n: aExample( 6)
In this case, we have a degree four linear homogeneous recurrence whose
characteristic equation is r4 = 2 r2 - 1 or r4 -2 r2 + 1 = 0. This factors as:
(r2 - 1)( r2 - 1) = 0 so the roots are r1 = r2 = 1 and
r3 = r4 = -1. (The order of the roots is arbitrary.)
Note there are two pairs of equal roots so there will be two terms each with n
as a factor.
The form of the general solution is: an = 1•r1n + 2•n•r2
n + 3•r3n +
4•n•r4n
Setting up the equations we have:
a0 = 0 = 1 + 3
a1 = -2 = 1 + 2 - 3 - 4
169
a2 = 4 = 1 + 22 + 3 + 24
a3 = -4 = 1 +32 - 3 - 34
so 1 = -1/2, 2 = 1/2, 3 = 1/2 and 4 = 3/2 and the final solution is:
an = (-1/2)•1n + (1/2)•n•1n + (1/2)• (-1)n + (3/2)•n•(-1)n
= -1/2 + n/2 + (1/2)•(-1)n + (3/2)•n•(-1)n
raw n straight lines on a paper so that every pair of : DExample( 7)
lines intersect, but no three lines intersect at a common point.
Determine how many regions the plane is divided into if n lines are
used. (Draw yourself some pictures.)
If n = 0 then there is 1 region.
If n = 1 there are 2 regions.
If n = 2 there are 4 regions.
If n = 3 there are 7 regions.
In general, the nth line intersects n -1 others and each intersection
subdivides a region, so the number of regions that are subdivided by
the nth line is: 1 before the first line, 1 after the last line, and n - 2
regions between the n -1 lines. This gives us the following recurrence
relation:
an = an-1 + n This can be solved iteratively by backward
substitution. Specifically,
= an-2 + (n - 1) + n
= an-3 + (n - 2) + (n - 1) + n
170
•
•
•
= a0 + 1 + 2 + ... + (n - 2) + (n - 1) + n = a0 + i = 1 + n(n + 1)/2
> 0 and na where 2 )1-n= 5(a 2
n: Consider the relation aExample( 8)
a0 = 2.
Make the following change of variable: let bn = an2. Then, b0 = 4 and bn
= 5 bn-1.
Since this is a geometric series, its solution is bn = 4•5n. Now
substituting back,
an = √bn = 2√5n for n 0.
6.8.2.Inhomogeneous Recurrence Relations:
We now turn to inhomogeneous recurrence relations and look at
two distinct methods of solving them. These recurrence relations in
general have the form an = cn-1an-1 + g(n) where g(n) is a function of n.
(g(n) could be a constant)
One of the first examples of these recurrences usually encountered is
the tower of Hanoi recurrence relation: H(n) = 2H(n-1) + 1 which has
as its solution H(n) = 2n – 1. One way to solve this is by use of
backward substitution as above. We’ll see another method shortly.
-Consider the Tower of Hanoi recurrence: H(n) = 2H(n : Example( 9)
1) + 1 with H(1) = 1. The solution to the homogeneous part is •2n.
Since g(n) = 1 is a constant, the particular solution has the form
171
p(n) = . Substituting into the original recurrence to solve for we
get: = 2 +1 so that = -1. Thus, p(n) = -1. This means that
H(n) = •2n – 1. Using the fact that H(1) = 1, gives 1 = •2 –1 so = 1.
Thus, the solution to the original recurrence is H(n) = 2n – 1. (Note
that alternative ways to get this solution are backward substitution and
the method shown below.)
= 3. 1with a 2+ n 1-n= 2a n: aExample( 10)
The homogeneous part an = 2an-1 has a root of 2, so f(n) = •2n. The
particular solution should have the form an = 2•n2 + 1•n + 0.
Substituting this into the original recurrence gives
2n2 + 1n + 0 = 2[2(n-1)2 + 1(n-1) + 0] + n2. Expanding and
combining like terms gives us
0 = n2(2 + 1) + n(-42 + 1) + (22 - 21 + 0). Notice that each
parenthesized expression must evaluate to 0 since the left hand side of
the equation is 0. This gives us the following values for the constants:
2 = -1, 1 = -4 and 0 = -6. Thus, p(n) = -n2 -4n - 6. Then we have
an = •2n -n2 -4n - 6. This gives us = 7 and the final solution is
an = 7•2n -n2 - 4n - 6.
If g(n) consists of two or more terms, then each term is handled
separately using the table above. For example, solving an = 3 an-1 + 6n –
2n, requires finding particular solutions for two recurrences—
an = 3 an-1 + 6n and
an = 3 an-1 – 2n.
172
There is one case in which the particular solutions above will not work.
This happens when the particular solution is a solution of the
homogeneous recurrence. Then, the particular solution that should be
tried is a higher degree polynomial. For example. if g(n) = dn and d is a
solution of the homogeneous part then try •n•dn as the particular
solution.
= 5. 1with a n+ 2 1-n= 3a n: aExample( 11)
The homogeneous part an = 3an-1 has a root of 3, so f(n) = •3n. The
particular solution should have the form an = •2n. Substituting this
into the original recurrence gives •2n = 3 •2n-1 + 2n. Solving this
equation for gives us the particular solution p(n) = -2n+1. Thus the
solution has the form an = •3n - 2n+1. Using the initial condition that
a1 = 5 we get 5 = 3 - 4 which gives = 3. Thus, the final solution is
an = 3n+1 - 2n+1.
:nother method of solving inhomogeneous recurrence relations A 6.8.3
Let’s consider the Tower of Hanoi recurrence again: H(n) = 2H(n-1)
+ 1 or H(n) – 2H(n-1) = 1. Substitute n – 1 for n in this equation to get
H(n-1) – 2 H(n-2) = 1. Notice what happens if we subtract the second
equation from the first: H(n) – 2H(n-1) – H(n-1) +2H(n-2) = 1 – 1,
or H(n) – 3H(n-1) + 2H(n-2) = 0, a homogeneous linear recurrence
relation. The characteristic equation x2 – 3x + 2 = 0 factors as
(x-2)(x-1) = 0 so the general form of the solution is
H(n) = 1• 2n + 2•1n = 1• 2n + 2. Using the initial conditions to
obtain the constants we find that 1 = 1 and 2 = -1 and thus we have
173
H(n) = 2n – 1 as we found before.
= 0 0= 2n with a 1-na – n: aExample (12)
Using the same method as above we find that an-1 - an-2 = 2(n-1). Now,
subtracting we get
an – an-1 = 2n
1)-2(n-= 2-n+ a 1-na-
an -2an-1 + an-2 = 2
This is not yet a homogeneous recurrence but one more application of
the method will give us a linear homogeneous recurrence relation.
an -2an-1 + an-2 = 2
2-= 3-na – 2-n+ 2a 1-na-
an -3an-1 +3an-2 –an-3 = 0 has characteristic equation
x3 – 3x2 + 3x - 1 = 0 that factors as (x – 1)3.
The general form of the answer must be an = 1•1n +2•n•1n + 3•n2•1n
or 1 + 2•n + 3•n2. Since a0=0 we immediately get that 1 = 0. a1 = 2
and a2 = 6 giving us
2 = 2 + 3 and 6 = 22 + 4 3. Solving for 2 and 3 we get 2 = 1 and
3 = 1 so the solution to the recurrence is an = n + n2 or n(n + 1).
The same method can be used to solve recurrence relations in which
g(n) is a higher order polynomial. The substitute n – 1 for n and
subtract may have to be used several times, but eventually you will
174
obtain a linear homogeneous recurrence relation. (However, factoring
the characteristic equation could turn into a challenge.)
A similar method can be used if the function g(n) is an exponential.
= 5. 1with a n+ 2 1-na= 3 n: aExample( 13)
Rewriting the recurrence relation gives us an - 3an-1 = 2n. First we
multiply by 2 to get
2an - 6an-1 = 2n+1. Now substitute n – 1 for n in this new equation to
get:
2an-1 - 6an-2 = 2n. Now, subtracting this new recurrence from the
original one we get:
an - 3an-1 = 2n
n2-= 2-n+ 6a 1-n2a-
an – 5an-1 + 6an-2 = 0.
The characteristic equation is x2 – 5x + 6 = 0 which factors as (x - 3)(x
– 2) = 0, so the answer has the form an = 1•3n + 2•2n. Using the facts
that a1 = 5 and a2 = 19 we get
5 = 31 + 2 2 and 19 = 91 + 42. Solving for the constants we get:
1 = 3 and 2 = -2 giving us the solution an = 3•3n + (-2)•2n = 3n+1 –
2n+1
6.8.4 .A formula for Fibonacci numbers: 푭풏 ퟏ = 푭풏 + 푭풏 ퟏ , n= 2 ,3 ,4 ,… (*)
푭ퟏ = ퟏ , 푭ퟐ = ퟏ , 푭ퟑ = ퟐ , 푭ퟒ = ퟑ , 푭ퟓ = ퟓ , 푭ퟎ = ퟎ
175
Using the equation (*) we can easily determine any number of terms
in this sequence numbers :
0 , 1 ,1 2,3, 5,8,13,21,34, 55, 89,144, 233, 377, 610, 987,1597,…
The numbers in this sequence are called Fibonacci numbers .
Example(3): What is the sum of the first n Fibonacci numbers
0 = 0
0 + 1 = 1
0 + 1 +1 = 2
0 +1 + 1+ 2 = 4
0 + 1 +1 + 2 + 3 = 7
0 + 1 + 1 + 2 + 3 + 5 =12
0 + 1 + 1 + 2 + 3 + 5 + 8 = 20
0 + 1 + 1 + 2 + 3 + 5 + 8 + 13 = 33
……….
푭ퟎ + 푭ퟏ + 푭ퟐ + 푭ퟑ + ⋯ + 푭풏 = 푭풏 ퟐ − ퟏ
푭ퟎ + 푭ퟏ + ⋯ + 푭풏 = (푭ퟎ + 푭ퟏ + ⋯ + 푭풏 ퟏ) + 푭풏
= (푭풏 ퟏ − ퟏ) + 푭풏
= 푭풏 ퟐ − ퟏ
Exercises: 1)Find the value of each of these quantities:
a) P(6,3) (b)P(6,5) (c) P(8,1) (d) P(8,5)
e) C(5,1) (f) C(5,3) (g) C(12,6) (h) C(8,8)
2 )Find the number of 5- permutations of a set with nine
elements
3) What is the row of Pascal 's triangle containing the binomial
coefficients ퟗ풌 , 0≤ k ≤ 9 ?.
3) Find the expansion of (풙 + 풚)ퟒ.
4) What is the coefficient of 풙ퟖ풚ퟗ in the expansion of
5) (ퟑ풙 + ퟐ풚)ퟏퟕ.
176
6) Prove that 풏 풌풌
풓
풌 ퟎ= 풏 풓 ퟏ
풓 .
7) Find recurrenc relations that are satisfied by the sequences
formed from the following functions :
(i) 풂풏 = 풏ퟐ − ퟔ풏 + ퟖ
(ii) 풂풏 = 풏!ퟏퟓ!
(iii) 풂풏 = 풏![ퟏퟓ!(풏 ퟏퟓ )!]
for n 14
177
References:
[1] AL Doerr, Ken Levasseur (2003) .Applied Discrete Mathematics.
[2] Charles M. Grinslead Swarthamore College .Introduction to
Probability.
[3] James L. Hein (2003) Discrete Mathematics .Jones and Bartlett
learning.
[4] Kenneth H. Rosen (2007) Discrete Mathematics and its
Applications . Sixth Edition . McGROW Hill.
[5] Laszlo Lovasz and Katlin Vesztergombi, (1999), Discrete
Mathematics Yale University.
[6] L. Lovaszan K. Vesztergombi(1979).Discrete Mathematics.
Elsevier ,Amesterdam.
[7] Migual A.Lerma Noteson (2005). Discrete Mathematics.
Northwestern University.
[8] M .O. Albertson , (1988) .Discrete Mathematics with Algorithms.
John Wiley and Sons
[9] Richard Johnsonbough .(2007).Applied Discrete Mathematics.
Prentice Hall Amazon .com.
[10] Susanna S. EPP . Discrete Mathematics with Applications.
Fourth Edition. De Paul University .Amazon .com.
[11] Tucker,Alan,Applied combinatorics,2nd ed.
.relations-http://www.answers.com/topic/recurrence]2[1
[13]http://mathcircle.berkeley.edu/BMC3/Bjorn1/node10htm1
178