MA320 - Discrete Mathematics
MA320 - Discrete Mathematics
Department of Mathematics
Small print: The purpose of these lecture notes is to provide a clear comprehension of discrete
mathematics for students taking mathematics, data science or computer science as major courses.
The goal is to lay the mathematical foundation for mathematics courses such as linear and abstract
algebra, combinatorics, graph theory, probability, set theory, logic and number theory.
Discrete mathematics describes processes that consist of a sequence of individual steps. Discrete
mathematics is different from calculus, which describes processes that change continuously. Although
the ideas of calculus were fundamental to the science and technology of the industrial revolution,
the ideas of discrete mathematics underlie all of the science and technology of this era of computers.
1
axioms be consistent; that is, they should not contradict one another. We also demand that there
not be too many axioms. If a system of axioms is too restrictive, there will be few examples of the
mathematical structure.
A certain amount of mathematical maturity is necessary to find and study applications of dis-
crete mathematics. A basic knowledge of set theory, mathematical induction, equivalence relations,
and matrices is a must. Even more important is the ability to read and understand mathematical
proofs. In these notes we will outline the background needed for a course in discrete mathematics.
If that meant nothing to you then you should learn something from the course that you do not
already know. In both style and content, this is an abstract mathematics course. There are few
prerequisites so long as elegant, abstract ideas appeal to you and you are willing to work rigorously
with definitions even if you find it hard to visualise the concepts they define.
TIMOTHY SINYANGWE.
1
Notice: This material must NOT be used as a substitute for attending the lectures.
Page 2 of 73
List of Symbols
Subject Symbol Meaning
Logic ¬p not p
p∧q p and q
pL∨q p or q
p q or p XOR q p or q but not both p and q
p≡q p is logically equivalent to q
p −→ q if p then q
p ←→ q p if and only if q
∴ therefore
P (x) predicate in x
P (x) =⇒ Q(x) Every element in the truth set of P (x)
is in the truth set of Q(x)
P (x) ⇐⇒ Q(x) P (x) and Q(x) have identical truth sets
∀ for all
∃ there exists
Number Theory d|n d divides n
and Applications
d-n d does not divide n
n div d the integer quotient of n divided by d
n mod d the integer remainder of n divided by d
gcd(a, b) the greatest common divisor of a and b
x := e x is assigned the value e
Sequences ... and so forth
Xn
ak the summation from k equals m to n of ak
k=m
Yn
ak the product from k equals m to n of ak
k=m
n! n factorial
Set Theory a∈A a is an element of A
a∈ /A a is not an element of A
{a1 , a2 , . . . , an } the set with elements a1 , a2 , . . . , an
{x ∈ D | P (x)} the set of all x in D for which P (x) is true
R, R− , R+ the sets of all real numbers, negative real numbers,
positive real numbers, and nonnegative real numbers
Z, Z− , Z+ the sets of all integers, negative integers,
positive integers, and nonnegative integers
Q, Q− , Q+ the sets of all rational numbers, negative rational number
positive rational numbers, and nonnegative rational numb
N the set of natural numbers
A⊆B A is a subset of B
A*B A is not a subset of B
Page 3 of 73
B−A the difference of B minus A
A=B A equals B
A∪B A union B
A∩B A intersection B
A the compliment of A
(x, y) ordered pair
(x1 , x2 , . . . , xn ) ordered n-tuple
A×B the Cartesian product of A and B
A1 × A2 × · · · × An the Cartesian product of A1 , A2 , . . . , An
∅ the empty set
P(A) the power set of A
Page 4 of 73
Contents
1 Set Theory 7
1.1 Introduction to Set Theory . . . . . . . . . . . . . . . . . . . . . . . . 7
1.2 New Sets from Old Sets . . . . . . . . . . . . . . . . . . . . . . . . . 7
2 Relations 10
2.1 Functions and Relations . . . . . . . . . . . . . . . . . . . . . . . . . 10
2.2 New Functions from Old Functions . . . . . . . . . . . . . . . . . . . 12
3 Counting Principles 14
3.1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14
3.2 The Inclusion-Exclusion Principle of Two Sets . . . . . . . . . . . . . 14
3.2.7 Permutations with Indistinguishable Objects . . . . . . . . . . 15
3.2.18 Useful Identities . . . . . . . . . . . . . . . . . . . . . . . . . . 18
5 Boolean Algebra 26
5.1 Switching Functions: Disjunction and Conjunction Normal Forms . . 26
5.1.6 Addition and Subtraction of Boolean Functions . . . . . . . . 27
5.1.7 Ten Important Laws In Boolean Algebra . . . . . . . . . . . . 28
5.1.10 Disjunction Normal Form (d.n.f) . . . . . . . . . . . . . . . . 29
6 Proof Techniques 32
6.1 Mathematical Induction . . . . . . . . . . . . . . . . . . . . . . . . . 32
6.1.1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32
6.1.3 Steps Involved in Proving By Mathematical Induction . . . . . 32
6.1.4 How To Do It . . . . . . . . . . . . . . . . . . . . . . . . . . . 32
6.2 Examples . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33
7 Graphs Theory 39
7.1 Introduction to Graphs Theory . . . . . . . . . . . . . . . . . . . . . 39
7.2 Graphs as Networks . . . . . . . . . . . . . . . . . . . . . . . . . . . . 42
7.3 Special Graphs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 42
7.4 Operations in Graphs . . . . . . . . . . . . . . . . . . . . . . . . . . . 45
7.5 The Concept of Degree of a Graph . . . . . . . . . . . . . . . . . . . 47
7.5.8 Havel-Hakimi Algorithm . . . . . . . . . . . . . . . . . . . . . 49
7.6 Walks, Trails, Paths, and Circuits . . . . . . . . . . . . . . . . . . . . 51
7.7 Connectedness . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 54
Page 5 of 73
7.8 Euler Circuits . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 56
7.9 Distance in Graphs . . . . . . . . . . . . . . . . . . . . . . . . . . . . 59
7.10 Cut-vertices and Bridges . . . . . . . . . . . . . . . . . . . . . . . . . 59
7.11 The Shortest Path Algorithm . . . . . . . . . . . . . . . . . . . . . . 60
7.12 Distance in Weighted Graphs . . . . . . . . . . . . . . . . . . . . . . 61
7.13 Dijkstra’s Algorithm . . . . . . . . . . . . . . . . . . . . . . . . . . . 62
7.13.1 Dijkstra’s Algorithm . . . . . . . . . . . . . . . . . . . . . . . 62
7.14 Trees and Forests . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 63
7.15 Properties of Trees . . . . . . . . . . . . . . . . . . . . . . . . . . . . 64
7.16 Constructing Mininum Spanning Tree . . . . . . . . . . . . . . . . . . 65
7.16.5 Kruskal’s Algorithim . . . . . . . . . . . . . . . . . . . . . . . 66
7.17 Hamiltonian Circuits . . . . . . . . . . . . . . . . . . . . . . . . . . . 68
Page 6 of 73
1 Set Theory
1.1 Introduction to Set Theory
Definition 1.1.1 (Set) A set is a collection of objects (elements).
Example 1.1.2 The following are some of the useful examples of sets in this course;
(1) N = {0, 1, 2, 3, ...} is the set of natural numbers.
(2) Z = {..., −3, −2, −1, 0, 1, 2, 3, ...} is the set of all integers.
(3) Q = { ab : a, b ∈ Z and b 6= 0} is the set of all rational numbers.
(4) R is the set of all real numbers.
(5) C = {z|z is a complex number}.
(6) ∅ or {} is the empty set. It has no elements.
And N ⊂ Z ⊂ Q ⊂ R ⊂ C.
Example 1.2.2 The set {n2 | n ∈ N} is the set of all numbers of the form n2 such
that n is a natural number. So it is the set of all square natural numbers.
Example 1.2.3 {a ∈ R | a > 0} which is the set of all real numbers a such that a is
bigger than zero. So it is the set of all positive real numbers.
Page 7 of 73
Using this notation we can now describe some standard ways of defining new sets in
terms of sets that we already know about.
A ∩ B = {a | a ∈ A and a ∈ B}
A ∪ B = {a | a ∈ A or a ∈ B}.
A \ B = {a | a ∈ A and a ∈
/ B}
Sometimes we will work within one fixed set U , called the universal set. For any set
A ⊂ U , we define the complement of A, denoted by A0 , to be the set
A0 = {a|a ∈ U and a ∈
/ A}.
Then
A∩B = {a ∈ R|2 ≤ a ≤ 3}
A∪B = {a ∈ R|0 < a < 4}
A0 = {a ∈ R|a ≤ 0 or a > 3}
A\B = {a ∈ R|0 < a < 2}.
(ii) A ∪ ∅ = A and A ∩ ∅ = A;
(iii) A ∪ (B ∪ C) = (A ∪ B) ∪ C and A ∩ (B ∩ C) = (A ∩ B) ∩ C;
(iv) A ∪ B = B ∪ A and A ∩ B = B ∩ A;
(v) A ∪ (B ∩ C) = (A ∪ B) ∩ (A ∪ C);
(vi) A ∩ (B ∪ C) = (A ∩ B) ∪ (A ∩ C).
Page 8 of 73
Proof.
We will prove (i) and (iii) and leave the remaining results to be proven as an exercise.
(i) Observe that
A ∪ A = {a|a ∈ A or a ∈ A}
= {a|a ∈ A}
=A
and
A ∩ A = {a|a ∈ A and a ∈ A}
= {a|a ∈ A}
= A.
Also, A\A = A ∩ A0 = ∅.
A ∪ (B ∪ C) = A ∪ {a|a ∈ B or a ∈ C}
= {a|a ∈ A or a ∈ B, or a ∈ C}
= {a|a ∈ A or a ∈ B} ∪ C
= (A ∪ B) ∪ C.
Definition 1.2.9 (Equality of Sets) Two sets A and B are equal, written A = B,
if we can show that A ⊂ B and B ⊂ A.
(ii) (A ∩ B)0 = A0 ∪ B 0 .
Proof
Page 9 of 73
Example 1.2.11 Other relations between sets often hold true. For example,
(A\B) ∩ (B\A) = ∅.
(A\B) ∩ (B\A) = (A ∩ B 0 ) ∩ (B ∩ A0 )
= A ∩ A0 ∩ B ∩ B 0
= ∅.
Definition 1.2.12 (Cartesian Product) Let A and B be sets. Then we can define
a new set A × B, called the Cartesian product of A and B, as a set of ordered pairs.
That is,
A × B = {(a, b) | a ∈ A and b ∈ B}.
Here (a, b) is the ordered pair whose first coordinate is a and whose second coordinate
is b.
Example 1.2.13 Let A = {a, b}, B = {1, 2, 3}, and C = ∅. Then A × B is the set
A × B = {(a, 1), (a, 2), (a, 3), (b, 1), (b, 2), (b, 3)}
and
B × A = {(1, a), (1, b), (2, a), (2, b), (3, a), (3, b)}
and
A × C = ∅.
2 Relations
2.1 Functions and Relations
Definition 2.1.1 (Relation) For sets A and B, a relation between A and B is any
subset of the Cartesian product A × B. In the case where A = B, we speak of R being
a relation in A.
Remark 2.1.2 Since A × B and B × A are not generally the same sets (i.e A × B 6=
B × A), a relation between A and B maybe quite a different mathematical object from
a relation between B and A.
Page 10 of 73
Definition 2.1.3 (Domain and range) Let R ⊆ A × B be a relation. The domain
of R (domR) is defined by
(b) it may happen that domR = A, then R is called a relation from A into B.
(vi) For most functions f : A −→ B it is not the case that rngf = B. And this will
lead to the definition of Surjectivity (onto).
Page 11 of 73
How do we check for one-to-oneness ?
ALGEBRAICALLY
(2) suppose that f (x1 ) = f (x2 ), show that x1 = x2 for all x1 , x2 ∈ domf .
If f is a continuous function, then f is one-to-one iff it is strictly increasing,
which is equivalent to the derivative been always positive or always negative in
the case where f is differentiable.
(i) Two functions f and g are identical iff they are composed of the same ordered
pairs.
(ii) Equivalently, f = g iff domf = domg and f (a) = g(a) for each a in their
common domain.
Suppose that f and g are functions whose ranges are a subset of a system in which
addition, multiplication and division are permissible, then we can define functions
f + g, f · g and fg as;
f + g is called the pointwise sum and f · g is called the pointwise product of f and g.
Page 12 of 73
In other words, the composition of two functions f and g denoted f ◦ g is defined by
f −1 = {(b, a)|(a, b) ∈ f }
Page 13 of 73
3 Counting Principles
3.1 Introduction
Counting problems arise throughout mathematics and computer science. For ex-
ample, we must count the successful outcomes of experiments and all the possible
outcomes of these experiments to determine probabilities of discrete events.
In this chapter, we will introduce the basic techniques of counting. These methods
serve as the foundation for almost all counting techniques.
The number of ways to select an element from A or from B, that is, the number
of ways to select an element from their union, is the sum of the number of ways to
select an element from A and the number of ways to select an element from B, minus
the number of ways to select an element that is in both A and B.
Definition 3.2.1 (The Multiplication Rule) Suppose that a procedure can be bro-
ken down into a sequence of two tasks. If there are n1 ways to do the first task and
for each of these ways of doing the first task, there are n2 ways to do the second task,
then there are n1 n2 ways to do the procedure.
Example 3.2.2 How many different bit strings of length seven are there?
Solution
Each of the seven bits can be chosen in two ways, because each bit is either 0 or 1.
Therefore, the multiplication rule shows there are a total of 27 = 128 different bit
strings of length seven.
Example 3.2.3 The chairs of the MPF exam room at CBU are to be labelled with
an uppercase English letter followed by a positive integer not exceeding 100. What is
the largest number of chairs that can be labelled differently?
Solution
The procedure of labelling a chair consists of two tasks, namely, assigning to the seat
one of the 26 uppercase English letters, and then assigning to it one of the 100 pos-
sible integers. The multiplication rule shows that there are 26 · 100 = 2600 different
Page 14 of 73
ways that a chair can be labelled. Therefore, the largest number of chairs that can be
labelled differently is 2600.
Theorem 3.2.4 (Permutation) If n, r ∈ Z such that 0 ≤ r ≤ n, then
n n!
Pr =
(n − r)!
By Theorem 3.2.4 we know that if n ∈ Z+ , then n Pn = n!. We will illustrate this
result with some examples.
Example 3.2.5 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?
Solution
Because it matters which person wins which prize, the number of ways to pick the
three prize winners is the number of ordered selections of three elements from a set of
100 elements, that is, the number of 3-permutations of a set of 100 elements. Conse-
quently, the answer is
100 100!
P3 =
(100 − 3)!
= 970200
Example 3.2.6 Suppose that a saleswoman has to visit eight different cities. She
must begin her trip in a specified city, but she can visit the other seven cities in any
order she wishes. How many possible orders can the saleswoman use when visiting
these cities?
Solution
The number of possible paths between the cities is the number of permutations of seven
elements, because the first city is determined, but the remaining seven can be ordered
arbitrarily. Consequently, there are 7! = 7 · 6 · 5 · 4 · 3 · 2 · 1 = 5040 ways for the
saleswoman to choose her tour. If, for instance, the saleswoman wishes to find the
path between the cities with minimum distance, and she computes the total distance
for each possible path, she must consider a total of 5040 paths!
Page 15 of 73
Example 3.2.9 How many different strings can be made by reordering the letters of
the word M AT HEM AT ICS?
Solution
We first note that the letter M is repeated twice so n1 = 2. Also, the letter A is
repeated twice so n2 = 2, and also the letter T is repeated twice so n3 = 2.
The word M AT HEM AT ICS consists of 11 letters so the number of different strings
that can be made by reordering the letters of this word is
11!
= 4989600
2! × 2! × 2!
Theorem 3.2.10 (Combination) If n, r ∈ Z such that 0 ≤ r ≤ n, then
n n!
Cr =
r!(n − r)!
Example 3.2.11 (i) How many poker hands of five cards can be dealt from a stan-
dard deck of 52 cards?
(ii) How many ways are there to select 47 cards from a standard deck of 52 cards?
Solution
(i) Because the order in which the five cards are dealt from a deck of 52 cards does
not matter, there are
52 52!
C5 = = 2, 598, 960
5!(52 − 5)!
52 52!
C47 = = 2, 598, 960
47!(52 − 47)!
Proof
From Theorem 3.2.10, we have
n n!
Cr = .
r!(n − r)!
Page 16 of 73
Now,
n n!
Cn−r =
(n − r)![n − (n − r)]!
n!
=
(n − r)!(n − n + r)!
n!
=
(n − r)!r!
= n Cr
and this completes our proof.
Theorem 3.2.13 (The Binomial Theorem) Let x and y be variables, and let n
be a nonnegative integer. Then
n
n
X n n−k k
(x + y) = x y .
k=0
k
Solution
2
2
X 2
(x + y) = x2−k y k
k=0
k
2 2 0 2 1 1 2 0 2
= xy + xy + xy
0 1 2
= x2 + 2xy + y 2 .
Example 3.2.15 What is the expansion of (x + y)4 ?
Solution
4
4
X 4 4−k k
(x + y) = x y
k=0
k
4 4 0 4 3 1 4 2 2 4 1 3 4 0 4
= xy + xy + xy + xy + xy
0 1 2 3 4
= x4 + 4x3 y + 6x2 y 2 + 4xy 3 + y 4 .
Example 3.2.16 What is the coefficient of x12 y 13 in the expansion of (x + y)25 ?
Solution
From the binomial theorem it follows that this coefficient is
25 25!
= = 5200300.
13 13!(25 − 13)!
Page 17 of 73
Example 3.2.17 What is the coefficient of x12 y 13 in the expansion of (2x − 3y)25 ?
Solution
First, note that this expression equals (2x + (−3y))25 . By the binomial theorem, we
have
25
25
X 25
(2x + (−3y)) = (2x)25−k (−3y)k
k=0
k
Proof
Using the binomial theorem with x = y = 1, we have
n n
n
X
n n n−k k X n
2 = (1 + 1) = 1 1 =
k=0
k k=0
k
Proof
Using the binomial theorem with x = 1 and y = −1, we have
n n
n
X n n−k k
X
k n
0 = (1 + (−1)) = 1 (−1) = (−1)
k=0
k k=0
k
Page 18 of 73
4 The Fundamentals of Logic
We now look at what constitutes a valid argument and a more conventional proof.
When a mathematician wishes to provide a proof for a given situation, he or she
must us a system of logic. This is also true when a computer scientist develops the
algorithm needed for a program or system of programs. The logic of mathematics is
applied to decide whether one statement follows from, or is a logical consequence of
one or more other statements.
Some times two or more statements can be combined to form a compound statement.
To do so, we use the following logical connectives as; Conjunction, Disjunction, Im-
plication and Biconditional.
Page 19 of 73
Definition 4.1.8 (Conjunction) If p and q are statements, then the conjunction
of p and q is ”p and q,” denoted by p ∧ q. It is true when both p and q are true. If
either p or q is false, or if both are false, p ∧ q is false.
We use the word ”or” in the inclusive sense. The exclusive ”or” is denoted by p Y q.
And so the compound statement p Y q is true if one or the other of p, q is true but
not both of the statements p, q are true. One way to express p Y q for Example 4.1.3
here is ”Discrete mathematics is a required course for computer scientists, or James
wrote I love discrete mathematics, but not both.”
Definition 4.1.12 (Implication) If p, q are statements, then the implication of p
and q denoted by p → q and reads ”p implies q designates the statement which is the
implication of q by p.
The alternative of Definition 4.1.12, we say that;
(i) ”if p, then q” (ii) p is sufficient for q” (iii) ”p is a sufficient condition for q.”
Throughout our discussion on logic, we must realise that a sentence such as;
Page 20 of 73
”The number x is an integer”
is not a statement because its truth value (true or false) can not be determined until
a numerical value is assigned for x. That is if x is assigned the value say x =
√7, then
the result would be true. Otherwise, assigning x to be such that x = 1/2, π, 2, then
the resulting statement would be false.
Let use now define ”0” to represent ”false”, and ”1” to represent ”true”, then we
can construct the truth table for the component statements p, q to investigate the
idea of the truth or falsity of compound statements which are dependent only on the
truth values of its components. That is;
p ¬p
0 1
1 0
From Table 1, we construct the following truth table of compound statements as;
Observation 4.1.17 From Table 2, we notice that the statement p ∧ q is true only
when both statements p, q are true, whereas, p ∨ q is false only when both component
statements p, q are false. Similarly, as we noted before, p Y q is true when exactly
on of the statements p, q is true. For the implication p → q, the result is true in all
cases, except where p is true and q is false, because we do not want a true statement
to lead us into believing something that is false.
Finally, the bi-condition p ↔ q is true when the statements p, q have the same truth
values and is false otherwise.
We now investigate a little further some of these initial concepts or ideas about
connectives.
Page 21 of 73
Example 4.1.18 Let s, t and u denote the following primitive statements;
s : Timothy goes out for a walk.
t : The moon is out.
u : It is raining.
The following English statements provide possible translations for the given (symbolic)
compound statements.
(i) (t ∧ ¬u) → s: If the moon is out and it in not raining, the Timothy goes out
for a walk.
(ii) t → (¬u → s): If the moon is out, then if it is not raining, Timothy goes out
for a walk.
(iii) ¬(s ↔ (u ∨ t)): It is not the case that Timothy goes out for a walk if and only
if it is raining or the moon is out.
We now work in reverse order to examine the logical (or symbolic) notation for the
three given English sentences;
(iv) ”Timothy will go out for a walk if and only if the moon is out.” Here the words
”if and only if” indicate that we are dealing with a bi-conditional. In symbolic
form, this becomes s ↔ t.
(v) ”If it is raining and the moon is not out, then Timothy will not go out for a
walk.” This compound statement is an implication where the hypothesis is also
a compound statement. Thus, we express this statement in symbolic form as
(u ∧ ¬t) → ¬s.
(vi) ”It is raining and Timothy will still go out for a walk.” This sentence is repre-
sented symbolically as u ∧ s.
In computer science the if-then and if-then-else decision structures arise (in various
formats) in high-level programming languages such as Python, Java, and C + +. The
hypothesis p is often a relational expression such as x > 2. This expression then
becomes a (logical) statement that has the truth value 0 or 1, depending on the
value of the variable x at that point in the program. The conclusion q is usually an
executable statement.” (So q is not one of the logical statements that we have been
discussing.) When dealing with ”if p then q,” in this context, the computer executes
q only on the condition that p is true. For p false, the computer goes to the next
instructionin the program sequence. For the decision structure ”if p then q else r,”
here q is executed when p is true and r is executed when p is false.
Example 4.1.19 Let p, q, r be primitive statements statements defined by
p : student’s grade is greater than or equal to 60
q : student has passed
r : student has failed
A pseudo-code for the if-then maybe written as follows;
Page 22 of 73
if p >= 60 then
print q
else
print r
Through out this section, we will denote a tautological compound statement by T0 and
any contradiction compound statement by F0 . In the later sections, we will use the
ideas of tautology and implication to describe a valid argument. This will be of greater
interest and importance to develop needed skills for proving mathematical theorems.
In general, an argument starts with a list of given statements called premises and a
statement called the conclusion of the argument. We examine these premises, say
p1 , p2 , . . . , pn , and try to show that the conclusion q follows logically from these given
statements-that is, we try to show that if each of p1 , p2 , . . . , pn is a true statement,
then the statement q is also true. To do so one way is to examine the implication
(p1 ∧ p2 ∧ · · · ∧ pn ) −→ q
(p1 ∧ p2 ∧ · · · ∧ pn ) −→ q
is true. Consequently, if we start with the premises p1 , p2 , . . . , pn each with truth value
1, and find that under these circumstances q has the value 1, then the implication
(p1 ∧ p2 ∧ · · · ∧ pn ) −→ q
Now the study of logic is referred to as the algebra of propositions (as opposed to
the algebra of real numbers). In logic we use the truth tables of the statements, or
propositions, to develop an idea of when two such entities are essentially the same.
2
At this point we have dealt only with the conjunction of two statements, so we must point out
that conjunction p1 ∧ p2 ∧ · · · ∧ pn of n statements is true if and only if each pi , 1 ≤ i ≤ n, is true.
Page 23 of 73
Consider the following example;
Example 4.2.1 For premitive statements p and q. The following table below provides
the truth tables for the compound statements ¬p ∨ q and p → q. Here we see that the
corresponding truth tables for the two statements ¬p ∨ q and p → q are exactly the
same
p q ¬p ¬p ∨ q p → q
0 0 1 1 1
0 1 1 1 1
1 0 0 0 0
1 1 0 1 1
(p → q) ≡ ¬p ∨ q
And in the same manner, from the Table in Example 4.2.1 we have
(p ↔ q) ≡ (p → q) ∧ (q → p)
Therefore, we can deduce that when s1 and s2 are logically equivalent statements
(i.e. s1 ≡ s2 ), then the compound statement s1 ↔ s2 is a tautology. Under these
circumstances it is also true that ¬s1 ≡ ¬s2 and so ¬s1 ↔ ¬s2 is also a tautology.
3
When s1 ≡ s2 the statements s1 and s2 provide the same truth tables since s1 , s2 have the same
truth values for all choices of truth values for their primitive components
Page 24 of 73
4.2.3 The Laws of Logic
Using the concepts of logical equivalence, tautology, and contradiction, we state the
following list of laws for the algebra of proposition.
Theorem 4.2.4 (Laws of Logic) For any primitive statements p, q, r and any tau-
tology T0 and any contradiction F0 ;
Example 4.2.5 (Simplifying Statement Forms) Use Theorem 4.2.4 to verify the
logical equivalence ¬(¬p ∧ q) ∧ (p ∨ q) ≡ p.
Solution:
Solution
This statement contains four occurences of pprimitive statements, three negation sym-
bols, and three connectives. From the laws of logic, it follows that
Page 25 of 73
[(p ∨ q) ∧ r] ∧ q ≡ (p ∨ q) ∧ (r ∧ q) Associative law of ∧
≡ (p ∨ q) ∧ (q ∧ r) Commutative law of ∧
≡ [(p ∨ q) ∧ q] ∧ r Associative law of ∧
≡q∧r Absorption law and commutative laws for ∧ and ∨
5 Boolean Algebra
We now encounter an algebraic system in which the structure depends primarily on
two closed binary operations. In dealing with Boolean algebras, we shall applications
more than the abstract nature of the system.
In order to investigate such two state devices, we abstract these notions of ”true”
and ”false”, ”on” and ”off” as follows;
Let B = {0, 1}. We define addition, multiplication, and complements for these ele-
ments of B by;
(i) Addition:
0 + 0 = 0; 0+1=1+0=0+1=1+1=1
(ii) Multiplication:
0 · 0 = 0 = 1 · 0 = 0 · 1; 1·1=1
(iii) Complement:
0̄ = 1; 1̄ = 0.
Suppose that x, y are Boolean variables, then the following hold true;
Page 26 of 73
(ii) xy = 1 if and only if x = y = 1.
Definition 5.1.2 (Boolean or Switching Function) A function f : B n −→ B is
called a Boolean or switching function of n Boolean variables, where n ∈ Z+ and
B n = {(b1 , b2 , . . . , bn )|bi ∈ {0, 1}, 1 ≤ i ≤ n}.
Example 5.1.3 Let f : B 3 −→ B, where f (x, y, z) = xy + z. This Boolean function
is determined by evaluating f for each of the eight possible assignments to the Boolean
variables x, y, z as tables demonstrates below;
x y z xy f (x, y, z) = xy + z
0 0 0 0 0
0 0 1 0 1
0 1 0 0 0
0 1 1 0 1
1 0 0 0 0
1 0 1 0 1
1 1 0 1 1
1 1 1 1 1
Definition 5.1.4 (Equality of Boolean Functions) Let f : B n −→ B and g :
B n −→ B for n ∈ Z+ , n ≥ 2 be two Boolean functions of the n Boolean variables
x1 , x2 , . . . , xn . We say that f and g are equal and write f = g if the columns for f, g
[in their respective (function) tables] are exactly the same. That is the table shows
that
f (b1 , b2 , . . . , bn ) = g(b1 , b2 , . . . , bn )
for each of the 2n possible assignments of either 0 or 1 to each of the n Boolean
variables x1 , x2 , . . . , xn .
Definition 5.1.5 (Complement of a Boolean Function) Suppose that
f : B n −→ B is a Boolean function, then the complement of f , denoted by f¯, is the
Boolean function defined on B n by
f¯(b1 , b2 , . . . , bn ) = f (b1 , b2 , . . . , bn ).
5
When dealing with Boolean variables multiplication is performed before addition. Hence, xy + z
represents (xy) + z, not x(y + z).
Page 27 of 73
5.1.7 Ten Important Laws In Boolean Algebra
(1) Law of Double Complement;
f¯ = f ; x̄¯ = x
f + g = f¯ · ḡ; x + y = x̄ · ȳ
f · g = f¯ + ḡ x · y = x̄ + ȳ
f + g = g + f; x+y =y+x
f g = gf ; xy = yx
f + (g + h) = (f + g) + h; x + (y + z) = (x + y) + z
(f g)h = f (gh); (xy)z = x(yz)
f + f = f; x+x=x
f · f = f; x·x=x
f + 0 = f; x+0=x
f · 1 = f; x·1=x
f + 1 = 1; x+1=1
f · 0 = 0; x·0=0
f + f¯ = 1; x + x̄ = 1
f · f¯ = 0; x · x̄ = 0
Page 28 of 73
(10) Absorption Laws;
f + fg = f; x + xy = x
f (f + g) = f ; x(x + y) = x
Example 5.1.8 To establish the first absorption property for Boolean variables, we
argue as follows;
x + xy = x · 1 + xy Reasons
= x · 1 + xy Identity law
= x(1 + y) Distributive law
=x·1 Dominance law (and commutative law of +)
=x Identity law.
wx + x̄z + (y + z̄)
Solution
Reasons
wx + x̄z + (y + z̄) = wx + (x̄¯ + z̄) + (y + z̄) De Morgans law
= wx + (x + z̄) + (y + z̄) Law of double complement
= [(wx + x) + z̄] + (y + z̄) Associative law of +
= (x + z̄) + (y + z̄) Absorption law and the commutative law of + and ·
= x + (z̄ + z̄) + y Commutative associative laws of +
= x + z̄ + y Idempotent law of +
Page 29 of 73
(iii) a representation of f as a sum of fundamental conjunctions a disjunctive normal
form(d.n.f ) of f .
Example 5.1.12 Given three Boolean variables x, y, z, find formulas for functions
f, g, h : B 3 −→ B for the columns specified in the table below;
x y z f g h
0 0 0 0 0 0
0 0 1 1 0 1
0 1 0 0 0 0
0 1 1 0 0 0
1 0 0 0 1 1
1 0 1 0 0 0
1 1 0 0 0 0
1 1 1 0 0 0
Solution
For the column under f , we want a result that has the value 1 only in the case where
x = y = 0 and z = 1. And so the function
f (x, y, x) = x̄ȳz
g(x, y, z) = xȳz̄
yields the value 1 for x = 1, y = z = 0, and is 0 in all other cases. Now since each of
f and g has the value 1 in only one case and these cases are distinct from each other,
their sum f + g has the value 1 in exactly these two cases. So
Example 5.1.13 Find the disjunctive normal form (d.n.f ) for f : B 3 −→ B, where
f (x, y, z) = xy + x̄z. Given the table of values as;
x y z xy x̄z f
0 0 0 0 0 0
0 0 1 0 1 1
0 1 0 0 0 0
0 1 1 0 1 1
1 0 0 0 0 0
1 0 1 0 0 0
1 1 0 1 0 1
1 1 1 1 0 1
Page 30 of 73
Solution
From the table, we see that the column for f contains four 1’s. They indicate the four
fundamental conjunctions needed in the d.n.f. of f , so
Another way to solve this problem is to take each product term appearing in f -namely,
xy and x̄z-and somehow involve whichever variables are missing. Using the properties
of these variables, we have xy+x̄z = xy(z+z̄)+x̄(y+ȳ)z (why)= xyz+xyz̄+x̄yz+x̄ȳy.
Solution
We examine each term, as follows;
Page 31 of 73
6 Proof Techniques
6.1 Mathematical Induction
6.1.1 Introduction
Consider a sequence of dominoes in the figure below;
6.1.4 How To Do It
(i) Consider an initial value for which the statement is true, that is for n = 1.
(ii) Assume the statement is true for any value of n = k, k ∈ Z+ . Then prove the
statement is true for n = k + 1, where k is any positive integer. We actually
break n = k + 1 into two parts, one part is n = k (which is already proved) and
try to prove the other part.
Page 32 of 73
Transitive Property
The transitive property states that, if for all a, b, c ∈ R, suppose a < b and b < c,
then a < c.
6.2 Examples
Example 6.2.1 Prove by mathematical induction that for all natural numbers n ∈ N
n(n + 1)
1 + 2 + 3 + ··· + n =
2
Proof:
We use mathematical induction to prove that
n(n + 1)
1 + 2 + 3 + ··· + n =
2
for all n ≥ 1.
Step 1: For n = 1: We have
1(1 + 1)
1 + 2 + 3 + ··· + 1 = =1
2
which is a true statement.
(k)(k + 1)
1 + 2 + 3 + · · · + k + (k + 1) = +k+1
2
k(k + 1) + 2(k + 1)
=
2
(k + 1)(k + 2)
=
2
Page 33 of 73
which is exactly equal to Equation (2). Hence, deduced. Therefore, since the statement
is true for n = 1, n = k and n = k + 1 for k ∈ Z, then by Mathematical Induction
n(n + 1)
1 + 2 + 3 + ··· + n =
2
for all natural numbers n.
Example 6.2.2 Prove by mathematical induction that
n(n + 1)(2n + 1)
12 + 22 + 32 + · · · + n2 =
6
Proof:
To prove that
n(n + 1)(2n + 1)
12 + 22 + 32 + · · · + n2 =
6
Step 1: We first prove that this is true for all n = 1 that is
1(1 + 1)(2 × 1 + 1) 6
12 + 22 + 32 + · · · + 12 = = =1
6 6
which is a true statement.
Page 34 of 73
which is exactly equal to the required result in Equation (4). Since the statement is
true for n = 1, n = k and n = k + 1 k ∈ Z, then by mathematical induction:
n(n + 1)(2n + 1)
12 + 22 + 32 + · · · + n2 =
6
for all natural numbers.
Recall the transitive property that if a, b and b are natural numbers, then
Solution
We use the principle of mathematical induction to prove that
2n > n
And then prove that the statement is true for all n = k + 1, k ∈ Z, that is
Deducing Inequality (7) from Inequality (6) we multiplying through Inequality (6) by
2 we get;
2 · 2k > 2k
⇒ 2k+1 > 2k
Since
2k+1 > 2k > k + 1
Page 35 of 73
then by the transitive property
2k+1 > k + 1
Hence deduced. Since the statement is true for n = 1, n = k and n = k + 1, then by
mathematical induction
2n > n for all n ≥ 1
for all integers.
3n ≥ 2n + 1
Proof:
Step 1: If n = 1, we have
31 ≥ 2(1) + 1 = 3
which is a true statement.
3k ≥ 2k + 1 (8)
and prove that the statement is also true for n = k + 1, where k ∈ Z. That is
We start with the hypothesis to deduce Inequality (9) from Inequality (8). From;
3k ≥ 2k + 1
Now since
3k+1 ≥ 6k + 3 ≥ 2k + 1
then by the transitive property we have
3k+1 ≥ 2k + 1
as required. Hence deduced. Now since the statement is true for n = 1, n = k and
for n = k + 1, then the statement is true for all positive integers.
2n ≥ n + 1.
Proof:
Step 1: If n = 1, then
2n ≥ n + 1 ⇒ 21 ≥ 1 + 1 = 2
Page 36 of 73
which is a true statement.
and prove that the statement is true for n = k + 1 for all k ∈ Z, that is
2k+1 ≥ k + 2 (11)
2k ≥ k + 1
. Now
2k1 ≥ 2k + 2 ≥ k + 2
then by the transitive property we have
2k+1 ≥ k + 2.
Solution
To show that 4n − 1 is divisible by 3;
Step 1: We first show that for n = 1, 4n − 1 is divisible by 3. Since if n = 1, we
have;
4n − 1 = 41 = 3
which is divisible by 3.
4k − 1, ∀ k ∈ Z (12)
4k+1 − 1 (13)
is divisible by 3. Starting with the assumption (12) to deduce the following statement
(13). Let x be any positive integer such that
4k − 1 = 3x.
Page 37 of 73
Then multiplying through by 4 we get;
4(4k − 1) = 4(3x)
⇒ 4k+1 − 4 = 12x
⇒ 4k+1 − 1 − 3 = 12x
⇒ 4k+1 − 1 = 12x + 3
⇒ 4k+1 − 1 = 3(4x + 1) (14)
Since the right hand side of (14) is divisible by 3, then 4k+1 − 1 is also divisible by
3. Therefore, since the statement is true for n = 1, n = k and n = k + 1, then we
conclude that 4k − 1 is divisible by 3 for all positive integers.
Solution
Step 1: If n = 1, then
6n − 1 = 61 − 1 = 5
which is divisible by 5. Hence true statement.
6k+1 − 1
6k − 1 = 5m
6(6k − 1) = 6(5m)
⇒ 6k+1 − 6 = 30m
⇒ 6k+1 − 1 − 6 = 30m
⇒ 6k+1 − 1 = 30m + 5
⇒ 6k+1 − 1 = 5(6m + 1) (15)
Since the right hand side of equation 15 is divisible by 5, then 6k − 1 is also divisible
by 5. Now since the statement is true for n = 1, n = k and n = k + 1 then we
conclude that 6n − 1 is divisible by 5 for all positive integers n.
Page 38 of 73
7 Graphs Theory
7.1 Introduction to Graphs Theory
Imagine an organization that wants to set up teams of three to work on some projects.
In order to maximize the number of people on each team who had previous experience
working together successfully, the director asked the members to provide names of
their past partners. This information is displayed on Table 3:
Table 3:
Figure 2:
As we can see from the drawing in Figure 2, it is possible for two edges to cross at a
point that is not a vertex. Note also that the type of graph described here is quite
different from the ”graph of an equation” or the ”graph of a function.” The edges
Page 39 of 73
may be straight or curved and should either connect one vertex to another or a vertex
to itself, as shown in Figure 3:
Figure 3:
In Figure 3, the vertices have been labelled with v ’s and the edges with e’s. When
an edge connects a vertex to itself (as e5 does), it is called a loop. When two edges
connect the same pair of vertices (as e2 and e3 do), they are said to be parallel. It is
quite possible for a vertex to be unconnected by an edge to any other vertex in the
graph (as v5 does), and in that case the vertex is said to be isolated.
An edge with just one endpoint is called a loop, and two or more distinct edges
with the same set of endpoints are said to be parallel. An edge is said to connect
its endpoints; two vertices that are connected by an edge are called adjacent; and a
vertex that is an endpoint of a loop is said to be adjacent to itself.
An edge is said to be incident on each of its endpoints, and two edges incident
on the same endpoint are called adjacent. A vertex on which no edges are incident
is called isolated.
Page 40 of 73
Example 7.1.2 Consider the following graph (see Figure 4):
Figure 4:
(i) Write the vertex set and the edge set, and give a table showing the edge-endpoint
function.
(ii) Find all edges that are incident on v1 , all vertices that are adjacent to v1 , all
edges that are adjacent to e1 , all loops, all parallel edges, all vertices that are
adjacent to themselves, and all isolated vertices.
Solution:
Edge Endpoints
e1 {v1 , v2 }
e2 {v1 , v3 }
e3 {v1 , v3 }
e4 {v2 , v3 }
e5 {v5 , v6 }
e6 {v5 }
e7 {v6 }
Page 41 of 73
Definition 7.1.3 (Directed Graph) A directed graph, or digraph, consists of
two finite sets; a nonempty set V (G) of vertices and a set E(G) of directed edges,
where each is associated with an ordered pair of vertices called endpoints. If edge e
is associated with the pair (u, v) of vertices, then e is said to be the directed edge
from u to v.
Telephone, electric power, gas pipeline, social network, and air transport systems
can all be represented by graphs, as can computer networks–from small local area
networks to the global internet system that connects millions of computers worldwide.
Questions that arise in the design of such systems involve choosing connecting edges
to minimize cost, optimize a certain type of service, and so forth.
A typical network, called a hub and smoke model, is shown below (see Figure 5):
Figure 5:
Page 42 of 73
Example 7.3.2 (Some Examples of Simple Graphs) See Figure 6:
Figure 6:
Example 7.3.3 (A Simple Graph) Draw all simple graphs with four vertices {u, v, w, x}
and two edges, one of which is {u, v}.
Solution:
Each possible edge of a simple graph correspond to a subset of two vertices. Given
4
four vertices, there are 2 = 6 such subsets in all:
{u, v}, {u, w}, {u, x}, {v, w}, {v, x}, and {w, x}.
Figure 7:
Figure 8:
Page 43 of 73
Definition 7.3.6 (Complete Bipartite Graph) Let m and n be positive integers.
A complete bipartite graph on (m, n) vertices, denoted Km,n , is a simple graph
with distinct vertices u1 , u2 , . . . , um and v1 , v2 , . . . , vn that satisfies the following prop-
erties: For all i, k = 1, 2, . . . , m and for all j, l = 1, 2, . . . , n,
Figure 9:
Example 7.3.9 (Subgraphs) List all subgraphs of the graph G with vertex set {v1 , v2 }
and edge set {e1 , e2 , e3 }, where the endpoints of e1 are v1 and v2 , the endpoints of e2
are v1 and v2 , and e3 is a loop at v1 .
Page 44 of 73
Solution:
G can be drawn as shown below (see Figure 10):
Figure 10:
There are 11 subgraphs of G, which can be grouped according to those that do not have
any edges, those that have one edge, those that have two edges, and those that have
three edges. The 11 subgraphs are shown in Figure 10:
Definition 7.4.2 (Join) The joint G = G1 + G2 has V (G) = V (G1 ) ∪ V (G2 ) and
E(G) = E(G1 ) ∪ E(G2 ) ∪ {vw | v ∈ V (G1 ) and w ∈ V (G2 )}.
The graph G = G1 + G2 = K2 + K3 is shown in Figure 12:
Page 45 of 73
Figure 12: The join of two graphs
v1 = w1 and v2 w2 ∈ E(G2 )
or
v2 = w2 and v1 w1 ∈ E(G1 ).
Figure 13:
Page 46 of 73
Figure 14: A graph and its complement
Figure 15:
Example 7.5.2 (Degree of a Vertex and Total Degree of a Graph) Find the
degree of each vertex of the graph G shown below (in Figure 16). Then find the total
degree of G.
Page 47 of 73
Figure 16:
Solution:
deg v1 = 0 since no edge is incident on v1 .
deg v2 = 2 since both e1 and e2 are incident on v2 .
deg v3 = 4.
total degree of G = deg v1 + deg v2 + deg v3 = 0 + 2 + 4 = 6.
Note that the total degree of a graph G equals twice the number of edges of G.
Roughly speaking, this is true because each edge has two end segments, and each end
segment is counted once towards the degree of some vertex. In fact, for any graph
without loops, the general result can be explained as follows: Imagine a group of
people at a party. Depending on how social they are, each person shakes hands with
various other people.
Theorem 7.5.3 (The Handshake Theorem) If G is any graph, then the sum of
the degrees of all vertices of G equals twice the number of edges of G. Specifically, if
the vertices of G are v1 , v2 , . . . , vn , where n is a nonnegative integer, then
Proposition 7.5.5 (Deduction) In any graph, there are an even number of vertices
of odd degree.
Page 48 of 73
It is often convenient to list the degrees of vertices of a graph; this is usually done
by writing them in nonincreasing order (that is, in decreasing order but allowing
’repeats’ where necessary). The resulting list is called the degree sequence of a graph.
Given a graph G, the degree sequence of G can be easily determined (we simply find
the degree of each of its vertices). For example, the graph in Figure 17 has degree
sequence 5, 4, 3, 3, 2, 2, 1, 1, 1, 0. Now we may be wondering if we can be able to draw
a graph G, given the degree sequence s. Now this leads us to the following definition:
With the aid of Theorem 7.5.7, we may now present a procedure, or algorithm, that
allows us to determine whether a finite sequence of nonnegative integers is graphical
or not.
(i) If some integer in the sequence exceeds n − 1, the the sequence is not graphical.
(ii) If all the integers in the sequence are 0, then the sequence is graphical.
(iii) If the sequence contains a negative integer, then the sequence is not graphical.
(iv) Delete the first number, say t, from the sequence and subtract 1 from the next
t numbers in the sequence to form a new sequence. Return to step 2.
Page 49 of 73
To illustrate Algorithm 7.5.8, consider the sequence:
s : 4, 4, 4, 3, 3, 2.
Step 1 is satisfied, and we begin the loop of Step 2 to 5. The tests in Step 2 and 3
do not immediately halt us. Proceeding to Step 5, we get
s01 = 3, 3, 2, 2, 2
s1 = 3, 3, 2, 2, 2. re-orderring
s02 = 2, 1, 1, 2
s2 = 2, 2, 1, 1. re-orderring
s03 = 1, 0, 1
s3 = 1, 1, 0. re-orderring
s04 = 0, 0
s4 = 0, 0. re-orderring
Algorithm 7.5.8 shows that s is graphical, since 0, 0 is the degree sequence of the
empty graph K2 on two vertices.
It should be pointed out that the graph G in Figure 18 is not the only graph with
degree sequence s. The graphs G and H in Figure 19 both have the same degree
sequence, namely 2, 2, 2, 2, 2, 2. So degree sequences do not always provide enough
information to uniquely describe a graph.
Page 50 of 73
Figure 19: Two graphs with the same degree sequence 2, 2, 2, 2, 2, 2.
Thus for the purpose of solving the puzzle, the map of Königsberg can be identified
with the graph shown in Figure 21 where the vertices A, B, C, and D represent the
land masses and the seven edges represent the seven bridges.
Page 51 of 73
In terms of this graph, the question becomes the following: It is possible find a
route through the graph that starts and ends at some vertex, one of A, B, C, or D,
and traverses each edge exactly once? Equivalently: Is it possible to trace this graph,
starting and ending at the same point, without ever lifting our pencil from the paper?
However, they are not all even: deg B = 5, deg C = 3, and deg D = 3. Hence
there is no route that solves the puzzle by starting and ending at A. Similarly when
starting at B, C, or D.
Definition 7.6.1 (Walk, Trails, Paths, and Circuits) Let G be a graph and let
v and w be vertices in G.
v0 e1 v1 e2 · · · vn−1 en vn .
where the v’s represent vertices,the e’s represent edges, v0 = v, vn = w, and for all
i = 1, 2, . . . , n, vi−1 and vi are endpoints of ei . The trivial walk from v to w consists
of the single vertex v.
A trail from v to w is a walk from v to w that does not contain a repeated edge.
A path from v to w is a trail from v to w that does not contain a repeated vertex.
A closed walk is a walk that starts and ends at the same vertex.
A circuit is a closed walk is a closed walk that contains at least one edge and does
not contain a repeated edge.
A simple circuit is a circuit that does not have any repeated vertex except the first
and last.
Page 52 of 73
For ease of reference, these definitions are summarized in Table 4:
Table 4:
Figure 22:
(i)
v1 e1 v2 e3 v3 e4 v3 e5 v4
(ii)
e1 e3 e5 e5 e6
(iii)
v2 v3 v4 v5 v3 v6 v2
(iv)
v2 v3 v4 v5 v6 v2
(v)
v1 e1 v2 e1 v1
Page 53 of 73
(vi)
v1
Solution:
(i) This is a trail from v1 to v4 .
(ii) This is just a walk from v1 to v5 .
(iii) This is a circuit.
(iv) This is a simple circuit (also known as a cycle).
(v) This is a closed walk.
(vi) This is a closed walk from v1 to v1 .
7.7 Connectedness
A graph is connected if it is possible to travel from any vertex to any other vertex
along a sequence of adjacent edges of the graph.
Definition 7.7.1 (Connectedness) Let G be a graph. Two vertices v and w of
G are connected if, and only if, there is a walk from v to w. The graph G is
connected if, and only if, given any two vertices v and w in G, there is a walk from
v to w. Symbolically,
If we take the negation of this definition, we will see that a graph G is not connected
if, and only if, there are two vertices of G that are not connected by any walk.
Example 7.7.2 (Connected and Disconnected Graphs) Which of the follow-
ing graphs are connected?
Figure 23:
Solution:
The graph of (a) is connected, whereas those of (b) and (c) are disconnected. To
understand why (c) is not connected, recall that in a drawing of a graph, two edges
may cross at a point that is not a vertex. Thus the graph in (c) can be redrawn as
follows (see Figure 24):
Page 54 of 73
Figure 24:
Some useful facts relating circuits and connectedness are collected in the following
lemma.
(ii) If vertices v and w are part of a circuit in G and one edge is removed from the
circuit, then there still exists a trail from v to w in G.
(iii) If G is connected and G contains a circuit, then an edge of the circuit can be
removed without disconnecting G.
The graphs in (b) and (c) are both made up of three pieces, each of which is itself
a connected graph. A connected component of a graph is a connected subgraph of
largest possible size.
(i) H is a subgraph of G.
The fact is that any graph is a kind of union of its connected components.
Page 55 of 73
Example 7.7.5 (Connected Components) Find all connected components of the
following graph G (see Figure 25):
Figure 25:
Solution:
G has three connected components: H1 , H2 , and H3 with vertex sets V1 , V2 , and V3
and edge sets E1 , E2 , and E3 , where
V1 = {v1 , v2 , v3 } E1 = {e1 , e2 }
V2 = {v4 } E2 = ∅
V3 = {v5 , v6 , v7 , v8 } E3 = {e3 , e4 , e5 }
Page 56 of 73
Consider the graph shown in Figure 26:
Figure 26:
The Euler circuit is shown in the graph above (see Figure 26) is:
v0 , v1 , v2 , v3 , v4 , v2 , v5 , v0 .
The analysis used earlier to solve the puzzle of the Königsberg bridges generalizes to
prove the following theorem:
Theorem 7.8.2 (Euler Circuit) If a graph has an Euler circuit, then every vertex
of the graph has positive even degree.
If some vertex of a graph has odd degree, then the graph does not have an Euler
circuit.
The contrapositive version of Theorem 7.8.2 is useful for showing that a given graph
does not have an Euler circuit.
Page 57 of 73
Example 7.8.3 (Showing That a Graph Does Not Have an Euler Circuit)
Consider the graph in Figure 27. Show that the graph does not have an Euler circuit.
Figure 27:
Solution:
Vertices v1 and v3 both have degree 3, which is odd. Hence by (the contrapositive form
of ) Theorem 7.8.2, this graph does not have an Euler circuit.
Now consider the converse of Theorem 7.8.2: If every vertex of a graph has even
degree, then the graph has an Euler circuit. Is this converse true?
The answer is no. Use counter-example to show: There is a graph G such that every
vertex of G has even degree but G does not have an Euler circuit. The illustration in
Figure 28 is such a counter-example.
Figure 28:
Note that the graph in the preceding drawing is not connected. It turns out that
although the converse of Theorem 7.8.2 is false, a modified converse is true:
Page 58 of 73
If every vertex of a graph has positive even degree and the graph is connected, then
the graph has an Euler circuit.
Figure 29:
The distance function d(u, v) on pairs of vertices is a metric, that is, it satisfies the
following fundamental properties:
Theorem 7.9.2 (The Distance Function) Let G be a graph and let u, v, w ∈ V (G).
Then
(i) d(u, v) ≥ 0 and d(u, v) = 0 if and only if u = v;
(ii) d(u, v) = d(v, u) (symmetric property);
(iii) d(u, v) ≤ d(u, w) + d(w, v) (triangle inequality).
Page 59 of 73
Figure 30:
In this particular example, it may not be too difficult to find the solution by intelligent
guesswork, but such an approach is less likely to succeed as the road network becomes
more and more complicated. In the section we describe an efficient algorithm which
can be used to find the shortest path between any two vertices in a graph.
Page 60 of 73
7.12 Distance in Weighted Graphs
Before introducing the shortest path algorithm, we will need to generalise the concept
of distance in a graph.
For example, an airline service can be represented by a weighted graph with the
vertices representing the cities serviced, edges representing the direct flying routes,
and with the weight of an edge being the cost of a direct fight. Finding the distance
between two vertices in this weighted graph corresponds to finding the minimum cost
of flying from one city to another, while a shortest path is a flying route between two
cities with the lowest cost.
Definition 7.12.2 (The Weight Matrix) Let G be a weighted graph with vertex
set V (G) = {v1 , v2 , . . . , vp }. It is convenient to represent G by means of a weight
matrix W (G) defined as follows: W (G) = (wi,j ) is p × p matrix, where
(
w(vi vj ) if vi vj ∈ E(G)
wi,j =
∞ if vi vj ∈
/ E(G).
(By 0 ∞0 we shall mean a number larger than any weight actually occurring in our
calculations.) For example, a graph and its weight matrix are shown in Figure 31,
where the weights of edges are indicated in the diagram.
Figure 31:
Page 61 of 73
7.13 Dijkstra’s Algorithm
We now introduce an algorithm, due to Dijkstra (1959), which determines, for a fixed
vertex x in a connected weighted graph G, the distance d(x, v) from x to each vertex
v of G, as well as a shortest x − v path in G. We shall write w(e) = ∞ if e ∈
/ E(G),
i.e, w(uv) = ∞ if u and v are non-adjacent vertices of G.
The idea of Dijkstra?s algorithm is to modify labels l(v) attached to the vertices,
where l(v) represents the length of the shortest x − v path presently known. As we
proceed, we reduce these labels as shorter paths are found from x to v.
(i) Set l(x) = 0 and for all v 6= x, set l(v) = ∞ and set S = V (G).
(iii) Among all the vertices in S, let u be the one of minimum label l(u).
(iv) For each v ∈ S, if uv ∈ E(G) and l(u) + w(uv) < l(v), then
Table 5:
Our results may be summarized as shown in Table 6. Using Table 5 we obtain, for
each i = 2, 3, 4, the distance from x = v1 to vi and a shortest x − vi path Pi .
Page 62 of 73
v d(x, v) Pi
v2 l(v2 ) = 1 x, v2
v3 l(v3 ) = 2 x, v3
v4 l(v4 ) = 3 x, v3 , v4
Table 6:
The desired railway system can be represented by a graph whose vertices correspond
to cities involved and which two vertices are adjacent if a track runs between the two
corresponding cities. The edges are labelled (weighted) with their proposed costs.
To solve this problem, we must find a connected graph (so that all stations can be
reached from all other stations) with the minimum sum of the edge weights. This is
called the Minimum Connector Problem.
Note that to construct a graph with minimum edge weight sum, we must avoid
cycles, since otherwise we could remove the most expensive edge (largest weight) on
the cycle, obtaining a new connected graph with smaller weight sum. Hence, it would
be possible to leave out a set of tracks between two cities and still have all cities con-
nected, implying that the original railway system is not the cheapest. Thus, what we
desire is a connected acyclic graph with minimum possible edge weight sum. Be-
fore solving the Minimum Connector Problem, we need to investigate in more detail
the type of graph we have just encountered.
Figure 32:
Figure 32 shows three trees. Trees are the simplest connected graphs. These graphs
are perhaps the most useful of all special classes of graphs. Recently, there has been
Page 63 of 73
considerable interest in tree structures arising in computer sciences and artificial intel-
ligence. We often meet such structures when organising data in a computer memory
store or when organising the flow of information through a system. Trees also have
applications in chemistry (for example, in counting alkanes Cn H2n+2 ), sociology, and
many other studies. In computer programming and switching theory, we frequently
deal with decision trees with only two alternatives at each intermediate vertex. We
will discuss mainly the application of trees in this section.
m = (n1 − 1) + (n2 − 1) + 1
= n1 + n2 − 1
=n−1
Thus, by induction, the size of a tree is one less than its order.
(i) T is a tree;
Theorem 7.15.4 (Tree, End-vertices) Every nontrivial tree contains at least two
end-vertices.
Page 64 of 73
7.16 Constructing Mininum Spanning Tree
In this subsection, we return to the Minimum Connector Problem. First we shall
need the concept of a spanning tree of a connected graph.
Definition 7.16.1 (Spanning tree, Spanning forest)
A spanning tree of a connected graph G is a tree that is a subgraph of G that contains
all the vertices of G. A spanning forest of a graph G is a forest that is a subgraph of
G that contains all the vertices of G.
A connected graph may actually have several nonisomorphic spanning trees. Figure
33 shows a graph G and three of its spanning trees T1 , T2 and T3 .
Figure 33:
Every connected graph G contains a spanning tree. We can find such a spanning tree
as follows: If G has no cycles, then the graph G itself is a spanning tree. If there are
cycles in G, then choose any cycle in G and remove one of its edges. By removing
one cycle edge in G, we still remain with a connected graph. We now repeat this
procedure, removing cycle edges one at a time, until finally only bridges remain; this
gives our spanning tree. So it is easy to find a spanning tree in a connected graph.
However, a much stronger statement can be made.
Definition 7.16.2 (Distance preserving) A spanning tree T of a connected graph
G is said to be distance preserving from a vertex v in G if dT (u, v) = dG (u, v) for
every vertex u.
Figure 34:
Page 65 of 73
Definition 7.16.4 (Minimum spanning tree)
The weight w(H) of a subgraph H of a weighted graph is the sum of the weights of the
edges of H. A minimum spanning tree of a connected weighted graph is a spanning
tree of minimum weight in the graph.
The Minimum Connector Problem is perhaps one of the best known problems in
combinatorial optimisation. Many practical problems involve connected weighted
graphs in which it is necessary to find a minimum spanning tree. Consider, for exam-
ple, a graph where each vertex represents a village, and an edge between two vertices
represents a road between the corresponding villages. The length of such a road is
indicated in the graph by assigning a weight to the corresponding edge. Telephone
line must be built along some existing roads that connect the villages with each other.
We wish to erect these telephone line in such a way that every pair of villages can
communicate by telephone. Moreover, the total number of kilometers of telephone
lines is to be minimised. The problem with which we are faced is to determine along
which roads these telephone lines should be erected to produce the desired system.
This amounts to finding the a minimum spanning tree in the connected weighted
graph.
Page 66 of 73
To illustrate Kruskal’s algorithm, we find a minimum spanning tree in the connected
weighted graph G shown in Figure 35.
Figure 35:
Fourth Choice: We cannot now choose bg, since it would create a cycle, namely
b, c, g, b. So we choose an edge of next smallest weight different from bg; this is either
cd or eg with weight 3. Let us choose cd.
Fifth Choice: We cannot now include eg in the tree, since it would create a
cycle (c, d, e, g, c). The edge of next smallest weight is dg with weight 4. Since this
edge would create a cycle (c, d, g, c), we choose instead one of the edges ab, ag, or af
with weight 6. Let us choose ag.
Sixth Choice: The edges of next smallest weight are ab and af with weight 6.
Since ab would create a cycle (a, b, c, g, a), we choose af .
This completes the spanning tree T , since the addition of any further edge would
create a cycle. The tree T (shown in Figure 36) is a minimum spanning tree of weight
Page 67 of 73
Figure 36:
It is clear that Kruskal’s algorithm will produce a minimum spanning tree of any
connected weighted graph to which it is applied. It is not obvious, though, that it
produces a minimum spanning tree.
Given a graph G, is it possible to find a circuit for G in which all the edges of G
appear exactly once?
Theorem 7.17.1 (Euler Circuit) A graph G has an Euler circuit if, and only if,
G is connected and every vertex of G has positive even degree.
Given a graph G, is it possible to find a circuit for G in which all the vertices of
G (except the first and the last) appear exactly once?
Page 68 of 73
In 1859, the Irish mathematician Sir William Rowan Hamilton introduced a puzzle
in the shape of a dodecahedron (DOH-dek-a-HEE-dron). A dodecahedron is a solid
figure with 12 identical pentagonal faces. See Figure 37:
Figure 37:
Hamilton labelled each vertex with the name of a city–eg Lusaka, Kitwe, Kabwe,
Luanshya, and so on. The problem Hamilton posed was:
Is it possible to start at one city and tour the country by visiting each other city
exactly once and return to the starting city?
Page 69 of 73
One way to solve the puzzle is to imagine the surface of the dodecahedron stretched
out and laid flat in a plane as in Figure 38:
Figure 38:
The circuit denoted in black lines is one solution. Note that although every city is
visited, many edges are not included in the circuit hence this is not an Euler circuit.
The following definition is made in honor of William Rowan Hamilton:
Definition 7.17.2 (Hamiltonian Circuit) Given a graph G, a Hamiltonian cir-
cuit for G is a simple circuit that includes every vertex of G. That is, a Hamiltonian
circuit for G is a sequence of adjacent vertices and distinct edges in which every vertex
of G appears exactly once, except for the first and the last, which are the same.
Note that an Euler circuit for a graph G:
(i) Must include every vertex and every edge of G.
(ii) Must visit every vertex exactly once except the start and end vertex.
Hence a Hamilton circuit may not be an Euler circuit.
To check whether G has an Euler circuit, we use Theorem 7.17.1. For checking a
Hamiltonian circuit, where G has at least two vertices, there is following:
Proposition 7.17.3 (Hamiltonian Circuit) If a graph G has a Hamiltonian cir-
cuit, then G has a subgraph H with the following properties:
(i) H contains every vertex of G.
Page 70 of 73
(ii) H is connected.
Figure 39:
Note that H has the same number of edges as it has vertices since all its 8 edges are
distinct and so are its 8 vertices v1 , v2 , . . . , v8 and back to v1 . Also, by definition of
Hamiltonian circuit, every vertex of G is a vertex of H, and H is connected since any
two of its vertices lie on a circuit. In addition, every vertex of H has degree 2.
If a graph G does not have a subgraph H with properties (1)-(4), then G does not
have a Hamiltonian circuit.
The contrapositive is very useful to show that a graph does not have a Hamiltonian
circuit.
Page 71 of 73
Example 7.17.4 (A Travelling Salesman Problem) This example illustrates a
type of problem known as a travelling salesman problem. It is a variation of the
problem of finding a Hamiltonian circuit for a graph. Consider a map showing four
cities A, B, C, and D and the distances in kilometres between them (see Figure 40).
Figure 40:
Suppose that a salesman must travel to each city exactly once, starting and ending in
city A. Which route from city to city will minimize the total distance that must be
travelled?
Solution:
The problem can be solved by writing all possible Hamiltonian circuits starting and
ending at A and calculating the total distance travelled for each.
Route Total Distance (In Kilometres)
ABCDA 30 + 30 + 25 + 40 = 125
ABDCA 30 + 35 + 25 + 50 = 140
ACBDA 50 + 30 + 35 + 40 = 155
ACDBA 140 : [This is ABDCA backwards]
ADBCA 155 : [This is ACBDA backwards]
ADCBA 125 : [This is ABCDA backwards]
Thus either route ABCDA or ADCBA gives a minimum total distance of 125 kilo-
metres.
J END I
6
6
For further reading, see; [1], [3] and [2], or any other Discrete mathematics books.
Page 72 of 73
References
[1] Susanna S Epp. Discrete mathematics with applications. Cengage learning, 2010.
Page 73 of 73