Theoretical Models Computing Book
Theoretical Models Computing Book
. . . . . . . . 63
5.4 Problems- Solving Hints . . . . . . . . . . . . . . . . . . . . . . . . 65
5.4.1 Problem 1: Basic concepts and operations . . . . . . . . . . 65
5.4.2 Problem 2: Representations of Graph Connectivity . . . . 65
5.4.3 Problem 3: Isomorphism Graph Invariants . . . . . . . . . 67
5.4.4 Problem 4: Bipartite graphs . . . . . . . . . . . . . . . . . . 69
5.4.5 Problem 5: Directed graphs . . . . . . . . . . . . . . . . . . 70
5.4.6 Problem 6: Trees . . . . . . . . . . . . . . . . . . . . . . . . 72
5.5 Algorithms on Graphs . . . . . . . . . . . . . . . . . . . . . . . . . 73
5.5.1 Shortest paths and Dijkstra Algorithm . . . . . . . . . . . . 73
CONTENTS 1
5.5.2 Max-ow Min-cut algorithm by Ford-Fulkerson . . . . . . . 79
6 Algebraic Model and Polynomial Equations 81
6.1 Linear polynomial equations . . . . . . . . . . . . . . . . . . . . . . 81
6.1.1 Gauss Elimination - Contents . . . . . . . . . . . . . . . . . 82
6.1.2 Gauss Elimination- Technique . . . . . . . . . . . . . . . . . 87
6.1.3 Matlab section . . . . . . . . . . . . . . . . . . . . . . . . . 89
6.1.4 Practical projects (Optional) . . . . . . . . . . . . . . . . . 91
6.2 Symbolic computation for nding roots of nonlinear equations . . . 91
6.3 Algebraic Modeling . . . . . . . . . . . . . . . . . . . . . . . . . . . 93
6.3.1 In Industrial Statistics . . . . . . . . . . . . . . . . . . . . . 93
6.3.2 In Business Intelligence . . . . . . . . . . . . . . . . . . . . 99
7 Probabilistic Models 101
7.1 Practical Motivation . . . . . . . . . . . . . . . . . . . . . . . . . . 101
7.2 Concepts and Definitions . . . . . . . . . . . . . . . . . . . . . . . 103
7.2.1 Random Variable and Probability Distribution . . . . . . . 104
7.2.2 Why study Probability Distributions? . . . . . . . . . . . . 106
7.3 Discrete Probability Distributions . . . . . . . . . . . . . . . . . . . 107
7.4 Problems . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 110
2 CONTENTS
Introduction
This course provides a challenging introduction to some of the central ideas of
Theoretical Computer Science. It attempts to present a vision of computer
science beyond computers: that is, CS as a set of mathematical tools for
understanding complex systems such as universes and minds.
A. COURSE OVERVIEW: No. of Credits: 4
1. Course Objective: To provide undergraduate students with mathematical
reasoning, combinatorial analysis, and algorithmic thinking and modeling.
2. Prerequisite: None
3. Major Contents: Logic, Set, Algorithms, Mathematical Reasoning, Induction,
and Recursion, Counting, Graph Models and Algorithms on Graphs, Roots of
Polynomial Equations.
4. Assessment:
Assignments and Class Attendance: 30%
Midterm Test: 20%; Final Exam: 50%
5. Documents:
Main lecture note: yes
References:
a/ DISCRETE MATHEMATICS, Norman L. BIGGS, Oxford University Press,
Second Edition, 2009.
b/ ELEMENTARY METHODS IN NUMBER THEORY, Melvyn B.
Nathanson, Springer 2000
B. COURSE STRUCTURE
Part I: Discrete Structures, including logic, sets, counting techniques.
Part II provides Graph Models, together relavant structures.
Part III: (Chapter 7) Algebraic methods and modeling for nding roots
of equations, both linear and nonlinear equations.
Part IV (Chapter 8) Advanced: Probabilistic Modeling. How to deal
with uncertainty in daily life?
3
4 CONTENTS
C. Key remarks and Philosophy of Learning
I/ This subject covers many mathematical topics that are essential in Computer
Science but are not covered in the standard calculus curriculum. In addition,
the subject teaches students about careful mathematics:
- precisely stating assertions about well-dened mathematical objects and
- verifying these assertions using mathematically sound proofs.
II/ Students are encouraged to collaborate on problem sets (counting for 30% of
the nal grade) as on teams in class. Study groups can be a big help in
mastering course material, besides being fun and a good way to make friends.
However, students must write up solutions on their own,
neither copying solutions nor providing solutions to be copied.
The last page of each problem set has a collaboration statement to be
completed and attached as the rst page of a problem set submission:
I worked alone and only with course materials
or
I collaborated on this assignment with (students in class).
III/ Philosophy
1. Amount learned is proportional to time put in.
2. Best way to learn: to gure out ideas yourself or teach them to someone else.
3. Second best: to do so with hints from others (friends or us).
4. Third best: to get the ideas from reading; but pause in your reading to
think about them.
5. The object of a lecture: not so much to inform you of important facts, but
rather to stimulate you to try to learn about new concepts.
6. The object of the course: to empower you to use the concepts of Discrete
Mathematics and Theoretical Computation in any context.
Chapter 1
Basic Logic
We study logic from the mathematical point of view. This introductory chapter
is about mathematical logic, covers two key topics:
1. Propositions Propositional logic
2. Predicate logic
We begin the course by looking at examples involving everyday English
sentences. This is followed by an introduction to the more formal mathematical
approach used in propositional and predicate logic.
1.1 Propositional logic
Motivation
The fundamental objects we work with in arithmetic are numbers. In a similar
way, the fundamental objects in logic are propositions. Here are some examples
of English sentences that are propositions:
Canberra is the capital of Australia.
There are 8 days in a week.
Isaac Newton was born in 1642.
5 is greater than 7.
Every even number greater than 2 can be expressed as the sum of two
prime numbers.
Propositions truth values. The rst and third of these propositions are true,
and the second and fourth are false. It is not known at present whether the
fth proposition is true or false.
5
6 CHAPTER 1. BASIC LOGIC
The following sentences are not propositions:
Where are you going?
Come here!
How about these?
Anne is tall.
Ice cream is delicious.
x > 5.
The last of the three sentences given above is an example of a predicate.
1.1.1 Theory- Content of Propositional Logic
Propositions- Connectives and truth tables
Compound propositions- Writing compound propositions
Tautology Contradiction
Logical equivalence
Decomposing complicated proposition
Provable equivalence- Rule of Inference
Denition 1. A proposition is a statement that is either true or false.
Whichever of these (true or false) is the case is called the truth value of the
proposition.
a/ Connectives and truth tables
Logic is not concerned with determining the truth values of propositions of the
kind we have seen so far.
E.g. the truth value of Canberra is the capital of Australia
is a question of geography, not logic. The next example is dierent, however:
If Brian and Angela are not both happy, then either Brian is not happy or
Angela is not happy.
The sentence about Brian and Angela is an example of a compound proposition.
It is built up from the atomic propositions
Brian is happy, and Angela is happy
using the words and, or, not (also written ) and if-then. These words are
known as connectives. As we will see, the role of connectives in logic is
analogous to the role played by operations such as + and in algebra.
1.1. PROPOSITIONAL LOGIC 7
The study of the structure of compound propositions is made easier by the use
of symbols for atomic propositions and connectives.
We will use lower-case letters such as p, q and r to denote atomic
propositions. There are ve connectives that we will use in our work; they are
listed in Table 1.1.1, together with their symbols.
Connective Symbol
and
or
not
if-then
if-and-only-if
Table 1.1: Connectives and associated symbols
The propositional connectives are:
negation ( ),
conjunction
disjunction
implication or
biimplication
They are read as not, and, or, if-then, if and only if respectively.
The connectives , , , are designated as binary,
while is designated as unary.
r: the negation of r
p q: the conjunction of p and q
p q: ?
p q or p q: the implication of q by p
c d: logical equivalence
8 CHAPTER 1. BASIC LOGIC
Conventions
b/ Compound propositions
With the exception of not, the symbols for these connectives are written
between the two operands (the propositions they connect).
For example, if
p denotes the proposition Today is Monday, and
q denotes the proposition It is raining,
then we can write
the symbol p, p or not p before the proposition to which it applies; thus,
p means Today is not Monday.
the symbol p q to denote the proposition
Today is Monday and it is raining.
Table 1.1.1 shows how to form the true value of p q
Can we form compound propositions p q, p q similarly?
1.1. PROPOSITIONAL LOGIC 9
p q p q
T T T
T F F
F T F
F F F
Table 1.2: Connective and
Notice that each column is obtained using the truth table for the principal
connective in the expression at the top of the column.
If an expression contains three variables (p, q and r, say), then the table
will have eight lines instead of four (there are 2
3
= 8 dierent ways of
allocating truth values to three expressions), but the method is the same.
Writing compound propositions in symbolic form
We now have the notation we need in order to be able to write compound
propositions in symbolic form. Express the proposition, e.g.
Either my program runs and it contains no bugs, or my program contains
bugs in symbolic form.
c/ Tautology Contradiction
Denition 2. You should know two following basic concepts to make right
reasoning.
- An expression that is always true, regardless of the truth values of the
variables it contains, is called a tautology.
- An expression that is always false, regardless of the truth values of the
variables it contains, is called a contradiction. Mathematically contradictions
are expressions of the form
or
where is any proposition (simple or compound).
Below examples shows how these concepts are used.
10 CHAPTER 1. BASIC LOGIC
1.1.2 Examples
Example 1. Express the proposition
Either my program runs and it contains no bugs,
or my program contains bugs in symbolic form.
Example 2. Construct the truth table for the expression (p q) q.
Example 3. Now look again at the proposition we introduced at the beginning
of this section
If Brian and Angela are not both happy,
then either Brian is not happy or Angela is not happy
a/ Write this compound proposition in symbolic form and
b/ provide its truth table.
d/ Logical equivalence
Denition 3. Two expressions (composed of the same variables) are logically
equivalent if they have the same truth values for every combination of the truth
values of the variables.
Informally, we could say that two expressions are logically equivalent if they
yield the same truth table. Formally,
A(p, q, r, ...) is logically equivalent to B(p, q, r, ...), write
A(p, q, r, ...) B(p, q, r, ...) if we have
A(p, q, ...) = B(p, q, ...) for every choice of boolean values of p, q, ...
Logical equivalence and connective if-and-only-if
There is a subtle but important distinction between the connective
if-and-only-if or and
the concept of logical equivalence .
1.1. PROPOSITIONAL LOGIC 11
When we write A B, we are writing a single logical expression.
(A B) (B A).
Logical equivalence, A B, on the other hand, is a relationship between two
logical expressions A and B. The connection of the two concepts is:
A and B are logically equivalent
if and only if the expression A B is a tautology.
f/ Conditionals A B
Given that if A then B (or A implies B= A B) is a conditional
statement with hypothesis A and conclusion B.
Denition 5. Its contrapositive is: if not B then not A and
its converse is: if B then A.
Since statements with the same truth table are said to be equivalent; the table
shows that a conditional and its contrapositive are equivalent, we write
if A then B = if not B then not A
12 CHAPTER 1. BASIC LOGIC
Proof Techniques for P = Q. To prove a generic proposition P = Q, you
could use one of the following methods:
a direct argument or Conditional Proof:
to carry out the implication P = Q directly, know P is true.
a contrapositive argument: to use the identity
P = Q Q = P
(Prove this equality!)
a contradiction argument means that, provided P is true,
we assume Q is false and try to derive a contradiction
P Q = false
Proof By Contradiction
A false statement is called a contradiction.
For example, S and not S is a contradiction for any statement S.
A truth table will show us that
if A then B, is equivalent to [ A and (not B) ] implies false.
or in mathematical symbols
A B [(A notB) false]
So to prove if A then B, it suces
to assume A and also
to assume not B, and then
to argue toward a false statement.
This technique is called proof by contradiction.
1
,
2
, . . . ,
n
Valid arguments. This implication is understood as
1
2
. . .
n
When all the premises
1
,
2
, . . . ,
n
have true value T, and nd that under
these circumtances also has the value T, then the implication
1
2
. . .
n
is tautology, and we have a valid argument.
1.1. PROPOSITIONAL LOGIC 15
Usages of Rules of inference. Rules of inference
1. enable us to consider only the cases wherein all the premises
1
,
2
, . . . ,
n
are true;
2. used in the development of step-by-step validation of how the conclusion
logically follows from the premises
1
,
2
, . . . ,
n
in the implication of the
form
1
,
2
, . . . ,
n
A few well known valid arguments are summaried next.
I: Rule of Modus Ponens
p (p q) q
Modus Ponens is also called the Rule of Detachment.
Quiz : Can you check p (p q) q is a valid argument?
In the tabular form:
p
p q
q
where the stands for therefore, indicating that q is the conclusion of two
premises p and p q above the line.
Example 5. Consider the following statements.
1/ Barack Obama is a human being.
2/ If x is a human being then x will die.
3/ Barack Obama will die.
II: Rule of Syllogism
(p q) (q r) (p r)
where p, q and r are any statement. In the tabular form, it is written
p q
q r
p r
16 CHAPTER 1. BASIC LOGIC
III: Rule of Modus Tollens
[(p q) p] q
This can be derived from Modus Ponens and the logical equivalence
p q p q
or
p q p q
In the tabular form:
p q
p
q
This rule of inference arises when there are exactly two possibilities to consider,
and we are able to elliminate one of them as being true, i.e. it is false. Then the
other possibility must be true.
1.2. PREDICATE LOGIC 17
V: Rule of Contradiction
Denote F
0
to be a contradiction. You can prove that
(p F
0
) p
is a tautology! This called the Rule of Contradiction, written as:
p F
0
p
The Rule of Contradiction is a key method of establishing the validity of an
argument, the method Proof by Contradiction.
Moreover we can employ this to the case when we wish to prove
(p
1
p
2
. . . p
n
) q
then we can form the validity of the argument
(p
1
p
2
. . . p
n
) q F
0
WHY?
1.2 Predicate logic
1.2.1 What topics will we learn?
A: Predicate logic- concepts of predicate
B: Quantifying a Predicate
C: Quantifying a Predicate- two propositions
D (*): Negating a predicate with many variables and quantiers
A. Propositions versus predicate
Denition 6. A predicate is a statement containing one or more variables; it
cannot be assigned a truth value until the values of the variables are specied.
We will investigate predicate logic later.
Statements containing variables commonly occur in algorithms and computer
programs.
For example, an algorithm might contain the statement x > 5. as the condition
in a control structure such as an If-then.
18 CHAPTER 1. BASIC LOGIC
In this case, however, the truth value of the statement is determined when the
line is executed while the program is being run with a particular set of inputs,
so statements of this type can be treated as propositions.
There is a second law, be seen of as the dual of the rst, for negating a
proposition containing there exists. It also corresponds to negating the
predicate and changing the quantier:
Rule 2 : [ xP(x) ] x[ P(x) ]
Summary
Rule 1 : [ xP(x) ] x[ P(x) ]
Rule 2 : [ xP(x) ] x[ P(x) ]
Rule 3 : [ xy P(x, y) ] xy [ P(x, y) ]
Rule 4 : [ x(P(x) Q(x)) ] x[ P(x) Q(x) ]
1.2.2 Problems- Solving Hints
I) Quantiers with many variables
A variable which has been quantied is said to be bound. A variable that
appears in a predicate but is not bound is said to be free.
Mixing Quantiers. Many mathematical statements involve several
quantiers.
Example 8. Write the following two propositions in symbols:
For every number x there is a number y such that y = x + 1.
There is a number y such that, for every number x, y = x + 1.
Can you symbolize the statement in two ways:
Every American has a dream.
Hint: let A be the set of Americans, let D be the set of dreams, and dene the
predicate
H(a, d) to be American a has dream d..
II) Predicate with many variables.
22 CHAPTER 1. BASIC LOGIC
In the specication of a system for booking theatre seats, B(p, s) denotes the
predicate person p has booked seat s. Write the following sentences in
symbolic form:
1. Seat s has been booked.
2. Person p has booked a (that is, at least one) seat.
3. All the seats are booked.
4. No seat is booked by more than one person.
III) If And Only If (I) Proofs
A statement of the form A if and only if (i) B means
A implies B and B implies A or in mathematical symbols
(A B) (B A) = (A B)
So there are actually two proofs to give.
The proofs can also be written as a single proof of the form
A i C i D i i B,
where each i statement is clear from previous information.
Practice 1: x is even if and only if x
2
2x + 1 is odd.
Practice 2: x
2
is odd if and only if x is odd.
IV) Symbolically proof.
Consider the following statements
Nguyen is playing a game.
If Nguyen is playing a game then he is not solving his home works.
If Nguyen is not solving his home works then his father will not buy him a
motorbike.
Can you prove that
Therefore, Nguyens father will not buy him a motorbike.
symbolically?
Chapter 2
Set Theory
2.1 Sets- Ways of describing things
2.1.1 Motivation
How could you write or represent all national soccer teams s taking part world
soccer matches in South Africa in the year 2010?
2.1.2 Concepts
A Set is a collection of some things. Set is a fundamental notion.
For instance,
1/ set A = {shirt, pull}, set B = {jean, trouser, sport}.
set of naturals N = {1, 2, 3, . . .},
We write shirt A, trouser B, but must write trouser N!
2/ For ex., to the example of world soccer matches in South Africa write
S = {s : a property P(s) is fullled, that s satises}
where P(s) = national soccer teams s taking part matches in South Africa.
Notation.
If S is a set and x is a member or element of S we write x S. Othewise
we write x S.
The set with elements x
1
, , x
n
is denoted {x
1
, , x
n
}.
The empty set with no elements is denoted {} or .
A set with one element is called a singleton. e.g., {a} is a singleton.
23
24 CHAPTER 2. SET THEORY
A sequence u, an ordered set made by elements a, b, c..., is written by
u = (a, b, c, . . .), e.g. u = (s
1
, s
2
, . . . , s
80
) is a sequence.
If an ordered set has only two elements it is called a pair.
Example 1: a daily outt (pull, jean) is such a pair.
A sequence is not a set, although they are made from the same elements.
Example 2: Hence, the sequence
(An, Binh, Cuong) = {An, Binh, Cuong}, which is a set.
Operation on Sets.
Forming new set from two sets intersection
The intersection E F, of sets E and F, consists of their common elements:
E F = {x : x E and x F}
Forming new set from two sets Cartesian product
The Cartesian product of two sets A and B, denoted by AB, consists of all
pairs (a, b) where a A and b B.
Set equality and subsets
Subsets. The set A is a subset of B, denoted A B, means every element
of A is an element of B, i.e. [ for all s, if s A then s B ]
The power set of a set S, denoted power(S) or P(S) is the set of all
subsets of S.
Two sets A, B are equal, denoted A = B if they have the same elements.
2.1.3 Examples
Example 0/ Well-known number sets are
the natural numbers {0, 1, } by N, the set of integers is denoted by Z,
the rational numbers by Q, and the real numbers by R.
Q =
_
m
n
: m, n Z, n = 0
_
1/ Could you nd the intersection E F when
E = [1; 4] := {x R : 1 x 4},
2.1. SETS- WAYS OF DESCRIBING THINGS 25
i) F = [2; 6),
ii) F = (0; 10), and
iii) F = [0; )?
2/ List all members (elements) of AB if given A = {shirt, pull},
B = {jean, trouser, sport}
3/ Quiz. Determine the set P(X) P(Y ) if you know
X = {a, b, 1} and Y = {u, a, b},
where P(S) is the set consisting all subsets of S.
2.1.4 Key Mathematical Symbols
SYMBOL MEANING Note
Belong to relation
Not belong to relation
imply; it follows that logic operator
Implied by logic operator
Equivalent to; if and only if logic operator
N Natural numbers set notation
Q Rational numbers set notation
Z Integer numbers set notation
R Real numbers set notation
For every quantier
There exists quantier
26 CHAPTER 2. SET THEORY
2.2 Relations
* A binary relation R between A and B is a rule that associate some
elements a A with certain elements b B.
Equivalently, it is a subset R of the product AB; that means
R = {some (a, b) : a and b satisfy some condition} AB
* Inx Notation: If R is binary, we can use inx to represent pairs in R.
For example, call R the is square of relation on N.
R = {(0, 0), (1, 1), (4, 2), (9, 3), . . . , (n
2
, n), . . .} = {(n
2
, n)|n N}.
In this example, we have (9, 3) R. So we can also write
R(9, 3) or 9R3 or 9 is square of 3.
-
* In general if x
i
A
i
, for all i = 1..n, the set of all n-tuples (x
1
, , x
n
) is
denoted
A = A
1
A
2
A
n
= {(x
1
, , x
n
)}
A n-ary relation R is a subset of A = A
1
A
2
A
n
If R is a relation and (x
1
, , x
n
) R, we write R(x
1
, , x
n
).
n-ary relations Application in CS: Relational Databases. A
relational database is a relation where the indexes of a tuple have associated
names called attributes.
Example. Set n = 3,
A
1
a set of names, A
2
a set of majors, A
3
a set of credits,
and let Students be a ternary relation between the sets A
1
, A
2
, A
3
Students = {(x, y, z) | x is a Name, y is a Major, and z is Credits}.
Students is also called a relational database with 3 elds A
1
of strings, A
2
of
strings, and A
3
of natural numbers.
2.2.1 Equivalence Relation
Consider a binary relation R on A (between A and A), it is just a subset R of
the product AA, i.e.
R = {some pairs (a, b) AA : a A b A}.
R is called an equivalence relation on A if it is reexive, symmetric and
transitive, due to the below meanings.
2.2. RELATIONS 27
1. Reexive property: aRa for all a A.
2. Symmetric property: For all a, b A, if aRb then bRa.
3. Transitive property: For all a, b, c A, if aRb and bRc then aRc.
Theorem 8. An equivalence relation R provides a partition of the set A, that
partition is formed by the set of all equivalence classes of R.
2.2.2 Partial orders
Consider a binary relation R on A (between A and A), it is just a subset R of
the product AA, i.e.
R = {some pairs (a, b) AA : a A b A}.
R is called a partial ordering relation on A if it is reexive, anti-symmetric
and transitive, due to the below meanings.
1. Reexive property: aRa for all a A.
2. Anti-symmetric property: For all a, b A, if aRb and bRa then a = b.
3. Transitive property: For all a, b, c A, if aRb and bRc then aRc.
If we could determine a partial ordering relation R on A then (A, R) is called a
poset.
2.2.3 Example
Relation of weekly approriate outt (for IU students from Monday till Saturday)
R = {(a, b) : a and b make a right outt}, i.e.
R = {Monday, Tuesday, . . . , Friday} =
{(shirt, jean), (shirt, trouser), (pull, jean), (pull, trouser), (pull, sport)}
Is R an equivalence relation? a partial ordering relation R on A? Why?
2.2.4 Problems- Solving Hints
A) Extract infomation from Relational Databases.
Recall that A
1
a set of names, A
2
a set of majors, A
3
a set of credits,
and let Students be a ternary relation between the sets A
1
, A
2
, A
3
Students = {(x, y, z) | x is a Name, y is a Major, and z is Credits}.
1/ Who are the student majoring in CS in senior class (4-th year)?
28 CHAPTER 2. SET THEORY
Set y = CS (constant string), and set z 90 for 4-th year students, then
senior-Students = {(x, CS, z) Students such that z 90}
2/ What is the history department database of names and their credits?
History-Students = {(x, z) | (x, His, z) Students } A
1
A
3
In Relational Databases theory, History-Students is called a projection on
A
1
A
3
with respect to the direction y = His.
B) Poset Diagram (Hasse Diagram): A graph representing a poset but with
only immediate predecessor edges, and the edges are oriented up from x to y
when x < y.
Quiz: can you show the Hasse Diagram of ({2, 3, 4, 8, 12, 15}, |)?
2.2.5 Practical projects (Optional)
Let A be a set of nine team of students, in a Green Summer Actions at
HCMUS, where the performance of team t
i
is denoted by p
i
Q
+
, for i = 1..9.
Suppose that the performances are distinct and sorted in increasing order, that
is p
1
< p
2
< p
3
< . . . < p
8
< p
9
, and the corresponding teams in A are denoted
as A = {t
1
, t
2
, t
3
, . . . , t
8
, t
9
}. We dene a binary relation on A by
t
i
t
j
p
i
p
j
.
Could you determine
a) whether (A, ) is a partial order set? Total order set? Explain why?
b) how many subsets B of A that have precisely 5 elements (teams), consist
the worst team t
1
, and not consist teams t
2
, t
3
?
c) how many subsets C of A having precisely 5 elements and the weakest
team of C is t
4
?
2.3. FUNCTIONS- WAYS OF TRANFORMING THINGS 29
2.3 Functions- Ways of tranforming things
2.3.1 Motivation
A) The idea of function is one of the most fundamental concepts in modern
mathematics. A function expresses the hypothesis of one quantity depending on
(or being determined by) another quantity. For example:
(i) bone mass is dependent on age of subject;
(ii) height is dependent on races etc.
If a function f assigns a value y in the range to a certain x in the domain, then
we write: y = f(x) where
x is called independent variable and y is dependent variable (although this
terminology is sometimes controversial).
B) When HCMCs Environmental Protection Agency (EPA) found a certain
company C (paper mill or cleaning chemical factory) dumping contaminated
liquid into Saigon River,
it ned the company C $12500 plus $100 per day
until the company compiled with national pollution rules.
Request: express the total ne as a function of the number x of days the rm
C continued to violate the national rules. Determine the slope and give your
remark about it.
2.3.2 Theory
Domain and range.
In general, given two sets A (domain) and B (contains range), function f from
set A to set B, is a special rule, such that each value a A gives rise a unique
value f(a) = b. We describe functions by few ways:
1. use an algebraic formula: function f : A B is given by a formula
f(a) = b,
2. by relation notation:
f = {(a, b) : each value a A gives a unique image b B}
or
f = {(a, f(a)) : a A and !f(a) B}
* The domain of f is A, denoted by Dom(f), consists of all a such that f(a) is
computable,
* b = f(a) is the image of a under f. The set of values b is called its range or
image, written Range(f).
30 CHAPTER 2. SET THEORY
Composite function.
Suppose that f, g are real-valued function with domains Dom(f) and Dom(g)
respectively. The function h := f g given by
h(x) := (f g)(x) = f[g(x)]
is called the composite of f with g.
The domain of f g is the set of all x Dom(g) such that g(x) Dom(f).
Note that it can happen that f g = g f. [why? try visualize the
diagram]
2.3.3 Examples
Ex 1: A = {1, 4, 7, 8, 10}, B = {2, 8, 14, 16, 17, 20, 35} N,
the doubling function is dened
1. by algebraic formula, can be written shortly by
f(a) = 2a, a A
2. by relation notation f = {(1, 2), (4, 8), (7, 14), (8, 16), (10, 20)},
Remark that graphing/sketching a function f on 2-dimensional
plane Oxy (2D-plane) means representing f by relation notation.
2.3.4 Problems- Solving Hints
A/ Number Theory- basic concepts
Division algorithm. For a, b Z with b = 0, there are unique pair of
integers q, r Z such that
a = bq +r with 0 r < |b|
Euclids algorithm for nding gcd(x, y) [try it on Maple!]
Example. Find gcd(189, 33)
The mod Function. For a, b Z with b > 0, apply the division
algorithm to get a = bq +r with 0 r < b. The remainder r is the value
of the mod function applied to a and b:
r = a mod b
2.3. FUNCTIONS- WAYS OF TRANFORMING THINGS 31
How to get a formula for r in terms of a and b?
Hint: we solve the equation for q = a/b r/b, employing the fact that
0 r < b
B/ Constructing Function A function f : R R given by f(x) = x
2
, a
function g : R R given by g(x) = 4x + 3
The composite function go f is determined by the formula ??
The composite function fo g is determined by the formula ??
C/ Specic properties of functions Let f : A B be a function.
Injective (also called one-to-one): Distinct elements in A map to distinct
elements in B; formalizing as
a = b f(a) = f(b)
Is f : N
8
N, be dened by f(x) = 2x mod 8
an injective function?
Surjective (also called onto): The range is the codomain. That is each
b B has the form b = f(a) for some a A.
Bijective (also called one-to-one and onto): Both injective and surjective.
That is
any b B has the form b = f(a) for a unique a A.
Prove: the function f : (0, 1) (2, 5) dened by f(x) = 3x + 2 is a
bijection.
2.3.5 Practical projects (Optional)
1. Piecewise functions are functions of the form
y =
_
f
1
(x) when x I
1
, (a real interval)
f
2
(x) when x I
2
, (another interval)
Sketching the graph of the piecewise function
y =
_
5
2
x
1
2
if 1 x 1
x
2
+ 4x + 5 if x > 1
2. Basic graphs and how to nd their intersection.
Given two graphs G : y = f(x) . . . () and H : y = g(x) . . . (), their
intersection G H can be determined by solving the system of equations
32 CHAPTER 2. SET THEORY
f(x) = g(x) . . .
to nd solutions x
i
.
The intersection G H = {M(x
i
, y
i
) : M G and M H}, that is
G H = {M(x
i
, y
i
) : f(x
i
) = g(x
i
) and y
i
= f(x
i
)}
Application of intersecting graphs: Break-even points: A cable
television company estimates that with t thousand subscribers, its
monthly revenue and cost (in thousands of dollars) are
R(t) = t
2
+ 3t 2 . . . (G) and
C(t), be given by 4t + 8s 6 = 0 . . . (H).
Find the intersection of the curve G and the line H on the Ots-plane?
Notation: The companys break-even points are the number of
subscribers t
0
at which R(t
0
) = C(t
0
).
3. Inverses: If f : A B, b = f(a) is a bijection, then there is an inverse
function g : B A dened by (an inverse action)
g(b) = a i f(a) = b
The inverse of f is denoted by f
1
.
E.g., the function f : (0, 1) (2, 5) dened by f(x) = 3x + 2 =: y is a
bijection, so the inverse of f is denoted by f
1
= g : (2, 5) (0, 1) dened
by ??
2.4 Integers and Algorithms on Integers
2.4.1 Review- Motivation
We start with the basic concept of a number.
The Natural Numbers, denoted as N, are the numbers 1,2,3,... These
are closed under addition (e.g., 3 + 29 = 32 N) .
Introducing the notion of subtraction makes us enlarge N to get the
Integers, denoted as Z, positive or negative or 0, so that our numbers are
closed under the operation of substraction.
2.4. INTEGERS AND ALGORITHMS ON INTEGERS 33
Z is closed under multiplication as well; which is to say that the product
of two integers is an integer (e.g., 3.(9) = 27 Z) .
To obtain a set of numbers closed under division:
we must enlarge Z to get the Rational Numbers Q, which are fractions
of the form a/b where a is in Z and b is in N.
We then have the extension diagram
N Z Q
The numbers between 0 and 1 can each be represented as a decimal point
followed by an innite string of digits, each digit being one of 1, 2, 3, ..., 9, 0.
Rational numbers in Q repeat themselves endlessly after some point: for
example 1 / 4 is .250*
(where the star means that you repeat the starred digit endlessly)
1 / 3 is .3*, 57 / 100 = .570*.
1 / 7 = .(142857)*,
Hence, we have the extension diagram
N Z Q R
Irrational numbers (not in Q, but still in R) do not do so, for example
e = 1.27... the Nepe base number of logarithm
= 1.414... = 2.90
o
the unit of measuring angle
2.4.2 Introduction to Algorithms
Learn chapter 14, key text by BIGGS, on Algorithms and Eciency, pages 159
171.
2.4.3 Basic Integer Theory
Divisibility algorithms
Counting systems- Arithmetic operations
Congruences linear congruences, the additive group Z
n
Greatest common divisors The Euclidean algorithm
Decompsing an integer by relatively prime numbers
34 CHAPTER 2. SET THEORY
Divisibility algorithms
Minimum principle: In a total ordering set (S, ), for any subset = A S
and A is bounded below, then there exists a smallest element of A, that is:
b S, a A : b a = a
0
A : a
0
a.
Divisibility: for a, d Z, we say d is a divisor of a i:
q Z : a = qd
Division algorithm: Let a, d Z with d 1. Then
!(q, r) Z
2
: a = qd +r where 0 r < d.
q is called the quotient and
r is called the remainder in the division of a and d.
Counting systems- m-adic representation
Fix an m Z and m 2, any n Z can be represented uniquely in the form:
n = [a
0
a
1
a
k
], means that
n = a
0
+a
1
m+a
2
m
2
+. . . +a
k
m
k
=
k
i=0
a
i
m
i
, where k N
such that
m
k
n < m
k+1
,
1 a
k
m1, and
a
i
N, 0 a
i
m1, for i = 1..k 1.
This is called the m-adic representation of n, a
i
the digits of n to base m.
For example, m = 2, our counting system is said to be binary,
n = 14 = 0 + 1.2
1
+ 1.2
2
+ 1.2
3
then k = 3 and the 2-adic representation of 15 is
[0111].
Group. Let = G, and G
2
= GG.
A binary operation : G
2
G is a map, we write x y := (x, y)
(G, ) is called a group if satises three axioms:
- associativity,
- there exists identity element and
- there exist inverses in G with respect to .
2.4. INTEGERS AND ALGORITHMS ON INTEGERS 35
Moreover, (G, ) is called abelian or commutative if x y = y x.
Ex1: (G, ) = (Z, +) is an abelian group, additively writen..
Ex2: (Q
, ), (R
, ), (C
bB
f
1
(b).
Does this represent a partition of the set A? Elucidate your reasoning.
Evaluate |A| if you know that |f
1
(b)| = k N
for all b B.
42 CHAPTER 3. COUNTING TECHNIQUES.
3.2.2 Practical projects (Optional)
Algorithmic problem solving: First Tool: Invariants
Invariant means a not-changing property of a process or system when that
process evolves. Similar terms of invariant are law and pattern. In
mathematical modeling and algorithmic problem solving, very often
* you wants to model a system in a concise way as much as possible (of course
after droping unimportant aspects to make the model tractable);
** then your goal is to nd some solution or conclusion from making logical
reasoning on the model by mathematical techniques or by simulation it.
The crucial structures/objects/property that you wish to nd out and employ
during both two phases above are xed pattern or invariant during the whole
process evolution.
Reason: these xed rules could help you to keep the model within tractable
range, and moreover to restrict the search domain of solutions.
Example 9. Cutting a chocolate bar of a rectangular shape by a horizontal cut
or vertical cut into unit-size squares provides an invariant between the number
of cuts c and the number of pieces p:
? =??
no matter how large the bar is!
Denition 13 (System invariants). Invariants of the system S are specic
constraints or properties that do not change when the system factors (variables)
change their values [to ensure S stability, existence ...] during the evolution of
concerned system.
, and U
n
= {a N : a|n(a is a divisor of n)}. On U
n
we dene
the relation:
x < y x|y.
* Prove that: (U
n
, <) is a poset (partial ordered set with respect to <)
* Draw the Hasse diagram of (U
15
, <) and of (U
16
, <)
4. Draw the Hasse diagram of poset (P(X), ) [the power set P(X) with
ordering ] when X = {a, b, c} and when X = {f, g, c, w}
5. Given a poset (A, ), A is nite, and let x, y be two arbitrary elements of
A. Recall that
The Hasse diagram of (A, ) include:
a set P of points in 2D-plane which correspond one-one with A, i.e.
there is a bijection between A and P
a set Q of directed arcs connecting some pair of distinct points:
x = y are connected by an arc from x to y if:
x < y and there is no z A : x < z < y
50 CHAPTER 4. INDUCTION AND RECURSION
Topics for Presentation
RSA encryption How to keep your information on nets from eardrops?
Integer Programming How to nd solution whose components are integers?
Planar graphs How to design computer board rightly?
Graph coloring How to design or draw maps mathematically correct?
Bipartite matching How to assign jobs to suitable workers?
Max-ow Min-cut algorithm by Ford-Fulkerson How to push most uid
subtances (as oil, trac, ...) on a directed net?
DOE: How to compute fractional designs
Shortest paths
Chapter 5
Graph Theory and Models
Better tools for representing discrete strutures. What interesting
structures else?
Graphs- an introduction
Undirected graph
Directed Graphs
Trees
5.1 Undirected Graphs
5.1.1 Basic concepts and basic operations
Basic concepts.
A undirected graph G = (V, E) consists of
a vertex set V = {1, 2, 3, , i, , n} of nodes or vertices; and
a set E of pairs of elements in V .
We call Es members the edges of G.
51
52 CHAPTER 5. GRAPH THEORY AND MODELS
Adjacency matrix A(G) = [a
ij
] is a 0-1 (Boolean) matrix, where
a
ij
= 1 when (i, j) E
and
a
ij
= 0 when (i, j) E.
Example. Let V = {a, b, c}, E = {(a, b), (b, a), (b, c)}, then G = (V, E) is a
graph, called complete graph K
3
on 3 vertices.
Quiz. Describe complete graphs K
4
, K
5
.
Denition 14. In a undirected graph G = (V, E),
degree of a vertex u V , written d(u) is the number of adjacent vertices
v of u.
a simple path P is a path consisting no duplicated edges,
an elementary path is a path that consists no duplicated vertices;
G = (V, E) is connected if for all pair of nodes i, j V , there exists at least a
path connecting them.
G = (V, E) is disconnected if there exists a pair of nodes a, b V for which
no path connecting them.
Undirected Graphs basic operations.
Removing a vertex u implies deleting every edge that has connected with
u;
5.1. UNDIRECTED GRAPHS 53
* a vertex v is called a cut vertex i H := G\ v is disconnected;
Removing an edge e = (u, v) still keeps u, v in G!
* an edge e = (u, v) is called a cut edge or bridge i G\ e is
disconnected.
Undirected Graphs basic properties.
Lemma 15. For an arbitrary undirected graph G = (V, E), the equality
2|E| =
uV
d(u) is valid.
Proof.
Each edge e = (u, v) E is determined by two end vertices u and v. When we
count and sum up the number of edges of the set E, each of them contribute
two to the sum of degrees, therefore the sum must be twice the number of
edges. We obtain that
vV
d(v) = 2 |E|
for any arbitrary undirected graph G = (V, E), including cases of multiple edges
and loops.
(u, v) = uv, b =
(v, u) = vu A then a = b.
u is the initial (emerging) vertex of a, and
v is the terminal (ending) vertex of a.
Adjacency matrix A(G) = [a
ij
] is a {0, 1} matrix, where
a
ij
= 1 when ij A; and
a
ij
= 0 for other cases.
5.3.1 Path Problem in Directed Graphs
* A path P of length k in a digraph G = (V, A) is a sequence of vertices
P = v
0
, v
1
, . . . , v
k
where v
i1
v
i
A, i = 1..k.
* A cycle C of length k in G = (V, A) is a path
C = v
0
, v
1
, . . . , v
k
where v
i1
v
i
A, i = 1..k and such that v
0
= v
k
* If there is no cycles in G, then G is called acyclic digraph (or PERT chart).
PERT chart is employed intensively in task-scheduling problems, where we want
5.3. DIGRAPHS 63
to model ordered lists or structures that have prerequisite property.
Path Problem (Is there a path from node i to node j?)
Ex., let R = {(1, 2), (2, 3), (3, 4)} on vertices V = {a, b, c}. We can represent R
as an adjacency matrix M where
M
i j
= 1 if i Rj, and M
ij
= 0 otherwise.
If we want an answer to our question, it would be nice to have the adjacency
matrix M
= [a
ij
] for the transitive closure t(R). Then we could simply check
whether a
ij
= 1.
Warshalls algorithm: to compute the adjacency matrix M
* Let M = [m
ij
] be the adjacency matrix of a digraph G = (V, A) with n
vertices. An entry m
ij
= True in M indicates the existence of an arc in G; an
arc is a path of length 1.
The logical Boolean product of M with itself is M
2
= M M, and
a True entry in this matrix M
2
indicates
the existence of a path of length 2.
* In general the matrix
M
k
= M M M, (k times of logical Boolean product)
records all paths of length k in G.
64 CHAPTER 5. GRAPH THEORY AND MODELS
* Dene the logical operator or of two arbitrary Boolean matrices B = [b
ij
],
C = [c
ij
] of the same size to be
Bor C = [b
ij
c
ij
]
forming by the logical of corresponding entries.
We now can dene matrices of the form (B D) or (C K) ...
by combining the two logical operators or and Boolean product
Denition 19. The reachability matrix or the transitive closure matrix M
of
t(R) of the adjacency relation A in G is determined by
M
= M or M
2
or . . . or M
n
5.4. PROBLEMS- SOLVING HINTS 65
5.4 Problems- Solving Hints
Students should try to solve at least 70% of the following items.
5.4.1 Problem 1: Basic concepts and operations
1. Prove that for an arbitrary undirected graph G = (V, E), the equality
2|E| =
vV
d(v) is valid.
2. Prove that in any (undirected) graph without multiple edges and loops
which has at least two vertices, there exist two vertices with identical
degrees.
3. Provide the denitions of: i) complete graph K
n
(n N
), ii) regular
graph R of degree r on n vertices where 1 r n 1, iii) wheel graph
W
m
with m+ 1 vertives, and iv) hypercube graph B
k
where B = {0, 1}
and the natural number k > 1.
4. In a weekend party at CSE faculty, every one shakes hand with each
other. Prove that the number of individuals who shakes hand with an odd
number of participants is an even number.
5. How many simple graphs G are there, provided that it has 5 vertices, and
that it:
a) has none isolated vertex? b) has exactly 2 isolated vertices?
c) has at least 2 isolated vertices?
5.4.2 Problem 2: Representations of Graph Connectivity
1. Write down the adjacency matrix of
a/ the complete graphs K
2
, K
3
, K
4
; b/ the wheel graph W
m
with m = 12;
66 CHAPTER 5. GRAPH THEORY AND MODELS
c/ the regular graph R = (V, E) of degree r = 2 if |V | = 6;
d/ the hypercube graph B
k
where k = 3 and k = 4
2. Write down the incidence matrix and the adjacency matrix of
a/ K
5
, and b/ the complete bipartite graph K
2,3
.
3. Prove that G or G is a connected graph., where G is the complement
graph of a simple graph G.
1. Choose the best right answer if your friend asks that: Two graphs
G = (V, E) and H = (W, F) are isomorphic when
(A) there exists a bijection f from the vertex set V to the vertex set W?
(B) there exists an injection g from the vertex set V to the vertex set W?
(C) their numbers of connected components are the same?
(D) there exists a bijective mapping f from the vertex set V to the vertex
set W and a bijective mapping g from the edge set E to the edge set F?
(E) None of the above?
Note 1: The numbers of connected components is a graph invariant.
2. Let graphs G and H be isomorphic. Prove that
for every d 0, the number of vertices of degree d in G and H are
the same;
for every l 3, the number of simple cycles of length l in G and H
are the same.
Note 2: The number of vertices of xed degree d and the number of
simple cycles of xed length l in G and H are graph invariants.
In the next question, choose the best right answer if your friend asks that:
5.4. PROBLEMS- SOLVING HINTS 69
3. For two isomorphic graphs, we have:
a. the same number of vertices; b. the same number of edges
c. the same pattern of vertex degrees (after sorting)
d. the same number of connected components
e. Any one of the above options
4. Two graphs G = (V, E) and H = (W, F) are isomorphic when
a. there exists an injective mapping f from the vertex set V to the vertex
set W
b. there exists a bijective mapping f from the vertex set V to the vertex
set W
c. there exists a bijective mapping f from the vertex set V to the vertex
set W and a bijective mapping g from the edge set E to the edge set F
d. there exists a bijective mapping f from the vertex set V to the vertex
set W such that the adjacency relation is preserved, i.e.,
(u, v) E (f(u), f(v)) F, for u, v V
e. None of the above is CORRECT.
5.4.4 Problem 4: Bipartite graphs
1. Prove that: a graph G is bipartite i every circle C of G has an even
length
2. Prove that i) we could arrange rows and columns of B such that B is the
adjacency matrix of an undirected graph G; and ii) we could arrange
vertices such that G is a bipartite graph; where B is the following square
70 CHAPTER 5. GRAPH THEORY AND MODELS
matrix
B =
_
_
0 0 0 0 0 1 0 0 0
0 1 1 0 0 0 0 0 0
0 0 0 0 1 1 0 0 0
1 0 0 1 0 0 0 0 0
0 0 0 0 0 0 1 1 1
1 1 0 0 0 0 0 0 0
0 1 1 0 0 0 0 0 0
0 0 0 0 1 0 1 1 0
0 0 1 0 0 0 0 0 0
_
_
,
3. Choose the best right answer if your friend asks that: For an undirected,
bipartite graph G = (V, E) with adjacency matrix M(G), we have:
a. the vertex set V can be split into two disjoint subsets A, B
b. |E| = |A|.|B|; c. M(G) is a symmetric matrix
d. G contains a Hamilton cycle;
e. two of the four options a. to d. are CORRECT.
5.4.5 Problem 5: Directed graphs
Remind you that: a directed graph (digraph) G = (V, A) consists of vertex set
V and a set A of ordered pairs of elements in V . We call As members the
arcs or directed edges of G. Formally, we understand that for two arcs
a, b A that are dened on two vertices u, v, then we can write
a =
(u, v) = uv, b =
(v, u) = vu A then a = b.
5.4. PROBLEMS- SOLVING HINTS 71
u is the initial (emerging) vertex of a, and v is the terminal (ending) vertex of a.
* A path P of length k in a digraph G = (V, A) is a sequence of distinct vertices
P = v
0
, v
1
, . . . , v
k
where v
i1
v
i
A, i = 1..k.
* A cycle C of length k in G = (V, A) is a path
C = v
0
, v
1
, . . . , v
k
where v
i1
v
i
A, i = 1..k and such that v
0
= v
k
* If there is no cycles in G, then G is called acyclic digraph (or PERT chart).
Remark that PERT chart is employed intensively in task-scheduling problems,
where we want to model ordered lists or structures that have prerequisite
property.
eP
W(e).
Single source shortest path in connected simple graphs.
Suppose explicitly that G is simple with vertices V = {a = v
1
, v
2
, v
3
, . . . , v
n
},
with weights W(v
i
, v
j
) R
+
whenever (v
i
, v
j
) E, and W(v
i
, v
j
) =
otherwise. Without loss of generality we x vertex a = v
1
, and formulate an
iterative algorithm, due to Edsger W. Dijkstra, to nd a shortest path P
0
from
vertex a = v
1
to any vertex z = a.
For any vertex v, let L(v) be its label, measuring the shortest length from a
to v. At any step, some have temporary labels and the rest have permanent
labels. Of course, at the begining L(a) = 0 (xed or permanent label) and
L(v) = (temporary labels) for v = a.
5.5. ALGORITHMS ON GRAPHS 75
Denote by S V the set of xed label vertices, in the sense that
S = {v V : shortest length from a to v = L(v) < }.
Dijkstras algorithm D(G, a, z) to nd a shortest path P
0
from a = v
1
to any
vertex z = a is based on two basic ideas:
1. Enlarge as much as possible the set S until S consists of z
2. Ensure that whenever we add a vertex u to S then its permanent label
L(u) must give the shortest length from the source a to the considered
vertex u.
Ideas are extracted from the observation that: if P
0
= [a, . . . , w, z] is a shortest
path from a to z then for any vertex w appearing earlier than z in P
0
then:
L(w) < L(z).
We implement ideas by an iterative algorithm, where at each step/iteration
we
1/ update label L(v) of every vertex v S to possible smallest weight (up to
that iteration): be done by employing the rule
L(v) = min{L(v), L(w) +W(w, v)} for v S, w S (w, v) E;
2/ nd the vertex u S that has L(u) minimal, and enlarge S = S {u}: be
done easily since |V \ S| is nite and get smaller after each iteration.
We accept the lemma below, its proof can be found in any standard graph book.
Lemma 20. If L(u) is the permanent label of vertex u then L(u) is the length
of a shortest path from a = v
1
to u.
Dijkstras algorithm to compute shortest path P
0
= [a, . . . , w, z].
76 CHAPTER 5. GRAPH THEORY AND MODELS
Algorithm 1 Computing P
0
= [a, . . . , w, z]
Input G = (V, E, W, a, z), a positive weighted edge, simple, connected graph
with a xed source a, and the sink (target) vertex z
Output L(z) the length of a shortest path and the path P
0
= [a, . . . , w, z] itself
function Singlesource-shortest path( G)
1. Initialization
(1i) Set L(a) = 0, and L(v) = for v = a.
(1ii) Set S = (the set of xed label vertices)
2. Checking whether we arrive at z?
if z S then stop; output L(z).
3. Get next vertex
(3i) choose vertex u V \ S together with the smallest value of L(u).
(3ii) Set S = S {u}
4. Revise labels
For each v S, and there is vertex u S such that (u, v) E, (v connects
u), set
L(v) = min{L(v), L(u) +W(u, v)}
If L(z) < then S = S {z}. Go back line 2.
end function
Example
Convention: we circle a xed vertex u (the uncircled vertices have temporary
labels) when the algorithm proceeds. Whenever circling a xed vertex v, that
vertex has permanent label and does not change value L(v) at all; we will also
label it with the name of the vertex from which it was labeled. This operation
allows us to track back the full path P
0
to the source a from the sink when the
algorithm stops. Hence, at Line 2, when z S, return L(z) and use the names
at labels of vertices to provide the explicit path P
0
.
We change names of vertices v
1
, v
2
, . . . , v
6
to {a, b, c, d, e, z} respectively.
Initialization.
Set L(a) = 0, circle a, and set L(v) = for v = a.
Set S = [] (empty list): no circled vertex has been found yet.
5.5. ALGORITHMS ON GRAPHS 77
(G)
b=
a=
c = v3
v1
v2
d=v4
e=v5
z=v6
2
7
1
4
1
2
2
Figure 5.2: Shortest path in a weighted graph G
Iteration 1:
Line 2: Checking z S. No, z still is not circled.
Line 3: Get next vertex. We select u V \ S = V together with the smallest
value of L(u): only a is the candidate. Update S = S {a} = [a], cirle a.
Line 4: Revise labels of vertices v S connecting to the last xed vertex in S.
We label the vertices b and d adjacent to a S, obtain
L(b) = min{L(b), L(a) +W(a, b)} = min{, 0 + 2} = 2, assign (a, 2) to b
L(d) = min{L(d), L(a) +W(a, d)} = min{, 0 + 1} = 1, assign (a, 1) to d
Iteration 2:
Line 2: Checking z S. No, z still is not circled.
Line 3: Get next vertex. We select u V \ S (or equivalently u S) having the
smallest value L(u): d is the candidate since L(d) < L(b). Update
S = S {d} = [a, d], cirle d
Line 4: Revise labels of vertices v S that connect to the last xed vertex in S.
78 CHAPTER 5. GRAPH THEORY AND MODELS
We label the vertex e adjacent to d, obtain the new label
L(e) = min{L(e), L(d) +W(d, e)} = min{, 1 + 4} = 5, assign (d, 5) to e
Iteration 3:
Line 2: Checking z S. No, z still is not circled.
Line 3: Get next vertex. For all u S choose the one having label smallest: b is
the right candidate since L(b) = 2 < 5 = L(e). Update S = S {b} = [a, d, b],
cirle b.
Line 4: Revise labels of v S that connect to the last xed vertex in S. The
vertices c, e both are adjacent to b, so we obtain the new labels
L(c) = min{L(c), L(b) +W(b, c)} = min{, 2 + 7} = 9, assign (b, 9) to c
L(e) = min{L(e), L(b) +W(b, e)} = min{5, 2 + 1} = 3, assign (b, 3) to e
Note that e has been just updated its label from (d, 5) to (b, 3), a better
improvement!
Iteration 4:
Line 2: Checking z S. No, z still is not circled.
Line 3: Get next vertex. For u S having L(u) smallest, then u = e is the best
candidate since L(e) = 3 < 9 = L(c). Update S = S {e} = [a, d, b, e], cirle e.
Line 4: Revise labels of v S and connect to the last xed vertex in S. The
vertex z now is adjacent to e, obtain the new label
L(z) = min{L(z), L(e) +W(e, z)} = min{, 3 + 2} = 5, assign (e, 5) to z.
Update S = S {z}. Go back line 2, stop. The explicit path P
0
= [a, b, e, z]
5.5. ALGORITHMS ON GRAPHS 79
from a to z is listed from the inverse trail of labels:
[z (e, 5) (b, 3) (a, 2)], the shotrest length is L(z) = 5.
Matrix form of Dijkstras algorithm. When you understand the algorithm,
you can nd the answer by using the following Table 5.5.1.
Step Vertex to Uncircled
be circled a b c d e z vertices
1 a 0 2 1 b, d, c, e, z
2 d 0 2 1 5 b, c, e, z
3 b 0 2 9 1 3 c, e, z
4 e 0 2 9 1 3 5 c, z
5 (nal) z 0 2 7 1 3 5 c
6 (extra) c 0 2 7 1 3 5
Table 5.2: Step by step runing of Dijkstras algorithm
At Step 5, c has been just updated its label from (b, 9) to (z, 7), a better
improvement!.
Note 1: if you want to nd shortest paths from source a to every vertex in
graph, then you proceed computing the above table until no vertex occurs in the
nal column. If this is the case, then the nal row of the mentioned table
provides all shortest path from a to every vertex in graph.
Complexity analysis of Dijkstras algorithm
Theorem 21. Let G = (V, E, W) be a positive weighted edge, simple, connected
graph having n vertices. If f(n) is the number of times Algorithm 5.5.1
examines an edge of G in the worst case, then f(n) = O(n
2
).
5.5.2 Max-ow Min-cut algorithm by Ford-Fulkerson
Go to library, prepare for your presentation.
80 CHAPTER 5. GRAPH THEORY AND MODELS
Chapter 6
Algebraic Model and
Polynomial Equations
The structure of this chapter
1/ Gauss Elimination Its Variations
2/ Nonlinear Polynomial Equations
3/ Modeling by Algebraic Methods
j=1
a
ij
x
j
, i = 1..m
where the coecients a
i,j
, b
i
are known real numbers, and the coecient matrix
A
mn
=
_
_
a
1,1
a
1,2
a
1,3
. . . a
1,n1
a
1,n
a
2,1
a
2,2
a
2,3
. . . a
2,n1
a
2,n
a
3,1
a
3,2
a
3,3
. . . a
3,n1
a
3,n
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
a
m,1
a
m,2
a
m,3
. . . a
m,n1
a
m,n
_
_
. (6.1)
The aim: discuss numerical methods for nding unknowns x = (x
1
, x
2
, , x
n
)
We will deal with the three cases:
(i) The case where m = n: the number of equations and the number of
unknowns are equal so that the coecient matrix A
mn
is square.
(ii) The case where m < n so that we might have to nd the minimum- norm
solution among the numerous solutions.
(iii) The case where m > n (the number of equations is greater than the
number of unknowns) so that there might exist no exact solution and we must
nd a solution based on global error minimization, like the LSE (Least-squares
error) solution.
6.1. LINEAR POLYNOMIAL EQUATIONS 83
Range(A) + Ker(A)
where the one x
+
is in the row space Range(A) of A, that can be
expressed as a linear combination of the m row vectors:
x
+
= A
T
,
and the other x
= 0.
Then
A(x
+
+x
) = AA
T
+Ax
= AA
T
+ 0 = AA
T
= b
Since AA
T
is supposedly a nonsingular mm matrix resulting from
multiplying an mn matrix by an n m matrix, we can solve the equation
AA
T
= b for to get
o
= [AA
T
]
1
b
Therefore,
x
+
= A
T
o
= A
T
[AA
T
]
1
b (6.2)
provides a solution for A.x = b, but not unique, due to many possibilities of x
!
6.1. LINEAR POLYNOMIAL EQUATIONS 85
Denition 23. The matrix A
T
[AA
T
]
1
is called the right pseudo- (generalized)
inverse of A, denoted pinv(A).
Based on the principle that any one of the two perpendicular legs is shorter
than the hypotenuse in a right-angled triangle, Eq. (6.2) is believed to represent
the minimum-norm solution.
MATLAB has the pinv() command for obtaining the pseudo-inverse. We can
use this command or
the slash(/) operator to nd the minimum-norm solution (6.2)
to the system of linear equations
A.x = b, where A R
mn
; b R
n
. (6.3)
= A
T
o
= A
T
[AA
T
]
1
b
can be viewed as the projection of an arbitrary solution x
of the solution x
= x
x
+
= [Id pinv(A)A]x
Ker(A)
The matrix P = [Id pinv(A)A] is called the projection operator.
x
= A
T
[Ax b] = 0 x
= [A
T
A]
1
A
T
b
x
= [A
T
A]
1
A
T
b (6.5)
Denition 24. The matrix [A
T
A]
1
A
T
is called the left pseudo- inverse of A,
also denoted pinv(A).
The LSE solution can be obtained by using
the MATLABs pinv() command or
the backslash () operator
6.1. LINEAR POLYNOMIAL EQUATIONS 87
6.1.2 Gauss Elimination- Technique
Consider a linear system
A.x = b, where A R
mn
; b R
n
...()
Denition 25. Elementary row operations or row reductions include:
a/ Multiply both sides of an equation by a non-zero constant
b/ Add a multiple of one equation to another
c/ Interchange two equations
We now form the augmented matrix A
= [A|b],
then using row reductions on A
rowreductions
_
4x
1
+ 2x
2
x
3
= 5
x
1
+ 4x
2
+x
3
= 12
2x
1
x
2
+ 4x
3
= 12
in the form A.x = b:
_
_
4 2 1
1 4 1
2 1 4
_
_
_
_
x
1
x
2
x
3
_
_
=
_
_
5
12
12
_
_
(6.6)
The augmented matrix
A
=
_
_
4 2 1 5
1 4 1 12
2 1 4 12
_
_
4 2 1 5
0 7/2 5/4 43/4
0 0 73/14 219/14
_
_
= R
This augmented matrix represents a triangular system (the coecient matrix is
triangular):
R = [U|c] U.x = c, i.e.
6.1. LINEAR POLYNOMIAL EQUATIONS 89
_
_
4 2 1
0 7/2 5/4
0 0 73/14
_
_
_
_
x
1
x
2
x
3
_
_
=
_
_
5
43/4
219/14
_
_
; (6.7)
Backward substitution means using:
the third row: 73/14x
3
= 219/14 x
3
= 3
the second row: 7/2x
2
+ 5/4x
3
= 43/4 x
2
= 2
the rst row: 4x
1
+ 2x
2
x
3
= 5 x
1
= 1.
The solution is x = (1, 2, 3).
_
0 0 0 0 1 1 1 1 2 2 2 2 3 3 3 3
0 1 0 1 0 1 0 1 1 0 1 0 1 0 1 0
0 0 1 1 0 0 1 1 1 1 0 0 1 1 0 0
0 1 1 0 0 1 1 0 1 0 0 1 1 0 0 1
_
_
T
,
where T denotes transpose.
Example 13. Fix n = 3, we use the full factorial design 2
3
with three
binary factors to nd the relationship between the factor x
1
of mixture ratio,
the factor x
2
of temperature, the factor x
3
of experiment time period and the
response y of wood toughness.
The levels of factors are given in Table 6.1, and simulated experiments in Table
6.2:
6.3. ALGEBRAIC MODELING 97
Factor Low (0) High (1)
Mix(ture) Ratio 45p 55p
Temp(erature) 1000C 1500C
Time period 30min 90min
Table 6.1: Factor levels of 2
3
factorial experiment
RUN Mix Ratio Temp Time Response Y
1 45p (-) 100C (-) 30m (-) 8
2 55p (+) 100C (-) 30m (-) 9
3 45p (-) 150C (+) 30m (-) 34
4 55p (+) 150C (+) 30m (-) 52
5 45p (-) 100C (-) 90m (+) 16
6 55p (+) 100C (-) 90m (+) 22
7 45p (-) 150C (+) 90m (+) 45
8 55p (+) 150C (+) 90m (+) 56
Table 6.2: Results of an example 2
3
Factorial Experiment
The linear model for the wood toughness y, t by the eight experimental runs, is
y = f(x
1
, x
2
, x
3
) =
0
+
1
x
1
+
2
x
2
+
3
x
3
+
12
x
1
x
2
+
13
x
1
x
3
+
23
x
2
x
3
+
123
x
1
x
2
x
3
.
Example 14. A 2
3
fractional factorial design has only 4 runs, whose
columns correspond to the three binary factors, of the full 2
3
-factorial design of
8 runs above.
This fraction is extracted from the below Hadamard matrix of order 4 (in which
every pair of rows and pair of columns have their inner product equals to 0).
This matrix provides enough information to estimate main eects of the mixture
98 CHAPTER 6. ALGEBRAIC MODEL AND POLYNOMIAL EQUATIONS
ratio x
1
, the temperature x
2
, the experiment time period x
3
in Example 1:
F =
_
_
1 x
1
x
2
x
3
1 1 1 1
1 1 1 1
1 1 1 1
1 1 1 1
_
_
T
.
But why using Fractional Factorial Designs? To cut cost in scientic
investigations and/or in industrial manufacturing. In particular case here, if we
employ the four experimental runs of F, we can t only a linear model for the
response y of wood toughness, of the form:
y = f(x
1
, x
2
, x
3
) =
0
+
1
x
1
+
2
x
2
+
3
x
3
.
So using less resource, we now could t a model that consists of only main
factor eects!
Assignment. Write a Maple program or Singular program to compute
a/ the full design D = Q
1
. . . Q
4
above, where Q
1
= {0, 1, 2, 3},
Q
2
= Q
3
= Q
4
= {0, 1};
b/ the mixed 4 2
3
fractional design F of 16 rows above.
Three Fundamental Research Problems on FFD:
1. Problem 1: Constructing a fraction with given estimable terms (masters
6.3. ALGEBRAIC MODELING 99
Hnh 6.1: th G gm cc khu vc v lin kt
level)
2. Problem 2: Constructing a strength t balanced fraction with given
estimable terms (PhD level!)
3. Problem 3: (PhD level!) Construction of new strength t fractions F,
given
a fraction F
0
of N runs, d factors, with strength t.
We also name this the OA Column Extension Problem:
extend F
0
with a new factor X to have a new fraction F = [F
0
|X] having
the same strength t and d + 1 factors.
6.3.2 In Business Intelligence
Mt cng ty A mun pht trin kinh doanh k loi dch v, nh l cung cp thc
phm, hng ni tht, thit b truyn thng ... ti 4 khu vc chnh TPHCM, k
hiu l I, II, III, IV; bit 4 k 2. S biu din cc khu vc ny v cc i
l kt ni chng cho bi th G nh trn.
Cng ty A mun xy dng cc siu th ti cc khu vc chnh TPHCM ni trn
sao cho tha ng thi hai rng buc:
a/ ch mt siu th c xy ti 1 khu vc, v
100 CHAPTER 6. ALGEBRAIC MODEL AND POLYNOMIAL EQUATIONS
b/ hai khu vc k nhau (c i l kt ni) bt k phi c hai siu th cung
cp 2 dch v khc loi nhau.
Phng n kh thi l phng n xy dng cc siu th ti 4 khu vc chnh ni
trn m tha mn ng thi hai iu kin a/ v b/.
i) C phng n kh thi khng khi k = 2?
ii) Anh (Ch) hy trnh by cc bc c th m hnh ha i s bi ton trn
khi 2 k n, bit 2 n N l s lng khu vc chnh TPHCM.
iii) Khi s loi dch v k = 3, v n = 4 nh cho trong G, hy cho bit c bao
nhiu phng n kh thi.
Chng 7
Probabilistic Models
7.1 Practical Motivation
Probabilistic Methods help us to solve typical problems in daily life as follows.
1. Given the probability that a randomly selected student in a class is a
female is 56%, how much chance that the selected student is a male?
2. The mass, X kg, of silicon produced in a manufacturing process is
modelled by the probability density function (pdf)
f
X
(x) =
3
32
(4x x
2
) if 0 x 4; f
X
(x) = 0 otherwise.
What is the mean of the mass of silicon produced?
3. Eggs sold at a market are usually packaged in boxes of six. The number,
X, of broken eggs in a box has the probability distribution given in the
following table:
101
102 CHNG 7. PROBABILISTIC MODELS
x 0 1 2 3 4 5 6
P[X = x] 0.80 0.14 0.03 0.02 0.01 0 0
Denote by Y the number of unbroken eggs in a box.
What are the average of X and of Y respectively?
4. A discrete random variable X represents the number of trafic accidents
each year at HCMC. Suppose X has the probability mass function
f
j
= P(X = j) =
3
4
_
1
4
_
j
, j = 0, 1, 2, 3, . . . ..
with unit of 100 accidents. Up to how much chance that at most 200
accidents take place in a year?
5. Consider a Markov chain M describing the loyalty of customers to three
retailers Coop, BigC and Walmart, coded by states 0, 1, and 2 respectively.
The transition probability matrix P, obtained in a recent poll, is given by
P =
_
0.4 0.2 0.4
0.6 0 0.4
0.2 0.5 0.3
_
What is the probability in the longrun that the chain M is in state 1, that
is how much chance the customers will go with BigC?
7.2. CONCEPTS AND DEFINITIONS 103
7.2 Concepts and Definitions
Probability is the science of problem-solving in the presence of variability and
uncertainty. We will need the below basic concepts.
Experiments An experiment E is a specific trial/activity (of scientists, human
being) whose outcomes possess randomness. Simple examples are:
Coin throwing- throw a coin, random outcomes are head (H) or tail (T)
Temperature measurement- observe continuously temperatures at noon in
HCMC in 10 days of Summer 2007, random outcomes are the list
[34, 29, 28, 32, 31, 32, 30, 31, 30, 33] (in Celcius degree).
Sample space.
1. Sample space S- set of all possible outcomes.
Example 1: Coin throwing S = {H, T}
2. Events- is subset A of sample space S: A S. Usually we include all
events into a set, called the event set Q := {A : A S and is an event}.
When an experiment E is performed and an outcome a is observed we say
that event A has occurred if a A.
3. Probability distribution (probability function)- a map P from Q to the
interval [0, 1]:
P : Q [0, 1],
A Q P(A) = Prob(A) =
probability or chance that the event A occurs.
104 CHNG 7. PROBABILISTIC MODELS
Axioms of Probability Theory (A. Kolmogorov, 1933).
i=1
p
i
= 1.
Fact 2. If all outcomes have equal probabilities, then
P(A) = Prob(A) =
n
A
n
, where n
A
= |A|.
Example 15. On a single toss of a die, we get only one of six possible
outcomes: 1,2,3,4,5 or 6; then the sample space S = {1, 2, 3, 4, 5, 6}, and
p
i
= P(i) = 1/6, for all i = 1..6
7.2.1 Random Variable and Probability Distribution
Definition 26. A random variable X is a function from a set - sample space S
to the reals R. For any b R, the preimage
A := X
1
(b) = {w : X(w) = b} S
7.2. CONCEPTS AND DEFINITIONS 105
is an event, we understand
Prob{X = b} := Prob(A) =
wA
Prob(w).
For finite set - sample space S then obviously
Prob{X = b} := Prob(A) =
|A|
|S|
.
The probability distribution of a random variable describes how probabilities are
distributed over the (range) values of the random variable.
Expectation and Variance- the Discrete Case
Expectation. The expectation operator defines the expected value (or average
behavior) of a random variable X as
E(X) =
xRange(X)
P(X = x) x, where (7.1)
P(X = x) = P(X
1
(x)); and X
1
(x) = {w : X(w) = x} S.
In words, E(X) is a weighted average of the possible values of X, where the
weight given to a value x is equal to the probability P(X = x) that X assumes
that value.
Note: since the r.v. X : S R is an assignment of values to the points in
sample space S, you could also think
E(X) =
wS
P(w) X(w) equivalently.
106 CHNG 7. PROBABILISTIC MODELS
Variance of a random variable X is
Var(X) = E[(X E(X))
2
].
7.2.2 Why study Probability Distributions?
Citibank in HCMC makes available financial services, including checking and
saving accounts, loans, mortgages, insurance and investment services. These
complicated activities have been done through a Citibanking system consisting
of many modules, like ATMs, or more advanced, the Card Banking Centers
(CBCs).
What would be the services available at CBSs? and How? Each CBC operates as
a waiting line system with randomly arriving customers seeking service at one of
the ATMs. CBC capacity studies are used
- to analyze customer waiting line and
- to determine whether additional ATMs are needed.
Data collected by Citibank showed that the random customer arrivals followed
a probability distribution known as the Poisson distribution. Using the
Poisson distribution, Citibank can compute probabilities for the number of
customers arriving at a CBC during any time period and decisions concerning
the number of ATMs needed.
Discrete probability distributions, such as the one used by Citibank are the topic
of the next section.
7.3. DISCRETE PROBABILITY DISTRIBUTIONS 107
7.3 Discrete Probability Distributions
Definition 27. Discrete random variable X is the one that has a finite range
set. For a discrete ran. var. X, its probability distribution is the probability
function
f(x) = P({X = x},
providing the probability that the r. v. X receives a particular value
x Range(X).
The discrete probability distribution f(x) must fulfill:
f(x) 0, and
xRange(X)
f(x) = 1.
Example 16 (Die tossing). On a single toss of a die, we get only one of six
possible outcomes 1,2,3,4,5 or 6; then the sample space S = {1, 2, 3, 4, 5, 6}.
Define the random variable X : S R
+
to be the identity function Id, that is
X(i) = Id(i) = i, i S.
The probability distribution associated with X is the probability function
f(i) = Prob{X = i} = P{X
1
(i)} =
|X
1
(i)|
|S|
= 1/6, for i = 1..6
Often for discrete distributions, we write p
i
= f(i) = P(i).
Example 17 (Fair bet). A bet whose expected winnings equals to 0 is called a
fair bet. Let the random variable X denote the amount that we win when we
make a certain bet. Find E(X) if there is a 60% chance that we lose 1 USD, a
20% chance that we win 1 USD, and a 20% chance that we win 2 USD. Is this a
fair bet?
108 CHNG 7. PROBABILISTIC MODELS
Lemma 28. For constants a and b, and for a discrete random variable X, we
have
E(aX +b) = a E(X) +b.
Chng minh. Use the definition 7.1.
* Important discrete distributions include Bernoulli, Binomial and Poisson.
1/ Bernoulli Distribution B(p) describes a random variable that can take
only two possible values, i.e. X = {0, 1}. Its probability function is given by
p(1) = P(X = 1) = p, p(0) = P(X = 0) = 1 p for some p [0, 1].
Use Eq. 7.1, it is easy to check that E(X) = p, Var(X) = p(1 p).
wS
P(w) V (w).
110 CHNG 7. PROBABILISTIC MODELS
3/ Poisson distribution: The Poisson distribution is given by
p(x) =
e
x
x!
x = 0, 1, 2, ... (7.3)
where
x = designated number of successes,
> 0 a constant = the average number of successes per unit of time period
e = 2.71 the natural base.
The Poisson distributions mean and the variance are
= ;
2
= = .
7.4 Problems
Problem 1: Describe in details some examples of when we can apply the Poisson
distribution.
Help: Poisson distributions can be used in the followings.
To model of the number of occurrences of some event/ phenomenon in the
time interval (0, t], we can use Formula 7.3. Now x = 0 implies that there
are no occurrences of the event in (0, t], and Prob(x = 0) = p(0) = e
.
To model the number of defects or non-conformities that occur in a
unit of product (unit area, volume ...) say, a semiconductor device, by a
Poisson distribution.
Problem 2: given that the number of wire-bonding defects per unit X is Poisson
distributed with parameter = 4. Compute the probability that a randomly
selected semiconductor device will contain two or fewers wire-bonding defects.
7.4. PROBLEMS 111
Problem 3. Past experience indicates that an average number of 6 customers per
hour stop for banking services at a bank.
(a) Find the probability of 3 customers stopping in any hour.
(b) Find the probability of 3 customers or less stopping in any hour
(c) What is the expected value, or mean, and standard deviation for this
distribution?
Problem 4. Two fair dice are tossed. If the total is 7, we win $100; if the total is
2 or 12, we lose $100; otherwise we lose $10. What is the expected value of the
game?
Problem 5. Known that 1% of the lightbulbs produced by DienQuang Cor. are
defective. Find the probability that 1 bulb is defective in a random sample of 30
bulbs, using
a) the binomial and
b) the Poisson approaximation of the binomial distribution?
.
2. The same request as above for H = (W, A) where W = {v
1
, v
2
, v
3
, v
4
, v
5
}
and A = {v
1
v
2
, v
2
v
3
, v
3
v
1
, v
3
v
4
, v
5
v
1
, v
5
v
3
}.
3. State the definition of weight matrix W of a weighted digraph G = (V, A).
4. Can you draw the graph G = (V, A) and write down its weight matrix W
where V = {a, b, c, d, e, f}, the arcs A = {ab, bc, be, cf, ef, ad, de} and the
corresponding weights are [2, 1, 4, 5, 1, 3, 2].
5. Practical Project: [use Chapter 5: Graph Theory].
A farmer wishes to ferry a deer, a cabbage, a lion and a pet mouse across
a river with a small boat which can accommodate at most two of his
belongings at a time. Furthermore, he
i/ will not let the lion be alone (i.e. without him) with the deer, and also
ii/ will not let the mouse be alone with the cabbage,
for a clear reason that the predators will eat the preys in the three
mentioned cases.
a/ Model the problem with a state transition graph G = (V, E) by using
appropriate state variables; f for the farmer, and g, c, w, m for his
belongings. Known that state variables can receive two states: L (for
at the left bank) and R (for at the right bank).
7.4. PROBLEMS 113
Hint: Describe firstly all states (vertices), and then list eligible states
u of V , by using the system invariants mentioned above with logic
notation.
b/ Describe clearly rules to form edges of G.
Appendix 1: Hamming metric.
Usually a state set of a graph G = (V, E) can be given by a binary
space/set V consisting of length n vectors:
V = {u = (u
1
, u
2
, . . . , u
n
) : u
i
= 0 u
i
= 1}.
The Hamming distance d(u, v) between two binary states
u = (u
1
, u
2
, . . . , u
n
) and v = (v
1
, v
2
, . . . , v
n
) is the number of their distinct
coordinates:
d(u, v) = |u
1
v
1
| +|u
2
v
2
| +. . . +|u
n
v
n
| =
n
i=1
|u
i
v
i
|
The weight of a binary state/vector is defined to be
wt(u) = d(u, 0) =
n
i=1
|u
i
0| =
n
i=1
u
i
.
The Hamming distance d(., .) defined on some binary space V is also
called the Hamming metric, and the space V equipped with the Hamming
metric d(., .) is called a Hamming metric space.
Appendix 2: State-transition in graphs.
Very often, changing states of a state-transition graph G = (V, E) can be
conducted mathematically by measuring how far the Hamming distance is
114 CHNG 7. PROBABILISTIC MODELS
between an original state u = (u
1
, u
2
, . . . , u
n
) to its effect state
v = (v
1
, v
2
, . . . , v
n
).
Example 18. A farmer wishes to ferry a goat, a cabbage and a wolf
across a river with a small boat which can
accommodate at most one of his belongings at a time.
Furthermore, he will not let the goat be alone (i.e. without him) with
cabbage, for a clear reason that the predator will eat the prey in the
mentioned case. What would be possible invariants of the process of
transporting between the river banks?
* You can not formulate any invariant without introducing some major
variables. Here four variables f, g, c, w would be reasonably good for
describing the moving process, where f, g, c, w all receive values from the
binary set {L(eft bank), R(ight bank)} = {0, 1}. Well, the situation that
the goat is not allowed be alone with cabbage without farmer is just
symbolically represented by the fixed rule:
Invariant 1 : (g = c) OR (f = g = c)
This rule is indeed an invariant, since it is (or better must be) maintained
in the whole process.
* Finding the invariant saying that the small boat can
accommodate at most one of the farmer belongings at a time is more
tricky! To do this, you have to think about the state-changing aspect of
the process when the farmer rows from one side to the other side of the
river. [You will not draw a boat with some items on it and move it on the
river several times, will you?] Then a simple question naturally arises:
7.4. PROBLEMS 115
what are the states of the process?
Example 19 (The farmers crossing river problem, cont.). The states of
the river crossing process are binary vectors of length 4
u = (u
f
, u
g
, u
c
, u
w
) = (u
1
, u
2
, u
3
, u
4
) {0, 1}
4
,
if we encode the left bank L and the right bank R by {0, 1} as done above!
We understand when the farmer is rowing his boat, for instance from a
left river bank u = (u
1
, u
2
, u
3
, u
4
) to a right river bank v = (v
1
, v
2
, . . . , v
n
)
(or the other way round), his position must change. The changing of state
u to v creates an edge e = (u, v) E, indeed! More clearly, the edge
e = (u, v) is truly determined iff
if u
1
= L(i.e. 0) then v
1
= R(i.e. 1); or the other way round.
A ha, we just find another invariant, must always be true during process
evolving or running: [e = (u, v) would exist if we have ]
Invariant 2 : u
1
+v
1
= 1, where the sum is binary plus.
Can you find more invariants and employ them?
.....
ANSWER: Combining with the fact that
the small boat can accommodate at most one of the farmer belongings
we realize a starting state u change at most two of its two coordinates to
be the result v. Hence, the third invariant is found:
116 CHNG 7. PROBABILISTIC MODELS
Invariant 3 : d(u, v) =
4
i=1
|u
i
v
i
| 2.
7.4. PROBLEMS 117
Copyright in 2011 by
Lecturer Nguyen V.M. Man, Ph.D.
Faculty Computer Science and Engineering
Institution University of Technology of HCMC
Address 268 Ly Thuong Kiet, Dist. 10, HCMC, Vietnam
Email: [email protected]
[email protected]