Propositional Logic Propositional Equivalences: Chapter 1: Logic and Proof
Propositional Logic Propositional Equivalences: Chapter 1: Logic and Proof
1
Thanks to Dr Patrick Chan for providing the Slides
Agenda
▪ Ch1.1 Propositional Logic
▪ Proposition
▪ Propositional Operator
▪ Compound Proposition
▪ Applications
▪ Ch1.2 Propositional Equivalences
▪ Logical Equivalences
▪ Using De Morgan's Laws
▪ Constructing New Logical Equivalences
2
Warm Up…
• John is a cop. John knows first aid. Therefore, all cops know
first aid
3
Warm Up…
▪ Human walks by two legs. Human is mammal. Mammal walks
by two legs.
4
Warm Up…
▪ The clock alarm of my iphone does not work today. The
clock alarm of iphone does not work on 1-1-2011. So, today
is 1-1-2011
5
Warm Up…
▪ Some students work hard to study. Some students fail in
examination. So, some work hard students fail in examination.
6
Small Quiz
▪ Next few pages contain 4 questions
▪ Write down the answer of each question on a paper
▪ Remember
▪ No Discussion
▪ Do not modify answers you written down
7
Small Quiz: Question 1
▪ According to the law, only a person who is elder than 21-year-
old can have alcoholic drink
▪ You are a police. Which person(s) you need to check?
8
Small Quiz: Question 2
▪ According to a policy of a company, if someone surf the
Internet longer than 2 hours, he/she has to earn more than
300k
▪ You are the boss of this company. Which staff(s) you need
to check?
9
Small Quiz: Question 3
▪ A company publishes a desk:
▪ Each card has two sides: a character and a number
▪ If one side of a card is a vowel, the number on the other
side should be even number
▪ You are a QC staff. Which card(s) you need to check?
E T 4 7
10
Small Quiz: Question 4
▪ A company publishes another desk:
▪ Each card has two sides: a shape and a color
▪ If one side of a card is a circle, the color on the other side should
be yellow
▪ You are a QC staff. Which card(s) you need to check?
11
Small Game: Answer
• Q1: Only a person who is elder than
21-year-old can have alcoholic drink
• Q2: If someone surf the Internet
longer than 2 hours, he/she has to
earn more than 300k
• Q3: If one side of a card is a vowel,
the number on the other side is
even number
• Q4: If one side of a card is a circle,
the color on the other side is yellow
12
Introduction
▪ In this chapter, we will explain how to
▪ make up a correct mathematical argument
▪ prove the arguments
13
Propositions
▪ Proposition (also called statement) is a declarative sentence
(declares a fact) that is either true or false, but not both
▪ Truth value of a proposition is either True/False (T/F) to indicate
its correctness
▪ Example:
▪ Keep quiet
✓
Not declarative
▪ 1 hour has 50 minutes
✓
False
▪ 1+1=3 False
▪ x+2=4 Can be either true or false
Can be turned into proposition when x is defined
14
Propositions
▪ Proposition Variable is letters denote propositions
▪ Conventional letters are p,q,r,s,……P,Q ,……
▪ Example: r : Peter is a boy
16
Proposition Logic
Conjunction Operator (AND)
▪ Definition
▪ Let p and q be propositions
▪ Conjunction of p and q is “p and q”
▪ Notation: p ⋀ q
▪ ⋀ points up like an “A”, which means “⋀ ND”
▪ Truth value
▪ True when both p and q are true
▪ False otherwise
▪ Example:
▪ p: Peter likes to play, q: Peter likes to read
▪ p ⋀ q : Peter likes to play and Peter likes to read
17
Proposition Logic
Disjunction Operator (OR)
▪ Definition
▪ Let p and q be propositions
▪ Disjunction of p and q is “p or q”
▪ Notation: p ⋁ q
▪ ⋁ points up like an “r”, means “O ⋁”
▪ Truth value
▪ False when both p and q are false
▪ True otherwise
▪ Example:
▪ p: Peter likes to play, q: Peter likes to read
▪ p ⋁ q : Peter likes to play or Peter likes to read
18
Proposition Logic
Disjunction Operator (OR)
▪ In English, OR has more than one meanings
▪ Example:
▪ Jackie is a singer OR Jackie is an actor
▪ Either one or both (inclusive)
▪ Disjunction operation (OR, ⋁ )
▪ Jackie is a man OR Jackie is a woman
▪ Either one but no both (exclusive)
▪ Exclusive OR operation (⊕ )
19
Proposition Logic
Exclusive OR Operator (XOR)
▪ Definition
▪ Let p and q be propositions
▪ Notation: p ⊕ q,
▪ Truth value
▪ True when exactly one of p and q is true
▪ False otherwise
▪ Example:
▪ p: You can have a tea, q: You can have a coffee
▪ p ⊕ q : You can have a tea or a coffee, but not both (exclusive or)
20
Small Exercise
▪ Given
p: “Today is Friday” q: “It is raining today”
▪ What is…?
▪ ¬p
Today is not Friday
▪ p ⋀ q
Today is Friday and it is raining today
▪ p⋁q
Today is Friday or it is raining today
▪ p⊕q
Either today is Friday or it is raining today, but not both
21
Small Exercise
▪ Given
p: “x > 50” q: “x < 100”
▪ What is…?
▪ ¬p
x ≤ 50
▪ p ⋀ q
Only q is T Only p is T
100 > x > 50
▪ p⋁q
p is T
x can be any number q is T
▪ p⊕q 50 100
x ≥ 100 or x ≤ 50 Both q and p is T
22
Proposition Logic
Truth Table
▪ Truth Table displays the relationships between the truth values of
propositions
▪ Example:
▪ Truth Table of Negation Operation
P ¬P
T F
F T
23
Proposition Logic
Truth Table
T T F T T F
T F F F T T
F T T F T T
F F T F F F
24
Proposition Logic
Conditional Statement (imply)
▪ Definition
▪ Let p and q be propositions
▪ Conditional statement is “if p, then q”
▪ Notation: p → q
▪ p is called the hypothesis (or antecedent or premise)
▪ q is called the conclusion (or consequence)
▪ Truth value p q p→q
▪ False when p is true and q is false T T T
▪ True otherwise T F F
▪ Example F T T
▪ p: you work hard, q: you will pass this subject F F T
▪ p → q : If you work hard, then you will pass this subject
25
Proposition Logic
Conditional Statement (imply)
▪ Example:
▪ p: “You give me twenty dollars”
▪ q: “We are the best friends”
▪ What is p → q?
▪ If you give me twenty dollars, then we are the best friends
▪ Assume p → q is true, what does “you do not give me twenty dollars”
(¬p) mean?
▪ Does it mean
▪ “We are not the best friend” (¬p → ¬q)?
26
Proposition Logic
Conditional Statement (imply)
▪ Example: p → q and its Contrapositive are equivalent
▪ Given p → q
Converse and Inverse are equivalent
“If it rains, the floor is wet”
▪ Situation 1 (¬p → ¬q) Inverse
If it does not rain, the floor is not wet
▪ Situation 2 (q → p ) Converse
If the floor is wet, it rains
▪ Situation 3 (¬q → ¬p) ✓ Contrapositive
If the floor is not wet, it does not rain
27
Proposition Logic
Necessary Condition
▪ Example
▪ Being divisible by 4 is sufficient for being an even number
29
Proposition Logic
Necessary / Sufficient Condition
▪ Relation between conditional statement and necessary / sufficient condition
▪ Necessary Condition
▪ E.g. Breathing is necessary condition for human life
P Q P is necessary
condition of Q
T T T p q p→q
T F T T T T
F T F
T F F
F F T
F T T
F F T
▪ Sufficient Condition
▪ E.g. Being divisible by 4 is sufficient for being an even number
P Q P is sufficient
condition of Q
▪ p → q is equivalent to:
T T T
T F F ▪ p is sufficient condition of q
F T T ▪ q is necessary condition of p
F F T
30
Proposition Logic
Conditional Statement (imply)
▪ Other equivalent forms for P → Q:
▪ P is a sufficient condition for Q
▪ Q is a necessary condition for P
▪ P implies Q
▪ If P, then Q
▪ If P, Q
▪ Q if P
▪ Q whenever P
P cannot be true when Q is not true
▪ P only if Q Q is necessary condition for P
31
Proposition Logic
Conditional Statement (imply)
▪ Remark:
▪ No causality is implied in P → Q
▪ P may not cause Q
▪ For example:
▪ If I have more money than Bill Gates, then a rabbit lives on the moon
32
1->2
33
Proposition Logic
Conditional Statement (imply)
▪ Example:
▪ A mother tells her child that “If you finish your homework, then you can eat the ice-
cream”
▪ What does it mean?
▪ Case 1 (p → q)
▪ Homework is finished, you can eat the ice-cream
▪ Homework is not finished, you can/cannot eat the ice-cream
▪ Case 2
▪ Homework is finished, you can eat the ice-cream
▪ Homework is not finished, you cannot eat the ice-cream
34
Proposition Logic
Biconditional Statement (equivalent)
▪ Definition
▪ Let p and q be propositions
▪ Biconditional statement is “p if and only if q” (iff)
▪ Notation: p ↔ q
▪ Also called bi-implications, equivalence
▪ Equivalent to (p → q) ⋀ (q → p)
p q p↔ q
▪ Truth value T T T
▪ True when p and q have the same truth values T F F
F T F
▪ False otherwise F F T
35
Proposition Logic
Necessary / Sufficient Condition
▪ p is necessary but not sufficient for q
q→p
▪ p is sufficient but not necessary for q
p→q
▪ p is both necessary and sufficient for q
p →q ⋀ p → q q↔p
▪ q is also both necessary and sufficient for p
36
Proposition Logic
▪ Remarks:
▪ In ordinary speech, words like “or” and “if-then” may have
multiple meanings
▪ In this technical subject, we assume that
▪ “or” means inclusive or ( ∨ )
▪ “if-then” means implication (→)
37
Proposition Logic
▪ Summary
38
Proposition Logic
▪ Summary
T T F T T F T T
T F F F T T F F
F T T F T T T F
F F T F F F T T
39
Compound Proposition
▪ Compound Propositions are formed from existing propositions using proposition logical
operators
▪ Example: Beijing is the capital of China and 1+1=2
▪ How can we determine the truth values of the complicated compound propositions
involving any number of propositional variables?
▪ Example:
What is the truth value for every situations? p → ¬q ↔ s ⋀ q ⨁ p
40
Compound Proposition
Precedence Operator
1 ¬ NOT
2 ⋀ AND
3 ⋁ ⨁ OR XOR
4 → Imply
5 ↔ Equivalent
▪ Example:
✓ ✓
▪ p⋁q⋀r ▪ ¬s⋀f ▪ a ↔ f→b
✓
▪ p ⋁ ( q ⋀ r) ▪ (¬ s )⋀ r ▪ (a↔f) →b
▪ (p ⋁ q) ⋀ r ▪ ¬ (s ⋀ f ) ▪ a↔(f→b )
41
Compound Proposition
42
Compound Proposition
▪ Algorithm:
2. Find the truth value of each compound expression that occurs in the
compound proposition according to the operator precedence
43
Compound Proposition
44
Compound Proposition
45
Compound Proposition
46
Compound Proposition
47
Compound Proposition
48
Compound Proposition
49
Compound Proposition
(p ∨ ( r ∧ q ))⟷(p ⊕ ( ¬r ) )
p q ¬p p ⋀ q p ⋁ q p ⨁ q p→q p↔q
T T F T T F T T
T F F F T T F F
F T T F T T T F
F F T F F F T T
51
Small Exercise
52
Translating English Sentences
53
Translating English Sentences
▪ Algorithm:
1. Remove the connective operators
2. Let a variable for each complete concept
3. Use the operators to connect the variables
4. Adding brackets in suitable positions will be helpful
▪ Example:
▪ You can access the Internet from campus only if you are a computer science major or you
are not a freshman
p →(q ⋁ ¬ s )
▪ p: “You can access the Internet from campus”
▪ q: “You are a computer science major”
▪ s: “You are a freshman”
54
Applications
System Specifications
▪ Specifications are the essential part of the system and software
engineering
55
Applications
System Specifications
▪ Example:
56
Applications 1.Remove the connective operators
2.Let a variable for each complete concept
System Specifications 3.Use the operators to connect the variables
4. Adding brackets in suitable positions will be helpful
57
Applications
58
Applications
A 1011 0110
B 0001 1101
Bit-wise OR 1011 1111
59
Applications
Logic Puzzles
▪ Puzzles that can be solved using logic are known as logic puzzles
▪ Example:
▪ There are two kinds of people on an island
▪ Batman: Always tell the truth
▪ Joker: Always lie
60
A B P Q
Batman Batman T F
Batman Joker F T
Joker Batman T T
Joker Joker F F
61
Types of Proposition
▪ Tautology P ¬P P ⋁ ¬P
▪ A compound proposition which is always true T F T
▪ Example: P ⋁ ¬P F T T
▪ Contradiction
P ¬P P ∧ ¬P
▪ A compound proposition which is always false T F F
▪ Example: P ∧ ¬P F T F
▪ Contingency
P
▪ A compound proposition which is neither a P ∧ ¬P P ⊕ (P ∧ ¬P)
T F T
tautology nor a contradiction
F F F
▪ Example: P ⊕(P ∧ ¬P)
62
Types of Proposition
▪ Are they Tautology, Contradiction or Contingency?
▪ P→P Tautology
▪ P⊕P Contradiction
▪ P↔P Tautology
▪ P→Q Contingency
▪ ¬P ⋁ Q Contingency
▪ ¬(P → Q) ∧ Q Contradiction
63
Logically Equivalence
64
Logically Equivalence
▪ Definition
Two propositions P and Q are logically equivalent if P ↔ Q is a
tautology
▪ Notation: P ⇔ Q or P ≡ Q
65
Logically Equivalence
▪ Truth Table can be used to test if compositions are logically
equivalent
▪ Example:
• if ¬p ⋁ q and p → q are logically equivalent?
¬p ⋁ q ⇔ p → q
66
Logically Equivalence
▪ Example:
Show p ⋁ (q ∧ r) ⇔ (p ⋁ q) ∧ (p ⋁ r)
67
Logically Equivalence p q s T
T T T T
T T T F
▪ Characteristic of Truth Table T T F T
▪ Assume n is the number of variables, Raw of tables = 2n T T F F
68
69
70
71
72
73
74
▪ Distributive Laws
p ∨ (q ∧ r) ≡ (p ∨ q) ∧ (p ∨ r)
p ∧ (q ∨ r) ≡ (p ∧ q) ∨ (p ∧ r)
75
76
77
78
▪ De Morgan’s Laws Extension
79
▪ De Morgan’s Laws Extension
80
81
82
83
84
85
86
87
88
89
Test
90
主观题 10分
作答 91
主观题 10分
作答 92
主观题 10分
作答 93
主观题 10分
请您编辑题干
作答 94
主观题 10分
请您编辑题干
作答 95
主观题 10分
作答 96
97
Discrete Mathematic
Agenda
Rules of Inference
Rules of Inference for Quantifiers
Recall…
Some students work hard to study. Some
students fail in examination. So, some work
hard students fail in examination.
Argument: Valid? p1
Given an argument, where p2
p1, p2, …, pn be the premises
…
q be the conclusion pn
The argument is valid when q
(p1 p2 … pn) q is a tautology
When all premises are true, the conclusion should be true
When not all premises are true, the conclusion can be either
true or false
p q pq
T T T
Focus on this case
T F F
Check if it happens
F T T
F F T
Chapter 1.5 & 1.6 6
Argument
Example: Argument is valid
pq If it rains, the floor is wet
p It rains
q The floor is wet
( p (p q) ) q Tautology
Need to check if p q pq p (p q) (p (p q)) q
the conclusion is T T T T T
true or not T F F F T
F T T F T
Must be true F F T F T
Rules of Inference
How to show an argument is valid?
Truth Table
May be tedious when the number of variables is
large
Rules of Inference
Firstly establish the validity of some relatively
simple argument forms, called rules of inference
These rules of inference can be used as building
blocks to construct more complicated valid
argument forms
Modus Tollens
q
Deny by denying pq
p
Rules of Inference
Hypothetical Syllogism pq
qr
pr
Disjunctive Syllogism
pq
p
q
pq
Simplification p q
p
Conjunction p
q
pq
Chapter 1.5 & 1.6 11
Rules of Inference
Resolution
pq
p=T p=F p r
q = T/F q=T
r=T r = T/F qr
Example
I go to swim or I play tennis
I do not go to swim or I play football
Therefore, I play tennis or I play football
Addition (p) p q
Small Exercise
Given:
If you send me an e-mail message,
then I will finish writing the program
If you do not send me an e-mail message,
then I will go to sleep early
If I go to sleep early,
then I will wake up feeling refreshed
Can these propositions lead to the conclusion
"If I do not finish writing the program,
then I will wake up feeling refreshed."
Small Exercise
Step Reason
1. pq Premise
Hypothesis: 2. ¬q ¬p Contrapositive of (1)
pq 3. ¬p r Premise
x P(x) x P(x)
P(a) P(c) for some element c
where a is a particular member
of the domain
Step Reason
1. x (DC(x) CS(x)) Premise
2. DC(Marla) CS(Marla) Universal Instantiation from (1)
3. DC(Marla) Premise
4. CS(Marla) Modus ponens using (2) and (3)
Small Exercise
Given
A student in this class has not read the book
Everyone in this class passed the first exam
These premises imply the conclusion
"Someone who passed the first exam has not
read the book"
Small Exercise
Premise: Conclusion:
x (C(x) ¬RB(x))
x (PE(x) ¬RB(x))
x (C(x) PE(x))
Step Reason
1. x (C(x) ¬RB(x)) Premise
2. C(a) ¬RB(a) Existential Instantiation from (1)
3. C(a) Simplification from (2)
4. x (C(x) PE(x)) Premise
5. C(a) PE(a) Universal Instantiation from (4)
6. PE(a) Modus ponens from (3) and (5)
7. ¬RB(a) Simplification from (2)
8. PE(a) ¬RB(a) Conjunction from (6) and (7)
9. x (PE(x) ¬RB(x)) Existential Generalization from (8)
Premise: Conclusion:
x (C(x) ¬RB(x))
x (PE(x) ¬RB(x))
x (C(x) PE(x))
Chapter 1.5 & 1.6 33
P(n): n > 4
Q(n): n2 < 2n
n (P(n) Q(n))
P(100) (since 100 > 4)
Q(100) (1002 < 2100) By Universal Modus Ponens
Informal Proofs
Informal proofs can often explain to
humans why theorems are true
Proof of mathematical theorems
Applications to computer science
Move from formal proofs toward more
informal proofs
p1
Assume p1 show
premise
…
are true
pn
q
Chapter 1.5 & 1.6 42
Universal Quantification: Proof of Theorems: Implication
Direct Proof: Example 1
Prove “If n is an odd integer, then n2 is odd”
Given,
The integer n is even
if there exists an integer k such that n = 2k
The integer n is odd
if there exists an integer k such that n = 2k+1
Show
If n is an odd integer, then n2 is odd
1. Assume the hypothesis is true
“n is odd” is true
By definition, n = 2k + 1, where k is a integer
2. Show the conclusion is correct
n2 is odd
n2 = (2k + 1)2 = 4k2 + 4k + 1 = 2(2k2 + 2k) + 1
By definition, as (2k2 + 2k) is an integer we can
conclude that n2 is an odd integer
Therefore, “if n is an odd integer, then n2 is an
odd integer” has been proved
Chapter 1.5 & 1.6 44
Universal Quantification: Proof of Theorems: Implication
Direct Proof: Example 2
Prove “If m and n are both perfect squares,
then nm is also a perfect square”
Given
An integer a is a perfect square
if there is an integer b such that a = b2
Show
If m and n are both perfect squares, then nm is also a
perfect square
Proof by Contraposition
Recall, contrapositive:
p q q p
p q can be proved by showing q p is
true
1. Assume the conclusion is not true
2. Show either one premise is not true
(p1 p2 … pn) q
q (p1 p2 … pn)
q (p1 p2 … pn)
Chapter 1.5 & 1.6 49
Small Exercise
Prove that “the sum of two rational numbers is
rational”
Given
The real number r is rational if there exist integers
p and q with q ≠ 0 such that r = p / q
A real number that is not rational is called
irrational
Small Exercise
Prove “if n is an integer and n2 is odd, then n
is odd”
Direct proof
Suppose that n is an integer and n2 is odd
Exists an integer k such that n2 = 2k + 1
Show n is odd
Show (n = ± √2k + 1) is odd
May not be useful
Universal Quantification
Proof of Theorems: Equivalence
Recall, p q (pq) (qp)
To prove equivalence, we can show p q
and q p are both true
Two steps
1. If n is a positive integer,
(shown in slides 43)
if n is odd, then n is odd
2
2. If n is a positive integer,
(shown in slides 54)
if n2 is odd, then n is odd
Therefore, it is true
Universal Quantification
Proof of Theorems: Equivalence
How to show p1, p2, p3 and p4 are equivalence?
p1 p2
p1 p3 p1
p1 p4 p2
p2 p3
p2 p4 p4
p3
p3 p4
Not necessary
E.g. if p1 p2 and p2 p3, then p1 p3
p4 p4 p4
p3 p3 p3
Chapter 1.5 & 1.6 59
Proof by Contradiction
By using Proof by Contradiction,
If you want to show p is true, you need:
p q is true P Q P Q
q is false T T T
T F F
F T T
F F T
Proof by Contradiction
Procedures of Proof by Contradiction to
prove p is correct :
1. Understand the meaning of p
2. Find out what p implies (p q is true)
3. Show that q is not correct
√2 = p / q , where q ≠ 0
2q2 = p2
p2 is an even number
If p2 is even, so p = 2a, and a is an integer
2q2 = 4a2
q2 = 2a2
q is also even
As p and q are even, they have a common factor
2, which leads the contradiction
Therefore, “ √ 2 is irrational” is true
Chapter 1.5 & 1.6 65
Proof by Contradiction
Proof by Contradiction can also be used to
show P(x) Q(x) (implication)
Let S(x) : P(x) Q(x) and prove S(x) is
correct
S(x) : P(x) Q(x)
S(x) (P(x) Q(x)) is true
P(x) Q(x) is false S(x)
= (P(x) Q(x))
= (P(x) Q(x))
= P(x) Q(x)
Chapter 1.5 & 1.6 68
Universal Quantification: Methods of Proving Theorems: Statement
Universal Quantification
Exhaustive Proof
Exhaustive Proofs
Prove all the possibilities
Example
Prove that (n + 1)3 > 3n if n is a positive integer
with n ≤ 4
Prove all the possibilities: n = 1, 2, 3 and 4
When n = 3 When n = 4
LHS: (n + 64 1)3 = LHS: (n + 1)3 = 125
RHS: 3n = 27 RHS: 3n = 81
LHS > RHS LHS > RHS
Therefore, (n + 1)3 > 3n is valid
Universal Quantification
Exhaustive Proof: Example 2
Given
An integer is a perfect power if it equals na , where a is an integer
greater than 1
Prove that the only consecutive positive integers not exceeding
100 that are perfect powers are 8 and 9
By exhaustive proof, list all the perfect powers not exceeding 100
n=1 2 3 4 5 6 7 8 9 10
a=2 1 4 9 16 25 36 49 64 81 100
3 1 8 27 64
4 1 32 81
5 1 64
>5 1
Universal Quantification
Proof by Cases: Example 1
Prove that if n is an integer, then n2 ≥ n
When n ≥ 1
n2 = n x n ≥ n x 1 = n, therefore n2 ≥ n
When n = 0
n2 = n = 0, therefore, n2 = n
When n ≤ -1
n2 > 0 and n < 0, therefore n2 ≥ n
Therefore, this theorem is valid
Existence Proofs
We will focus on the theorems which are
assertions that objects of a particular type
exist ()
A theorem of this type is a proposition of the
form x P(x), where P is a predicate
The proof of this proposition is Existence
Proof
By finding an element a such that P(a) is true
Uniqueness Proof
The theorems which assert the existence of a
unique element with a particular property will be
discussed
The two parts of a uniqueness proof are:
Existence (An element with the property exists)
Show that an element x with the property exists
Uniqueness (No other element has this property)
Show that if y ≠ x, y does not have the property.
Equivalently, we can show that if x and y both have
the desired property, then x = y
x (P(x) y( P(y) (y = x) ) )
Existence Uniqueness
Chapter 1.5 & 1.6 80
Uniqueness Proof: Example
Show that if a and b are real numbers and a ≠ 0,
then there is a unique real number r such that
ar + b = 0
Existence Part
The real number t = -b / a is a solution of ar + b = 0 because
a(-b/a) + b = -b + b = 0
Consequently, a real number t exists for which at + b = 0
Uniqueness Part
Suppose that s is a real number such that as + b = 0
at + b = as + b t is – b / a
at = as a is nonzero
t=s
This means that if s ≠ t, then as + b ≠ 0
Chapter 1.5 & 1.6 81
Tips
DO NOT over simplify the proof
“Obviously" or "clearly” in proofs indicate that steps
have been omitted that the author expects the reader
to be able to fill in
Unfortunately, this assumption is often not warranted
We will assiduously try to avoid using these words and
try not to omit too many steps
However, if we
included all steps in
proofs, our proofs
would often be too
long
Agenda
Ch 2.1
Set
The Power Set
Cartesian Products
Using Set Notation with Quantifiers
Truth Sets of Quantifiers
Ch 2.2
Set Combination
Set Identifies
Generalized Unions and Intersections
Ch 2.1 & 2.2 2
Set
Definition
A set is an unordered collection of objects
The objects in a set are called the elements, or
members, of the set
Notation:
a A denote that a is an
element of the set A
a A denotes that a is not
an element of the set A
Set
There are many ways to express the sets
Listing all the elements
Set builder notation
Venn diagrams
Set
Set Builder
Describe the properties the elements must have to
be members
S = {x | P(x)}
S contains all the elements which make the predicate
P true
Example:
R = { x | x is integer < 100 and > 40}
O = { x | x is an odd positive integer less than 10}
= {x Z+ | x is odd and x < 10}
Z+ is the set of positive integers
Set
Venn Diagrams
Venn Diagrams are named after the English
mathematician John Venn
A rectangle represents the
universal set U v w
Contains all the objects under e a
consideration
U may varies depends on z U
which objects are of interest
Set
Two sets are equal if and only if they have
the same elements
A and B are sets
A and B are equal if and only if
x (x A ↔ x B)
Notation (=)
We write A = B if A and B are equal sets
x (x A x B)
Subset Subset: x (x A x B)
Every nonempty set S is guaranteed to have
at least two subsets,
Empty set ( S)
x is always false
Set S itself (S S)
x S x S must be true
x (x A x B) x (x B x A)
Ordered n-tuple
Two ordered n-tuples are equal if and only if
each corresponding pair of their elements is
equal
(a1, a2, ..., an) = (b1, b2, ..., bn)
if and only if ai = bi, for i = 1,2, ..., n
Ordered n-tuple
Cartesian Products
A subset R of the Cartesian product
A x B is called a relation from the set A to the
set B
The elements of R are ordered pairs, where
the first element belongs to A and the second
to B
Ordered n-tuple
Cartesian Products: Example 1
Given A = {1, 2} and B = {a, b, c}
What are A x B and B x A?
AxB=
{(1, a), (1, b), (1, c), (2, a), (2, b), (2, c)}
BxA=
{(a, 1), (a, 2), (b, 1), (b, 2), (c, 1), (c, 2)}
Ordered n-tuple
Cartesian Products
Generally, the Cartesian product of the sets
A1, A2 , ..., An, denoted by A1 x A2 x... x An, is
the set of ordered n-tuples (a1, a2, ..., an),
where ai belongs to Ai for i = 1, 2, ..., n.
A1 x A2 x ... x An =
{(a1, a2, ..., an ) | ai Ai for i = 1,2,...,n}
AxB xC=
{(0,1,0), (0,1,1), (0,1,2),
(0,2,0), (0,2,1), (0,2,2),
(1,1,0), (1,1,1), (1,1,2),
(1,2,0), (1,2,1), (1,2,2)}
Set Combination
Complement
Let U be the universal set
The complement of the set A, denoted by A, is the
complement of A with respect to U
The complement of the set A is U - A.
An element x belongs to A if and only if x A
A = {x I x A}
U
Ch 2.1 & 2.2 36
Set Combination
Union
Let A and B be sets
Union of the sets A and B, denoted by A U B, is the
set that contains those elements that are either in A
or in B, or in both
An element x belongs to the union of the sets A and
B if and only if x belongs to A or x belongs to B
AUB={x|xAxB}
A B
Notation: U (Union)
U
Ch 2.1 & 2.2 37
Set Combination
Intersection
Let A and B be sets
Intersection of the sets A and B, denoted by A ∩ B,
is the set containing those elements in both A and B
An element x belongs to the intersection of the sets
A and B if and only if x belongs to A and B
A∩B={x|xAxB}
Notation: ∩ (i∩teraction) A B
U
Ch 2.1 & 2.2 38
Set Combination
Difference
Let A and B be sets
Difference of A and B, denoted by A - B, is the set
containing those elements that are in A but not in B
The difference of A and B is also called the
complement of B with respect to A
An element x belongs to the difference of A and
B if and only if
x A and x B
A – B = {x | x A x B}
A–B=A∩B
A B
U
Ch 2.1 & 2.2 39
Set Combination
Symmetric Difference
Let A and B be sets
Symmetric Difference of A and B, denoted by A
B, is the set containing those elements is either in A
or B, but not in both
An element x belongs to the symmetric different of
the sets A and B if and only if x belongs to A XOR B
A B = { x | (x A x B)
¬(x A x B) }
A B = (A - B) U (B - A) A B
A B = (A U B) - (B A) U
Ch 2.1 & 2.2 40
Set Combination
Summary
A = {x I x A} A
U
AUB ={x|xAxB} A B
U
A∩ B= {x|xAxB} A B
U
A - B = {x | x A x B} A B
U
A B = { x | (x A x B)
A B
¬(x A x B) } U
A – B = {x | x A x B}
A∩B={x|xAxB}
A–B=A∩B
|AUB|=|A|+|B|-|A∩B|
A B = A B + A B - A B
|AUB UC|
= |A|+|B|+|C| = + +
-|A∩B|
-|B∩C| - - -
-|A∩C|
+
+|A∩B∩C|
Ch 2.1 & 2.2 45
A B
Example:
A = {1,3,5,7,9} and B = {2,4,6,8,10}
A∩B=
A and B are disjoint
Set Identifies
Membership Table
Prove that A ∩ B = A U B
Using membership table
Builder Notation
Prove that A ∩ B = A U B
Using Builder Notation and equivalence rules
A∩B
= { x | x (A ∩ B) }
= { x | ¬((x A) (x B)) }
= { x | ¬(x A) ¬(x B)) }
= { x | (x A) (x B) }
= { x | (x A) (x B) }
=AUB
Set Identifies
Subset
Prove that A ∩ B = A U B
Using subset (implication & equivalence rules)
Show A ∩ B A U B Show A U B A ∩ B
A∩B AUB
Let x (A ∩ B) Let (x A) (x B)
= ¬((x A) (x B)) = (x A) (x B)
= ¬(x A) ¬(x B)) = ¬(x A) ¬(x B))
= (x A) (x B) = ¬((x A) (x B))
= (x A) (x B) = x (A ∩ B)
Therefore, subset of A U B Therefore, subset of A ∩ B
n maybe infinite
Ch 2.1 & 2.2 53
Generalized
Unions and Intersections
Another notation Set of i, e.g. {1..n}
iI
Ai x | i I ( x Ai )
iI
Ai x | i I ( x Ai )
A ∩ B ∩ C = {0}
Generalized
Unions and Intersections
Example 2
Suppose that Ai = {1,2,3,...,i} for i =
1,2,3,…
iI
Ai 1,2,3,..., i 1,2,3,...i
iI
iI
Ai 1,2,3,..., i 1
iI
Methods
First, specify an arbitrary ordering of
the elements of U, for instance a1,
a2, . . . , an a1 a2 a3 a4
Represent a subset A with the bit
string of length n, where the ith bit in
this string is 1010
1 if ai belongs to A
0 if ai does not belong to A
0111
Ch 2.1 & 2.2 58
Computer Representation of Sets
Equal =
Union bitwise OR
Intersection bitwise AND
Complement bitwise NOT
1010
0111 1000
Agenda
Functions
One-to-One Functions
Onto Functions
Increase/Decrease Functions
Inverse Functions
Composition of Functions
Graphs of Functions
Floor and Ceiling Functions
Factorial Functions
Functions
In Mathematic…
f(x) = x2
g(x, y) = x + y
In Programming…
float square (float x) {return x^2}
float sum (float x, float y) {return x+y}
Functions
A function f : A B can also be defined in terms of
a relation from A to B
A relation from A to B is a subset of A x B
By defining using a relation, a function from A to B
contains unique ordered pair (a, b) for every
element a A
AxB
( ,A) ( ,A) ( ,A) ( ,A)
( ,B) ( ,B) ( ,B) ( ,B)
( ,C) ( ,C) ( ,C) ( ,C)
( ,D) ( ,D) ( ,D) ( ,D)
( ,E) ( ,E) ( ,E) ( ,E)
A B
( ,F) ( ,F) ( ,F) ( ,F)
Chapter 2.3 Functions 6
Functions
If f is a function from A to B,
preimage image
A is the domain of f f
B is the codomain of f
a b=f(a)
If f(a) = b, f
b is the image of a
A B
domain codomain
a is a preimage of b
The range of f is the set of all images of elements
of A Range
If f is a function from A to B,
we say that f maps A to B
Domain of G =
{Mickey, Minnie, Donald,
Goofy}
Codomain of G =
{A, B, C, D, E, F}
Range of G = {A, B, F}
Functions: Example 2
Let f be the function that assigns the last two bits of
a bit string of length 2 or greater to that string. What
are the domain, codomain and range?
For example, f (11010) = 10
In/Decrease Functions
Function f whose domain and codomain are
subsets of the set of real numbers is called
Increasing if f(x) ≤ f(y)
Decreasing if f(x) ≥ f(y)
Strictly Increasing if f(x) < f(y)
Strictly Decreasing if f(x) > f(y)
whenever x < y and x and y are in the domain of f
f(x) f(x)
Function Example 3
In/Decrease Functions
A function f is
Increasing if xy (x<y f(x) ≤ f(y))
Decreasing if xy (x<y f(x) ≥ f(y))
Strictly Increasing if xy (x<y f(x) < f(y))
Strictly Decreasing if xy (x<y f(x) > f(y))
where the universe of discourse is the domain of f
Identity Function
Let A be a set. The identity function on A is
the function A : A A, where A(x) = x, for all
x A (Note that is the Greek letter iota)
Assigns each element to itself
Domain = Codomain
y
y = (x) = x
Function Example 5
Function Operation
Let f1 and f2 be functions from A to R
f1 + f2 and f1 f2 are also functions from A to R
defined by
(f1 + f2)(x) = f1(x) + f2(x)
(f1 f2)(x) = f1(x) f2(x)
Functions: Programming
Domain and codomain of functions are often
specified in programming languages
Example,
Pascal : function floor (x: real) : integer
Java : int floor (float x) {...}
C++: int floor (float x) {…}
Domain is the set of real numbers
Codomain is the set of integers
S image of S
( f (S) )
range of f
image of A
Chapter 2.3 Functions 19
Images of Subset
f (S) may be ambiguous:
A set (image of S) ({ f (s) | sS })
Function f for the set S
(input of a function is a set)
We assume f (S) is a set in this course
One-to-One Functions
Function f is said to be one-to-one, or injective,
if and only if f(a) = f(b) implies that a = b
for all a and b in the domain of f
One-to-one functions never assign the same value
to two different domain elements
A A
B B
C C
D D
E E
F F
Not one-to-one One-to-one
Chapter 2.3 Functions
(Many-to-one) 22
One-to-One Functions
By taking the contrapositive of the definition, a
function f is one-to-one if and only if f(a) ≠ f(b)
whenever a ≠ b
We can express that f is one-to-one using
quantifiers as
a b (f(a) = f(b) a = b) or
a b (a ≠ b f(a) ≠ f(b)),
where the universe of discourse is the domain of
the function
One-to-One Functions
Example 1
Determine if the function f(x) = x + 1 from the
set of real numbers to itself is one-to-one
Example 2
Determine whether the function f(x) = x2 from
the set of integers to the set of integers is
one-to-one
Onto Functions
Function f from A to B is called onto, or surjective,
if and only if for every element b B, there is an
element a A with f(a) = b
A function f is onto if y x (f(x) = y), where
Domain for x is the domain of the function
Domain for y is the codomain of the function
A
B
C A
D B
E C
F
Not onto Onto
Chapter 2.3 Functions 26
Onto Functions
Example
Example 1
Is the function f(x) = x2 from the set of integers
to the set of integers onto?
There is no integer x with x2 = -1, therefore, not
onto
Example 2
Is the function f(x) = x + 1 from the set of
integers to the set of integers onto?
Yes
Chapter 2.3 Functions 27
1 bijection
a a a 1
b 2 1 b 2
3 b
c c 2 c 3
d 4 3 d 4
5 d
one-to-one one-to-one one-to-one
onto onto onto
Chapter 2.3 Functions 28
One-to-one and Onto Functions
Example 1
The identity function on A is the function A :
A A, where A(x) = x, for all x A
Assigns each element to itself
One-to-one?
Onto?
So it is a bijection
y
y = (x) = x
f(x) f(x)
Example 3
a 1 a 1
b 2 b 2
c 3 3
d 4 c 4
Not one-to-one Not a function
Not onto
f
Inverse Functions
f -1
Recall, the definition of a function domain
codomain
Let A and B be nonempty sets
Function f from A to B is an assignment of
exactly one element of B to each element of A
Every element (a) in domain (A) has only one image ( f (a))
Inverse function f -1 (reverse processing)
f -1 : B A
Every element (b) in domain (B) has only one image
( f -1 )
a 1 a 1 a 1 a 1
2 b b 2 b 2
b c 2 c 3
3 3 c
c 4 d 3 d 4 d 4
One-to-one Not one-to-one One-to-one Not one-to-one
Not onto Onto Onto Not onto
Inverse Functions
If a function f is not a one-to-one correspondence,
an inverse function of f cannot be defined
f is not one-to-one a 1
Some b in the codomain is the image of b 2
c
more than one element a d 3
f is not onto a 1
Some b in the codomain is the image of b 2
no element a 3
c 4
Inverse Functions
Example 1
Let f be the function from R to R with
f(x) = x2 . Is f invertible?
Example 2
Show that if we restrict the function f(x) = x2 to a function
from the set of all nonnegative real numbers to the set of all
nonnegative real numbers, then f is invertible
Composition of Function
Let
g be a function from the set A to the set B
f be a function from the set B to the set C
The composition of the functions f and g, denoted
by f ο g, is defined by
(f ο g)(a) = f( g(a) )
g f
A B C
(f ο g)
(f ο g)(a)
g(a) f(g(a))
a g(a) f(g(a))
g f
A B C
(f ο g)
Chapter 2.3 Functions 39
Composition of Function
Example
Let f and g be the functions from the set of integers
to the set of integers defined by f(x) = 2x + 3 and
g(x) = 3x + 2
What is the composition of f and g?
What is the composition of g and f?
Composition of Function
Let f is a one-to-one correspondence between A
and B, then
f -1 o f = A and f o f -1 = B
where A & B are identity functions on sets A & B
respectively
Such that:
(f-1 o f )(a) = f -1 ( f(a) ) = f-1( b ) = a
(f o f -1)(b) = f ( f -1(b) ) = f ( a ) = b
Graphs of Functions
Example 1
Display the graph of the function
f(n) = 2n + 1 from the set of integers to the
set of integers
The graph of f is the set of f (n)
ordered pairs of the form
(1, 3)
(n, f(n)) = (n, 2n + 1),
where n is an integer (0, 1)
n
Example 2
Display the graph of the function f(x) = x2
from the set of integers to the set of integers
The graph of f is the set
of ordered pairs of the
form (x, x2), where x is
an integer
Graphs of Functions
Example 3
Display the graph of the function f(x) = x2
from the set of real to the set of real
Example 4
The graph of the floor The graph of the ceiling
function x function x
x x
[n, n + 1) (n, n + 1]
Chapter 5: Relation
5.1
Relations and
Their Properties
5.2
n-ary Relations and
Their Applications
5.3
Representing Relations
Yan Huang
School of Computer Science and Engineering
South China University of Technology
Agenda
What is Relation?
Representation of Relation
Graph
Matrix
Operators of Relation
Properties of Relation
What is Relation?
Relation: x likes y
Relation
R is defined as
A binary relation from A to B
Ordered pairs, which
First element comes from A
Second element comes from B
aRb: (a, b) R
aRb: (a, b) R
Moreover, when (a, b) belongs to R,
a is said to be related to b by R
Given
Peter takes C++ Peter R C++ Peter R DisMath
Paul takes DisMath Paul R C++ Paul R DisMath
Mary takes none of them Mary R C++ Mary R DisMath
Relation VS Function
Function Relation
from a set A to a set B from a set A to a set B
All elements of A are Some elements of A
assigned to B are assigned to B
Exactly one element of Zero, One or more
B to each element of A elements of B to an
element of A
Function is a special case of Relation
a 1 a 1 a 1
b 2 b 2 2
c 3 c 3 b 3
d 4 d 4 c 4
Function Not a Function Not a Function
Relation Relation Relation
Ch 5.1, 5.2, 5.3 8
Relation Representation
Graph
Relations can be represented by Directed Graph
You will learn the directed graph in detail in
<Discrete Math Part 2>
a d
Graph G = (V, E) consists of Edge
a set of vertices V
Vertex
a set of edges E,
a connection between a pair of b c
vertices
V = { a, b, c, d}
E = { (a,b), (b,c), (b,d), (c,d) }
Relation Representation
Graph
a d a d
b c b c
Graph
G to present a relation from A to B is
vertices V A U B a 1
b 2
edges E A × B c 3
d 4
For example
If there is an ordered pair (x, y) in R,
then there is an edge from x to y in D
x y
Relation Representation
Graph: Example
Peter R C++, Peter R DisMath
Paul R C++, Paul R DisMath
Mary R C++, Mary R DisMath
Peter
C++
Paul
DisMath
Mary
Directed Graph
Matrix
Let R be a relation from A = {a1, a2, . . . , am} to B =
{b1, b2, . . . , bn}
An mn connection matrix M for R is defined by
1 if (ai, bj) R
mij = b1 b2 b3 b4
0 if (ai, bj) R
a1 0 0 0 0
a2 1 0 0 0
a3 0 1 1 0
a4 1 0 0 0
a5 0 0 1 1
Relation Representation
Matrix: Example
Peter R C++, Peter R DisMath
Paul R C++, Paul R DisMath
Mary R C++, Mary R DisMath
Peter
C++ 1 0
Paul 0 1
DisMath 0 0
Mary
Directed Graph Matrix
Example:
A = {1, 2, 3, 4}
R = {(1,1), (1,4), (2,1), (2,3), (2,4), (3,1), (4,1),
(4,2)}
Example 1
Let A be the set {1, 2, 3, 4}, which ordered pairs are
in the relation R = {(a, b) | a divides b}?
1 2
1 1 1 1
0 1 0 1
0 0 1 0
0 0 0 1
3 4
Example 2
How many different relations are there on a set
with n elements?
Relation Properties
Reflexive
a ( (a, a) R )
Irreflexive
a ( (a A) ((a, a) R) )
Transitive
abc ( ((a,b)R(b,c)R) ((a,c)R))
Relation Properties
Symmetric
a b ( ((a, b)R) ((b, a)R) )
Asymmetric ( (a,a) cannot be an element in R )
a b ( ((a, b)R) ((b, a)R) )
Antisymmetric ( (a,a) may be an element in R )
a b ( ((a, b)R (b, a)R) (a = b) )
Irreflexive
a ( (a A) ((a, a) R) )
No node links to itself
Transitive
abc ( ((a,b)R(b,c)R) ((a,c)R))
Every two adjacent forms a triangle
(Not easy to observe in Graph)
Ch 5.1, 5.2, 5.3 20
Relation on One Set
Asymmetric
a b ( ((a, b)R) ((b, a)R) )
No link is bidirectional (Antisymmetric)
No node links to itself (Irreflexive)
Antisymmetric
a b ( ((a, b)R (b, a)R) (a = b) )
No link is bidirectional
0
0
? Irreflexive
a ( (a A) ((a, a) R) )
0
? 0
All 0’s on diagonal
Transitive
abc ( ((a,b)R(b,c)R) ((a,c)R))
Not easy to observe in Matrix
0 0 Asymmetric
0
1 0 a b ( ((a, b)R) ((b, a)R) )
0 0 All 1’s are across from 0’s (Antisymmetric)
0 1 0 All 0’s on diagonal (Irreflexive)
0 Antisymmetric
0
1 a b ( ((a, b)R (b, a)R) (a = b) )
0 All 1’s are across from 0’s
0 1
Ch 5.1, 5.2, 5.3 23
Example 1
Consider the following relations on {1, 2, 3, 4},
Which properties these relations have?
R1 = {(1,1), (1,2), (2,1), (2,2), (3,4), (4,1), (4,4)}
Reflexive Irreflexive Transitive Symmetric Asymmetric Antisymmetric
R6 = {(3,4)}
Reflexive Irreflexive Transitive Symmetric Asymmetric Antisymmetric
Example 2
Reflexive Reflexive
Irreflexive Irreflexive
Transitive Transitive
Symmetric Symmetric
Asymmetric Asymmetric
Antisymmetric Antisymmetric
Reflexive Reflexive
Irreflexive Irreflexive
Transitive Transitive
Symmetric Symmetric
Asymmetric Asymmetric
Antisymmetric Antisymmetric
Example 3
Let A = Z+, R = { (a,b) A A | a divides b }
Is R symmetric, asymmetric, or antisymmetric?
Combining Relations
Example
Given, A = {1,2,3}, B = {1,2,3,4}
R1 = {(1,1),(2,2),(3,3)},
R2 = {(1,1),(1,2),(1,3),(1,4)}
R1 U R2 = {(1,1),(1,2),(1,3),(1,4),(2,2),(3,3)}
R1 ∩ R2 = {(1,1)}
R1 - R2 = {(2,2),(3,3)}
R2 - R1 = {(1,2),(1,3),(1,4)}
R1 R2 = {(1,2),(1,3),(1,4),(2,2),(3,3)}
Ch 5.1, 5.2, 5.3 28
Combining Relations
Let R be relation from a set A to a set B
Inverse Relation (R-1) = {(b,a) | (a,b) R}
Complementary Relation (R) = {(a,b) | (a,b) R}
Example
X = {a, b, c} Y={1, 2}
R = {(a, 1), (b, 2), (c, 1)}
Combining Relations
Theorems
Let R1 and R2 be relations from A to B. Then
(R-1)-1 = R
(R1 U R2)-1 = R1-1 U R2-1
(R1 ∩ R2)-1 = R1-1 ∩ R2-1
(A B)-1 = B A
-1 =
( R )-1 = (R-1)
(R1 - R2)-1 = R1-1 - R2-1
If R1 R2 then R1-1 R2-1
Combining Relations
Example 1
Given
R1 is symmetric
R2 is antisymmetric
Does it R1 U R2 is transitive?
Example 2
Given R1 and R2 are transitive on A
Does R1 U R2 is transitive?
1 0 1
1 0 1
M R1 R2 M R1 M R2 1 1 1
M R1 1 0 0
0 1 0 1 1 0
1 0 1 1 0 1
M R2 0 1 1 M R1 R2 M R1 M R2 0 0 0
1 0 0 0 0 0
Combining Relations
Composite
Recall, the composition in functions…
Let
g be a function from the set A to the set B
f be a function from the set B to the set C
The composition of the functions f and g, denoted
by f ο g, is defined by (f ο g)(a) = f( g(a) )
(f ο g)(a)
g(a) f(g(a))
a g(a) f(g(a))
g f
A B C
(f ο g)
Ch 5.1, 5.2, 5.3 36
Combining Relations
Composite
Let
R be a relation from a set A to a set B
S be a relation from a set B to a set C
The composite of R and S is the relation consisting
of ordered pairs (a, c), where
a A, c C, and
There exists an element b B, such that (a, b) R
and (b, c) S
The composite of R and S is denoted by S o R
Combining Relations
Composite
Suppose
R be a relation from a set A to a set B
S be a relation from a set B to a set C
(x, y) S o R implies z ( (x, z)R (z, y)S)
(x, y) S o R
(x,z)R (z,y)S
x z y
R S
A B C
(S ο R)
Remark: May be more than one element z,
where (x, z)R and (z, y)S
Ch 5.1, 5.2, 5.3 38
Combining Relations
Composite: Example
What is the composite of the relations R and S,
where
R is the relation from {1,2,3} to {1,2,3,4} with
R = {(1,1),(1,4),(2,3),(3,1),(3,4)}
S is the relation from {1,2,3,4} to {0,1,2} with
S = {(1,0),(1,2),(2,0),(3,1),(3,2),(4,1)}?
S o R = { (1,0),(1,2),(1,1),(2,1),(2,2),(3,0),(3,2),(3,1)}
1
1 0 1 0
2
2 1 2 1
3
3 2 3 2
4
Ch 5.1, 5.2, 5.3 39
Combining Relations
Composite: Properties
Let R1 and R2 be relations on the set A.
Show (R1 o R2)-1 = R2-1 o R1-1
Proof:
Let (x, y) (R1 o R2)-1
(x, y) S o R implies
(x, y) (R1 o R2)-1
z ( (x, z)R (z, y)S)
(y, x) R1 o R2
z ( (y, z)R2 (z, x)R1)
z ( (z, y)R2-1 (x, z)R1-1 )
(x, y) R2-1 o R1-1
Ch 5.1, 5.2, 5.3 40
Combining Relations
Composite: Properties
Let F,G and H be relations on the set A, then
F o (G U H) = (F o G) U (F o H)
F o (G ∩ H) (F o G) ∩ (F o H)
(G U H) o F = (G o F) U (H o F)
(G ∩ H) o F (G o F) ∩ (H o F)
Composite
Let R be a relation on the set A. The powers
Rn , n = 1, 2, 3, ..., are defined recursively by
R1 = R
R2 = R o R
R3 = R2 o R = (R o R) o R
...
Rn+1 = Rn o R
Composite: Example
R R
1 1 1
2 2 2
Let R = {(1,1), (2,1), (3,2), (4,3)} 3 3 3
4 4 4
Find the powers Rn, n = 2,3,4,…
R R2
1 1 1
2 2 2
3 3 3
4 4 4
R2 = R o R = {(1,1),(2,1),(3,1),(4,2)}
R R3
R3 = R2 o R = {(1,1),(2,1),(3,1),(4,1)} 1
2
1
2
1
2
R4 = R3 o R = {(1,1),(2,1),(3,1),(4,1)} 3
4
3
4
3
4
Rn = R3 for n = 5, 6, 7, ….
Ch 5.1, 5.2, 5.3 43
Composite: Matrix
Suppose
R1 be relation from set A to set B represented by MR1
R2 be relation from set B to set C represented by MR2
The matrix for the composite of R1 and R2 is:
MR 2 o R1
Composite: Matrix
n : the number of row of R1
Define: the number of column of R2
MR 2 o R1 = MR 2
MR 1
n
where ( M R2 M R1 )ij [( M R1 )ik ( M R2 ) kj ]
k 1
An element in the matrix
Composite: Matrix
The powers Rn can defined using matrix as:
M R n M R
n
Example 0 1 0
Find the matrix representing M R 0 1 1
the relation R2 1 0 0
0 1 0 0 1 0 0 1 1
M R 2 M R 2 0 1 1 1 1 1
0 1 1
1 0 0 1 0 0 0 1 0
Ch 5.1, 5.2, 5.3 47
Composite: Property 1
Theorem
If R S, then S o R S o S
It implies:
If R S and T U, then R o T S o U
Composite: Property 2
An ordered pairs (x, y) is in Rn iff there is a path of
length n from x to y in R
1 2 1 2 1 2 1 2
3 4 3 4 3 4 3 4
Composite: Property 2
An ordered pairs (x, y) is in Rn iff there is a path of
length n from x to y in R
1 2 1 2 1 2 1 2
3 4 3 4 3 4 3 4
R R2 R3 R4
Example
In R, 1 > 2 > 4, length = 2 (1,4) R2
In R, 3 > 2 > 4 > 3, length = 3 (3,3) R3
(1,2) R4 In R, 1 > 2 > 4 > 3 > 2, length = 4
Ch 5.1, 5.2, 5.3 50
Combining Relations: Relation on One Set
Composite: Property 2
Theorem
Let R be a relation on A. There is a path of
length n from a to b in R iff (a, b) Rn
Composite: Property 2
Proof by Induction a path of length n from a to
b iff (a, b) Rn
Show n=1 is true
An arc from a to b is a path of length 1, which is in R1 = R
Hence the assertion is true for n = 1
Assume it is true for k. Show it is true for k+1
As it is true for n = 1,
suppose (a, x) is a path of length 1, then (a, x) R
As it is true for n = k,
suppose (x, b) is a path of length k, then (x, b) Rk
Considering, (a, x) R and (x, b) Rk,
(a, b) Rk+1 = Rk o R as there exists an element x, such
that (a, x) R and (x, b) Rk
The length of (a,b) is k+1
Composite: Property 3
R is transitive iff Rn R for n > 0.
Proof
1. (Rn R) R is transitive
Suppose (a,b) R and (b,c) R
(a,c) is an element of R2 as R2 = R o R
As R2 R , (a,c) R
Hence R is transitive
Composite: Property 3
2. R is transitive (Rn R)
Use a proof by induction:
Basis: Obviously true for n = 1.
Induction: Assume true for n, show it is
true for n + 1
For any (x, y) is in Rn+1, there is a z such that
(x, z) R and (z, y) Rn
But since Rn R, (z, y) R
As R is transitive, (x, z) and (z, y) are in R,
so (x, y) is in R
Therefore, Rn+1 R
Composite: Property 4
Proof: If R is transitive, Rn is also transitive
When n = 1, R is transitive
Assume Rk is transitive
Show Rk+1 is transitive
Given (a,b) Rk+1 and (b,c) Rk+1, show (a,c)
Rk+1
Rk+1 = Rk o R
As (a,b) Rk+1, (d,b) Rk and (a,d) R
As (b,c) Rk+1, (f,c) Rk and (b,f) R
As (a,c) Rk+1, (?,c) Rk and (a,?) R
Composite: Property 4
Given (a,b) Rk+1 and (b,c) Rk+1, show (a,c) Rk+1
Rk+1 = Rk o R
As (a,b) Rk+1, (d,b) Rk and (a,d) R
As (b,c) Rk+1, (f,c) Rk and (b,f) R
As (a,c) Rk+1, (?,c) Rk and (a,?) R
As “R is transitive iff Rn R for n > 0”
(d,b) Rk R
As R is transitive, (d,b) R and (b,f) R imply (d,f) R
As R is transitive, (d,f) R and (a,d) R imply (a,f) R
Therefore, by considering, (f,c) Rk and (a,f) R, (a,c)
Rk+1
Composite: Property 4
Proof: If R is transitive, Rn is also transitive
When n = 1, R is transitive
Assume Rk is transitive
Show Rk+1 is transitive
Given (a,b) Rk+1 and (b,c) Rk+1, show (a,c)
Rk+1
Rk+1 = Rk o R
As (a,b) Rk+1, (a,d) Rk and (d,b) R
As (b,c) Rk+1, (b,f) Rk and (f,c) R
As (a,c) Rk+1, (a,?) Rk and (?,c) R
Composite: Property 4
Given (a,b) Rk+1 and (b,c) Rk+1, show (a,c) Rk+1
Rk+1 = Rk o R
As (a,b) Rk+1, (a,d) Rk and (d,b) R
As (b,c) Rk+1, (b,f) Rk and (f,c) R
As (a,c) Rk+1, (a,?) Rk and (?,c) R
As “R is transitive iff Rn R for n > 0”
(b,f) Rk R
As R is transitive, (d,b) R and (b,f) R imply (d,f) R
As R is transitive, (d,f) R and (f,c) R imply (d,c) R
Therefore, by considering, (a,d) Rk and (d,c) R, (a,c)
Rk+1
Chapter 5: Relation
5.4
Closures of Relations
5.5
Equivalence Relations
Yan Huang
School of Computer Science and Engineering
South China University of Technology
Agenda
5.4 Closures of Relations
Reflexive Closure
Symmetric Closure
Transitive Closure
5.5 Equivalence Relations
Equivalence Relations
Equivalence Class
Partition
3 4
Closure
Let R be a relation on a set A
S is called the closure of R with respect to
property P if
S with property P
S is a subset of every relation with property P
containing R
Minimum terms are added to R to fulfill the
requirements of property P
Symmetric Closure
a b ( ((a, b)R) ((b, a)R) )
Transitive Closure
abc ( ((a,b)R(b,c)R) ((a,c)R))
Closure
Reflexive Closure: Example
R = {(1,1), (1,2), (2,1), (3,2)}
on the set A = {1, 2, 3}
R is not reflexive
1 2 How can we produce a
reflexive relation containing
R that is as small as possible?
Add (2,2) and (3,3)
R’ = {(1,1), (1,2), (2,1), (3,2),
3 (2,2), (3,3)}
R’ is reflexive closure of R
Any reflexive relation that
contains R must contain R’
Closure
Symmetric Closure: Example
R = {(1,2), (1,2), (2,2), (2,3),
(3,1), (3,2)} on {1, 2, 3}
R is not symmetric
1 2 How can we produce a
symmetric relation containing R
that is as small as possible?
Add (2,1) and (1,3)
R’ = {(1,2), (1,2), (2,2), (2,3),
(3,1), (3,2), (2,1), (1,3)}
3
R’ is symmetric closure of R
Any symmetric relation that
contains R must contain R’
Closure
Transitive Closure: Example
R = {(1,2), (1,3), (2,3), (3,4)}
on {1,2,3,4}
R is not transitive
1 2
How can we produce a
transitive relation containing
R that is as small as possible?
Add (1,4), (2,4)
3
R’ = {(1,2), (1,3), (2,3), (3,4),
(1,4), (2,4)}
R’ is transitive closure of R
4 Any transitive relation that
contains R must also contain R’
Mathematical View d f
Transitive Closure of R is R*
Ch 5.4 & 5.5 11
Closure
Transitive Closure
The connectivity relation of the relation R,
denoted R*, is the union of Ri, where i =
1,2,3,…
R* R n
n 1
Transitive Closure of R is R*
Closure
Transitive Closure
Proof: Transitive Closure of R is R*
1. R* is a transitive relation
2. R* contains R
3. R* is the smallest transitive relation which
contains R
Transitive Closure n 1
Closure
R Rn
*
Transitive Closure n 1
It is true for n, Rn Sn
Therefore Rn Sn S for all n
Hence S must contain R* since it must also contain the
union of all the powers of R
n 1
Closure
Transitive Closure
A path of length n in a digraph G is a
sequence of edges (x0, x1),(x1, x2),...,(xn-1, xn)
d f
Proof
Suppose there is a path from a to b in R
Let m be the length of the shortest path, which is x0, x1,
x2, ..., xm-1, xm, where x0 = a and xm = b
Assume m > n
Because n vertices in A and there are m vertices in the
path, at least two vertices in the path are equal
Suppose that xi = xj with 0 ≤ i < j ≤ m
There is a path contained a cycle from xi to itself (xj)
This cycle can be removed to shorten the path
Hence, the shortest length must be less than or equal
to n
xi+2 …x j-2
xi+1 xj-1
… …
x0 x1 x2 xi-1 xi xi+1
j+1 xm
a xj b
Ch 5.4 & 5.5 20
Closure
Transitive Closure
From the Theorem, we know that Rk for k > n
does not contain any edge that does not
already appear in the first n powers of R
k 1 k 1
Closure
Transitive Closure
Theorem
Let MR be the zero-one matrix of the relation
R on a set with n elements. Then the zero-
one matrix of the transitive closure R* is
M R* M R[1] M R[ 2 ] M R[ 3] M R[ n ]
Remark : M R k M R[ k ]
M R M R[1]
Ch 5.4 & 5.5 22
Closure
Transitive Closure: Example
Find the zero-one matrix of the transitive
closure of the relation R where
1 0 1 1 1 1 1 1 1
M R 0 1 0 M R[ 2] 0 1 0 M R[3] 0 1 0
1 1 0 1 1 1 1 1 1
M R* M R M R[ 2 ] M R[3]
1 0 1 1 1 1 1 1 1 1 1 1
M R* 0 1 0 0 1 0 0 1 0 0 1 0
1 1 0 1 1 1 1 1 1 1 1 1
Ch 5.4 & 5.5 23
Algorithm
W0 = MR
For k = 1 … n
Update each element in Wk by using:
a b
Let v1=a, v2=b, v3=c, v4=d.
W0 is the matrix of the relation.
Hence,
0 0 0 1
1 0 1 0
d c W0
1 0 0 1
0 0 1 0
Closure: Theorem
Let R be binary relation on a nonempty set A
If R is reflexive, r(R) = R
If R is symmetric, s(R) = R
If R is transitive, t(R) = R
Closure: Theorem
Suppose R is transitive, is s(R) transitive?
Let R= {(1,2),(3,2)}
R is transitive
s(R) = {(1,2), (2,1), (3,2), (2,3)}
s(R) is not transitive
r( s(R) ) = s( r(R) )?
r( t(R) ) = t( r(R) )?
s( t(R) ) = t( s(R) )?
Closure: Theorem
Proof r( s(R) ) = s( r(R) )
= (R U D) U (R U D)-1
= (R U D) U (R-1 U D-1)
= (R U R-1) U (D U D-1)
= s(R) U D
= r( s(R) )
Example:
t(R1 - R2) = t(R1) - t(R2) ?
r(R-1) = ( r(R) )-1 ?
Equivalence
What is Equivalence?
Equivalence Relations
Definition
A relation R on a set A is an equivalence
relation iff R is reflexive, symmetric and
transitive
a b a b
d c d c
Equivalence Relation
Ch 5.4 & 5.5 38
Equivalence Relations
Example 1
Suppose that R is the relation on the set of strings of English
letters such that aRb iff g(a)=g(b), where g(x) is the length
of the string x.
Is R an equivalence relation?
Reflexive
Since g(a)=g(a), it follows that aRa whenever a is a string
Symmetric
Let aRb, so g(a)=g(b), bRa. Therefore, g(b)=g(a)
Transitive
Let aRb and bRc, then g(a)=g(b) and g(b)=g(c), so aRc
Consequently, R is an equivalent relation
Equivalence Relations
b=x·m+a
Example 2 where x is an integer
x = (b-a) / m
Definition of Congruence
a ≡ b (mod m)
a is congruent to b modulo m if m divides a-b
Equivalence Relations
Example 3
Show that the "divides" relation on the set of
positive integers is not an equivalence relation.
Equivalence: Examples
R is the relation on the set of strings of
English letters, where aRb iff g(a)=g(b) and
g(x) is the length of the string x
“Peter” ~ “Susan”
“Ann” ~ “May”
Equivalence Classes
The equivalence class of a with respect to R
is denoted by [a]R
[a]R = {s | (a,s) R}
If b [a]R, b is called a representative of this
equivalence class
[d] = {d}
Equivalence Classes
[a]R = {s | (a,s) R}
Example 2
R = { (a,b) | a ≡ b (mod m) } is an equivalence
relation on the set of integers, where m be a
positive integer greater than 1
Let m = 5
R = { (a,b) | a ≡ b (mod 5) }
[0] = { …, -10, -5, 0, 5, 10, … }
[1] = { …, -9, -4, 1, 6, 11, … }
[a] = { …, a-10, a-5, a, a+5, a+10, … }
General Case, for any m,
[a] = { …, a-2m, a-m, a, a+m, a+2m, … }
For any a,
[a] = the set of all strings of the same length as
a
Equivalence Classes
Theorem
Let R be an equivalence relation on a
nonempty set A. The following statements
are equivalent:
1. aRb
2. [a] = [b]
3. [a] ∩ [b]
Equivalence Classes
1. aRb
Theorem: Proof 2. [a] = [b]
Show that (3) implies (1) 3. [a] ∩ [b]
Suppose that [a] ∩ [b]
Then there is an element c[a] and c[b]
In other words, aRc and bRc
By the symmetric property, cRb
Then by transitive, since aRc and cRb, we have aRb.
1 1 1 1 1
2 3 2 3 2 3 2 3 2 3
{{1,2,3}} {{1}, {2,3}} {{2}, {1,3}} {{3}, {1,2}} {{1}, {2}, {3}}
t(s(r(R)))
d c
d c
Ch 5.4 & 5.5 60
Equivalence Classes & Partitions
Theorem 3: Proof
Proof: tsr(R) is an equivalence relation
Reflexive
When constructing r(R), a loop is added at every
element in A, therefore, tsr(R) must be reflexive
Symmetric
If there is an edge (x, y) then the symmetric
closure of r(R) ensures there is an edge (y, x)
Chapter 5: Relation
5.6
Partial Orderings
Yan Huang
School of Computer Science and Engineering
South China University of Technology
Agenda
Partial Order
Total Order
Lexicographic Order
Hasse Diagrams
Minimal/Maximal Element
Least/Greatest Element
Lower/Upper Bound
Greatest Lower/Least Upper Bound
What is Order?
Equivalence (=) concept is discussed
The abstraction of the following relations
will be discussed in this chapter
Bigger or Equal / Smaller or Equal (≤, ≥)
Bigger / Smaller (<, >)
c d c d c d
Not Partial Order Partial Order Partial Order
Chapter 5.6 Partial Orderings 6
Partially Ordered Set
When R is a partial order in A, (A, R) is called
a partially ordered set or a poset
Recall, aRb denotes that (a,b) R
If R is a partial ordering relation
a b denotes that (a,b)
(A, ) is a poset
Reflexive
a ≥ a for every integer a
Antisymmetric
If a ≥ b and b ≥ a, then a = b
Transitive
a ≥ b and b ≥ c imply that a ≥ c
(Z, ≥) is a poset
Comparability
The elements a and b of a poset(S, ) are
called comparable if either a b or b a
Otherwise, a and b are imcomparable
Example
In the poset (Z+, | ),
Are 3 and 9 comparable? Yes, since 3 | 9
Are 5 and 7 comparable? No
Total Ordered
If (S, R) is a poset and every two elements
are comparable, S is called a total ordered or
linear ordered or simple ordered set
In this case (S, R) is called a chain
a b a b a b
c d c d c d
Not Partial Order Partial Order Partial Order
Not Total Order Not Total Order Total Order
Lexicographic Order
What is the order of a letter? A C?
Alphabetical order C A?
Lexicographic Order
General Case: Example
Let A1 = A2 = … = An = Z+ and R1 = R2 = … = Ri = 'divides'
If the following relation is Lexicographic Order R?
i=1 2 1 2? 2 1 3?
If a1 1 b1, or
if there is an integer i>0 such that
a1 = b1, …, ai = bi and ai+1 i+1 bi+1
Chapter 5.6 Partial Orderings 18
Lexicographic Order
String
Lexicographic order is applied to strings of symbols
where there is an underlying 'alphabetical' order
If a1 1 b1, or
Lexicographic Order (a1,a2,…,at) = (b1,b2,…,bt) and m<n
if there is an integer i>0 such that or
String: Example 1
a1 = b1, …, ai = bi and ai+1 i+1 bi+1 (a1,a2,…,at) ≤ (b1,b2,…,bt)
t=8
“fiscrete” length = 8
alphabetical order: d < f
“discreteen” length = 12
discreteen fiscrete
It is Hasse Diagram
Hasse Diagrams
Show the partial ordering using a graph
For example {(a, b) I a ≤ b} on the set {1, 2, 3, 4}
4 4 4 4
3 3 3 3
2 2 2 2
1 1 1 1
The graph is too complicated and try to simplify it:
A partial ordering must be reflexive:
the loops are not necessary
A partial ordering must be transitive:
some edges can be removed
By assuming all edges are pointed upward,
the direction of edges is not necessary
Chapter 5.6 Partial Orderings 22
Hasse Diagrams
To construct a Hasse diagram:
1. Construct a digraph representation of the
poset (A, R) so that all arcs point up (except
the loops).
2. Eliminate all loops
3. Eliminate all redundant arcs
Start to eliminate from the top
4. Eliminate the direction of the edge
Hasse Diagrams
8 12
Example 1
4 6
Draw the Hasse diagram
representing the partial 2 3
ordering { (a,b) | a divides b }
on A={1,2,3,4,6,8,12} 1
8 12 8 12 8 12
4 6 4 6 4 6
2 3 2 3 2 3
1 1 1
Chapter 5.6 Partial Orderings 24
Small Exercise {a,b,c}
{} {}
Chapter 5.6 Partial Orderings 25
Covering Relation
Let (S, ) be a poset. (x,y) such that y cover
x is called the covering relation of (S, )
if x y and there is no element z S such
that x z y {a,b,c}
({a}, {a,b})?
({ }, {a,b})? { } {a} {a,b} or { } {b} {a,b}
({a}, {a})? {a} = {a}
Chapter 5.6 Partial Orderings 26
Minimal & Maximal Elements
Let (A, R) be a poset and S A.
s (b) in S is a minimal element (maximal
element) of S iff there does not exist an
element x in S such that xRs ( bRx )
b
maximal minimal
element element
{ a, b, c} b c a d
{ a, b, c, d, e} b c, e
c e
Well Ordered
A chain (A, R) is well-ordered iff every
nonempty subset of A has a least element
Examples:
(Z, ) is a chain but not well-ordered
Z does not have least element
(N, ) is well-ordered
(N, ) is not well-ordered
b
Upper Lower
Bound Bound
{a, d} b c a d
{c, d, e} d, b /
c e
Lattice
A partially ordered set in which every pair of
elements has both a least upper bound and a
greatest lower bound is called a lattice
Lower Bound: b, c, a
No Greatest Lower Bound
f f No Upper h
Bound
e d e
d e e f g
c
b
d
b
c
b
c b c d
a a a
a
Upper Bound: d, e, f
No Least Upper Bound
4 5 4 3 5 4 3 5
2 3 2 2
1 1 1
Lattice: Theorem
Theorem: If L is a lattice, least upper bound and
greatest lower bound of a and b can be defined as
a b and a b, respectively. and satisfy the
following properties for a,b,c L.
1. Commutative laws
a b = b a and a b = b a
2. Associative laws
a (b c) = (a b) c and a (b c) = (a b) c
3. Idempotent laws
a a = a and a a = a
4. Absorption laws
a (a b) = a and a (a b) = a
• Be noted that and does not necessary to be OR and AND.
They can be any binary operation which fulfill the following properties
Chapter 5.6 Partial Orderings 36
Lattice: Theorem: Example 1
Given (P({x,y}), )
Is it a partial order? 1. Reflexive
2. Antisymmetric
3. Transitive lub: a b
Is it a lattice? glb: a b
What should be or ? 1. Commutative laws
a b = b a and a b = b a
2. Associative laws
a (b c) = (a b) c and
a (b c) = (a b) c
3. Idempotent laws
{a,b} {} a a = a and a a = a
4. Absorption laws
a (a b) = a and a (a b) = a
{a} {b} {a} {b}
{} {a,b}
Chapter 5.6 Partial Orderings 37
glb: a b {}
Example, b (e c) = b d = b
(b e) (b c) = a a = a
Are they distributive?
d
d
b e c
b c
a
a
Bounded Lattice
A lattice (L, ) is called bounded lattice if
there exist elements α, β L such that for
each x L, x α and β x.
α is the largest element of L (denoted by 1)
β is the smallest element of L (denoted by 0)
If a lattice is bounded, then
1 is the lub of the lattice
0 is the glb of the lattice
Complemented Lattice
lub: a b
Example glb: a b
y is ¬x if x y = 1 and x y = 0
x ¬x x ¬x
1
1
0 1 0 1
c d
c
d
e
1 0 1 0
a b a b
a b,e a b,d
0
0 b a,c b a,c
c b Complemented c b,d
Not
Lattice
Complemented d NO d a,c
Lattice
e a
Chapter 5.6 Partial Orderings 42
Lattice: Principle of Duality
Any statement that is true for lattice remains
true when is replaced by and and
are interchanged throughout the statement.
Example of dual
{a,b} {}
{} {a,b}
Chapter 3: Counting
3.1
The Basics of Counting
3.2
The Pigeonhole Principle
3.3
Permutations & Combinations
3.5
Generalized Permutations &
Combinations
3.6
Generating Permutations &
Combinations
Yan Huang
School of Computer Science and Engineering
South China University of Technology
Agenda
Basic Counting Principles
Multiplication / Addition Principle
Inclusion-Exclusion Principle
Permutation / Combination
Distributing Objects into Boxes
Generating Permutations & Combinations
Why Counting?
Counting problems arise throughout
mathematics and computer science
For example
the number of experiment outcomes
the number of operations in an algorithm
(time complexity)
Example 1
In 1999, a virus named “Melissa” is
created by David L. Smith based on a
Microsoft Word macro
Melissa sends an email "Here is that
document you asked for, don't show it
to anybody else." to the top 50 people
in the address book
Example 2
A programming language Beginner's All-
purpose Symbolic Instruction Code (BASIC)
GW-BASIC (1986) in MS-DOS
Example 2
In BASIC, the requirements of a variable name
A string of 1 or 2 alphanumeric characters
(a-z or 0-9)
Begin with a letter
Uppercase and lowercase letters are not
distinguished
Different from the 5 strings of two characters that
are reserved
How many different variable names are there
in this version of BASIC?
Chapter 3.1, 3.3, 3.5, 3.6 10
Basic Counting
A string of 1 or 2Principles: Multiplication/Addition
alphanumeric Principle
characters (number & letter)
Example 2
Begin with a letter
Uppercase and lowercase letters are not distinguished
Different from the 5 strings of two characters that are reserved
Inclusion-Exclusion Principle
Suppose that a task can be done in A or in B ways
But some of the set of A ways to do the task are the
same as some of the B ways to do the task
overcount
A B A B
|AUB|=|A|+|B|-|A∩B|
Chapter 3.1, 3.3, 3.5, 3.6 12
Basic Counting Principles: Inclusion-Exclusion Principle
Example 1
How many bit strings of length 8, either start with a 1 bit
or end with the two bits 00?
Permutation
A permutation of a set of distinct
n objects is an ordered arrangement
of these objects
1st 2nd
… rth
… nth
General Case
The ordering of r elements selected from n distinct
elements is called r-permutation
n!
n Pr P ( n, r ) n( n 1)( n 2)...( n r 1)
( n r )!
Chapter 3.1, 3.3, 3.5, 3.6 15
Combination
The unordered selection of r elements from n
distinct elements is called r-combination
It is a subset of the set with r elements
n n!
C
n r C ( n, r )
r r!(n r )!
Combination
C(n, r) = C(n, n - r)
Algebraic Proof
n!
C (n, r )
r!(n r )!
n!
(n (n r ))!( n r )!
C ( n, n r )
Combination
Combinatorial proof
Using counting arguments to prove that both sides of
the identity count the same objects but in different ways
Using combinatorial proof for nC r = nCn-r
C(n, r) = C(n, n - r)
Suppose that S is a set with n
elements.
Every subset A of S with r
elements corresponds to a
subset of S with n - r elements,
namely A Consequently,
C(n, r) = C(n, n - r)
…
Permutation / Combination
Proof
6 3 2
3P2 = 3C2 x 2P2
Number of r-permutations Number of r-permutations
of n elements of r elements
P ( n, r ) C ( n , r ) P ( r , r )
Number of r-combinations
of n elements
P (n, r ) n! /( n r )! n!
P(r , r ) r! /( r r )! r!(n r )!
Chapter 3.1, 3.3, 3.5, 3.6 19
Example
Your class has 10 students. How many
different ways the committee can be set up:
1. A committee of four 10C4
2. A committee of four and 10C4 · 4C1
one person is to serve as chairperson
3. A committee of four and
10C4 · 4C2
two co-chairpersons
4. Two committees:
10C4 · 4C2 · 10C3· 3C1
One with four members with two co-chairs
One with three members and a single chair
Chapter 3.1, 3.3, 3.5, 3.6 20
Counting Problems
How to apply what you have learn to solve
the counting problems?
Multiplication / Addition Principle
Inclusion-Exclusion Principle
Permutation / Combination
List all the possibilities
Counting Problems
Many counting problems can be treated as
the ways objects can be placed into boxes
Distinguishable Indinguishable
(labeled) (unlabeled)
Objects
Distinguishable
(labeled)
Boxes
Indinguishable
(unlabeled)
Chapter 3.1, 3.3, 3.5, 3.6 22
Distinguishable Objects 1
Distinguishable Boxes 1
How many ways are there to arrange the 5
students into a classroom with 5 seats?
Permutation
5!
Distinguishable Objects 1
Distinguishable Boxes 1
How many ways are there to arrange the 5 students
(A, B, C, D & E) into a classroom with 5 seats and
the student A and B sit next to each other?
Two situations:
4!
“AB” C D E
2 x 4!
4!
“BA” C D E
Chapter 3.1, 3.3, 3.5, 3.6 24
Distinguishable Objects 1
Distinguishable Boxes 1
How many ways are there to arrange the 5 students
into the round table with 5 seats?
Distinguishable Objects ∞
Distinguishable Boxes 1
How many strings of length r can be formed
from the English alphabet?
26 letters
Each letter can be used repeatedly
26r strings of length r
Distinguishable Objects 1
Distinguishable Boxes m
How many ways to give an apple, an orange, a
banana and a strawberry to Mickey Mouse and
Donald Duck?
4C0+4C1+4C2+4C3+4C4
Mickey 0 = 4C0
Mickey 1 = 4C1
Mickey 2 = 4C2
Mickey 3 = 4C3
Mickey 4 = 4C4
(Donald Duck takes the rest)
Chapter 3.1, 3.3, 3.5, 3.6 28
Distinguishable Objects n
Distinguishable Boxes m
How many ways to assign 3 apples and 2 oranges
to Mickey Mouse and Donald Duck?
6 x 2 = 12
Chapter 3.1, 3.3, 3.5, 3.6 29
Distinguishable Objects 1
Indistinguishable Boxes 1
How many poker hands of 5 cards can be
dealt from a standard deck of 52 cards?
A 2 3 4 5
Combination
=
2 A 4 5 3
n = 52, r = 5
=
52C5 3 4 A 5 2
=…
Four suits 4 6 2 9 4 5
Distinguishable Objects n
Indistinguishable Boxes 1
How many ways to put 3 apples, 2 oranges
and 1 banana to 3 indistinguishable boxes
and each box contains 1 item?
Distinguishable Objects 1
Indistinguishable Boxes m
One Office { {A,B,C,D} , {} , {} }
4 employees { { A,B,C} , {D} , {} }
Two Offices { { A,B,D} , {C} , {} }
1 employee, { { A,C,D} , {B} , {} }
3 employees { { A,C,D} , {A} , {} }
2 employees, { {A, B} , {C, D} , {} }
2 employees { {A, C} , {B, D} , {} }
{ {A, D} , {B, C} , {} }
Three Offices
2 employees, { {A, B} , {C} , {D} }
1 employee, { {A, C} , {B} , {D} }
1 employee { {A, D} , {B} , {C} }
{ {C, D} , {A} , {B} }
{ {B, D} , {A} , {C} }
14 different ways
{ {B, C} , {A} , {D} }
Chapter 3.1, 3.3, 3.5, 3.6 34
Distinguishable Objects n
Indistinguishable Boxes m
How many ways to put 3 apples, 2 oranges
and 1 banana to 3 indistinguishable boxes
and each box contains 2 items?
Indistinguishable Objects n
Distinguishable Boxes 1
How many routes are there from the lower-left
corner of 4 x 3 grid to the upper-right corner if the
turtle is restricted to traveling only to right or upward?
URUURRU
Each any route contains 7 moves:
4 Upward (U)
3 Right (R)
Answer: 7C4
Indistinguishable Objects n
Distinguishable Boxes ∞
Select five bills from $1, $2, $5, $10, $20, $50 and $100
Bill
100 50 20 10 5 2 1
Bill Bill Bill Bill
100 50 20 10 5 2 1 ***||*||||*
*||**|*||*| 100 50 20 10 5 2 1
Indistinguishable Objects n
Distinguishable Boxes ∞
How many solutions does the equation
x1 + x2 + x3 = 11 have, where x1, x2, and x3 integers
and x1 ≥ 1, x2 ≥ 2, and x3 ≥ 3?
Answer is 1
Indistinguishable Objects n
Indistinguishable Boxes m
How many ways are there to pack 6 copies of
the same book into 4 identical boxes, where a
box can contain as many as six books?
Generating Combinations
Recall that the bit string corresponding to a
subset
For kth position:
1 : ak is in the subset
0 : ak is not in the subset
If all the bit strings of length n can be listed,
then by the correspondence between subsets
and bit strings, a list of all the subsets is
obtained
Example
Find out the next combination using next
larger bit string algorithm for 1. i = 0
2. while bi = 1
1011 2.1 bi = 0
2.2 i = i + 1
3. bi = 1
Next:
1100
b3 b2 b1 b0
Generating Combinations
1. i = r
Example 1 2. while ai = n - r + i
2.1 i = i - 1
Find the next larger 4-combination 3. ai = ai + 1
of the set {1, 2, 3, 4, 5, 6} 4. for j = i + 1 to r
after {1, 2, 5, 6} 4.1 aj = ai + j - i
a1 = 1, a2 = 2, a3 = 5, and a4 = 6
The last ai such that ai ≠ n - r + 1 is a2 (i = 2)
Example 2
List all 3-combination for the set {a, b, …, e}
Assume {a, b, …, e} = {1, 2, …, 5}
For all {a1, a2, a3}
1. i = r
1. {a, b, c} 6. {a, d, e} 2. while ai = n - r + i
2.1 i = i - 1
2. {a, b, d} 7. {b, c, d}
3. ai = ai + 1
3. {a, b, e} 8. {b, c, e} 4. for j = i + 1 to r
4. {a, c, d} 9. {b, d, e} 4.1 aj = ai + j - i
5. {a, c, e} 10. {c, d, e}
Generating Permutations
Any set can be placed in one-to-one
correspondence with the set {1, 2, 3, ..., n}
The permutations of any set of n elements can
be listed by generating the permutations of the
n smallest positive integers
The algorithms based on the lexicographic
(or dictionary) ordering is discussed
Generating Permutations
Example
What is the next permutation in lexicographic order
after 362541?
r-Permutations
How can we list all r-permutations from a
set {1, 2, 3, . . . , n}? r-combination
{a1, a2 , a3}
{1, 2, 3, 4} n-permutation
1. Use “next larger
r-combinations” lists {1, 2, 3} {1, 2, 3}
all r-combinations {1, 2, 4} {1, 3, 2}
2. For each r-combination, {1, 3, 4} {2, 1, 3}
use n-permutation to list {2, 3, 1}
all permutations {2, 3, 4}
{3, 1, 2}
{3, 2, 1}
Chapter 3.1, 3.3, 3.5, 3.6 53
Pigeonhole Principle
Suppose that a flock of 26 pigeons flies into a
set of 25 pigeonholes to roost
What can we conclude?
Pigeonhole Principle
Pigeonhole Principle
If k is a positive integer and k + 1 or more objects
are placed into k boxes, then there is at least one
box containing two or more of the objects
Also called the Dirichlet Drawer Principle
the nineteenth-century German mathematician Dirichlet
a
b 1
2
c
3
d
Pigeonhole Principle
Example 1
How many words we should have if there must be
at least two that begin with the same letter?
27 English words, because 26 letters in the English
alphabet
Example 2
How many people we should have if there must be
at least two with the same birthday?
367 people because 366 possible birthdays
Proof by Contradiction
Suppose that none of the boxes contains more than
N/k - 1 objects
The total number of objects is at most
N N
k 1 k 1 1 N N/k < (N/k) + 1
k k
This is a contradiction because there are a total of N
objects
k
N
Chapter 3.1, 3.3, 3.5, 3.6 62
Generalized Pigeonhole Principle
N/k ≥ r, N = k(r - 1) + 1, is the smallest
integer satisfying N/k ≥ r
Could a smaller value of N suffice?
No
If k(r - 1) objects
We could put r - 1 of them in each of the k
boxes
No box would have at least r objects
N = 100
k = 12
r=?
100/12 = 9 who were born in the same
month
Applications: Subsequence
Example
Example:
a1 , a2, ..., a5 = 5, 8, 2, 3, 1
5, 3, 1 is a subsequence? a1, a4, a5
8, 1 is a subsequence? a2, a5
2, 3, 5, 8 is a subsequence? a3, a4 , a1, a2
Applications: Subsequence
Theorem
Every sequence of n2 + 1 distinct real numbers
contains a subsequence of length n + 1 that is
either strictly increasing or strictly decreasing
Example
Given a sequence: 8, 11, 9, 1, 4, 6, 12, 10, 5, 7
10 term = 32 + 1
What is the length of the longest in / decreasing
subsequences? n+1 = 4
Increasing sequence Decreasing sequence
1, 4, 6, 12 11, 9, 6 ,5
1, 4, 6, 7
1, 4, 6, 10
1, 4, 5, 7
5, 8, 2, 3, 1
(i1, d1) = (2, 3) (i4, d4) = (1, 2)
Chapter 3.1, 3.3, 3.5, 3.6 71
Applications: Subsequence
5, 8, 2, 3, 1
Proof (2, 3) (1, 2)
Suppose no increasing or decreasing
subsequences is longer than n
ik and dk are both positive integers less than or
equal to n, for k = 1, 2, . . . , n2 + 1
By the product rule,
n2 possible ordered pairs for (ik, dk)
By the pigeonhole principle
two of n2 + 1 ordered pairs are equal
Therefore, there exist terms as and at,
with s < t such that is = it and ds = dt
Friends Enemies
Mutual Friend/Enemies
A B A B
A B C D are mutual
friends/enemies
C D C D
Chapter 3.1, 3.3, 3.5, 3.6 74
Applications: Ramsey Theory
Example 1
Assume that in a group of six people
Show that there are either three mutual
friends or three mutual enemies in the group
A B C D E F
Example 1
Let A be one of the six people
According to pigeonhole principle (5/2 = 3),
A at least has three friends, or three enemies
Former Case: suppose that B, C, and D are friends
If any two of these three people are friends, then these two and A
form a group of three mutual friends
Otherwise, B, C, and D form a set of three mutual enemies
Similar to the latter case
A B C D E F
Example
What is R(3, 3)?
Answer should be 6
In a group of five people where every two people are
friends or enemies, there may not be three mutual friends
or three mutual enemies
A C
E D
Agenda
Recurrence Relations
Modeling with Recurrence Relations
Linear Nonhomogeneous Recurrence Relations
with Constant Coefficients
Generating Functions
Useful Facts About Power Series
Extended Binomial Coefficient
Extended Binomial Theorem
Counting Problems and Generating Functions
Using Generating Functions to Solve Recurrence
Relations
Ch. 4.1, 4.2 & 4.4 2
Recursion
How many i-
7 products?
2 4 1 How many
i-products?
0 0 1 1 0 1 1 1 1 0 0 1 0 0
Ch. 4.1, 4.2 & 4.4 3
Recurrence Relations
A recurrence relation for a sequence {an} is an
equation that expresses an in terms of one or more
previous elements (a0, …, an−1)
A sequence is called a solution of a recurrence
relation if its terms satisfy the recurrence relation
Example 1
Let {an} be a sequence that satisfies the
recurrence relation an = an-1 - an-2 for n = 2, 3,
4, . . . , and suppose that a0 = 3 and a1 = 5.
What are a2 and a3?
Recurrence Relations
Example 2
Consider the recurrence relation
an = 2an−1 − an−2, where n ≥ 2
Which of the following are solutions?
an = 3n
2an−1 − an−2 = 2(3(n - 1)) - 3(n - 2) = 3n = an
an = 2n
2an−1 − an−2 = 2(2n-1) – nn-2 = 2n ≠ an
an = 5
2an−1 − an−2 = 2 x 10 – 5 = 5 = an
Compound Interest
Growth of saving in a bank account with r% interest
per given period
Sn = Sn-1 + r · Sn-1 = (r+1) · Sn-1
Example:
Suppose that a person deposits $10,000 in a savings
account at a bank yielding 11 % per year with interest
compounded annually. How much will be in the account
after 30 years?
S30 = 1.11S29 = 1.11(1.11S28) = …= (1.11)30 10,000
Tower of Hanoi
Objective
Get all disks from peg 1 to peg 3
Rules
Only move 1 disk at a time
Never put a larger disk on a smaller one
1 2 3
Tower of Hanoi
More than 1 steps
Break Down
Recursive Call Recursive Call
More than 1 steps 1 step More than 1 steps
Tower of Hanoi
More than 1 steps
Break Down
Recursive Call Recursive Call
More than 1 steps 1 step More than 1 steps
Tower of Hanoi
More than 1 steps
Break Down
Base Case Base Case
1 step 1 step 1 step
Tower of Hanoi
The solution
Tower of Hanoi
Let Hn be the number of moves for a stack of
n disks.
Strategy:
Move top n−1 disks (Hn−1 moves)
Move bottom disk (1 move)
Move top n−1 to bottom disk (Hn−1 moves)
Hn = 2Hn-1 + 1
Example 1
Find a recurrence relation and give initial conditions for the
number of bit strings of length n that do not have two
consecutive 0s.
Example 2
Find a recurrence relation and give initial conditions for the
number of bit strings of length n that do not have three
consecutive 0s.
an = an-5
Bn = nBn-1
5-LiHoReCoCo
Non-constant coefficient
k-LiHoReCoCo (n is a variable)
Linear: the power of all ai term is one
Homogeneous: no constant term (no team without ai)
Recurrence: a sequence {an} which an in terms of an-1, an-2,…
Degree k: refer to k previous terms an-k
Constant Coefficients: c1, c2, … independent from n
Ch. 4.1, 4.2 & 4.4 20
Solving 2-LiHoReCoCos
Given 2-LiHoReCoCo: an = c1an−1 + c2an−2 , and a0 =
c and a1 = d
Solving 2-LiHoReCoCos
By considering 1-LiHoReCoCo, an = c an-1
Obviously, the general solution is an = cn a0
Therefore, the solution of the form may be an = rn
Solving 2-LiHoReCoCos
Theorem
Consider an arbitrary 2-LiHoReCoCo:
an = c1an−1 + c2an−2
By substituting an = rn, we have the characteristic
equation:
r2 − c1r − c2 = 0
If there has two different roots r1 and r2, then
an = w1r1n + w2r2n
for n ≥ 0 and some constants w1, w2
Solving 2-LiHoReCoCos
Step 1
Show if an = w1r1n + w2r2n , {an} is a solution of the
recurrence relation
c1an1 c2 an2 c1 w1r1n1 w2 r2n1 c2 w2 r1n2 w2 r2n2
w1r1n2 c1r1 c2 w2 r2n2 c1r2 c2
w1r1n2 r12 w2 r2n2 r22 r1 and r2 are the solution of
r 2 c1r c2 0
w1r1n w2 r2n
an
Solving 2-LiHoReCoCos
We know that {an} and {α1r1n + α2r2n} are both
solutions of the recurrence relation an = c1an−1 +
c2an−2 and both satisfy the initial conditions when n =
0 and n = 1
Because there is a unique solution of 2-
LiHoReCoCo with two initial conditions, it follows
that the two solutions are the same, that is, an =
α1r1n + α2r2n for all nonnegative integers n
We have completed the proof
Characteristic Equation: r2 − r − 2 = 0
Characteristic Root:
r = (1 ± 3) / 2 b b 2 4ac
r = 2 or r = −1 x
2a
Therefore, an = w1 2n + w2 (−1)n
By using a0 = 2, a1 = 7
a0 = 2 = w120 + w2 (−1)0
a1 = 7 = w121 + w2 (−1)1
w1 = 3 and w2 = 1
Therefore, an = 3·2n − (−1)n
Ch. 4.1, 4.2 & 4.4 29
Characteristic equation: r2 - 6r + 9 = 0
Only one characteristic root: r = 3
Hence, the solution to this recurrence relation is
an = w13n + w2n3n
for some constants α1 and α2
By using the initial conditions,
a0 = 1 = w1, a1 = 6 = 3w1 + 3w2, so w1=1 and w2 = 1
Consequently, an = 3n + n3n
Summary
Given : an = c1an−1 + c2an−2 and a0 = c and a1 = d
1. Characteristic equation: r2 − c1r − c2 = 0
Small Exercise
What is the solution of the recurrence relation
an = - an-1 + 6an-2 with initial conditions a0 = 0
and a1 = 5?
Characteristic Equation: r2 + r - 6 = 0
(r + 3)(r – 2) = 0
Characteristic Root: r1 = -3, r2 = 2
Therefore, an = w1 (-3)n + w2 (2)n
Using the initial condition
a0 = 0 = w1 + w2
a1 = 5 = -3w1 + 2w2
w1 = -1, w2 = 1
Therefore, an = - (-3)n + (2)n
Ch. 4.1, 4.2 & 4.4 35
Small Exercise
the recurrence relation: an = - 2an - an-2
Initial conditions a0 = 5 and a1 = -6
Characteristic Equation: r2 + 2r + 1 = 0
(r + 1)(r + 1) = 0
Characteristic Root: r1 = -1
Therefore, an = w1 (-1)n + w2 n (-1)n
Using the initial condition
a0 = 5 = w1
a1 = -6 = -w1 - w2
w1 = 5, w2 = 1
Therefore, an = 5 (-1)n + n (-1)n
Ch. 4.1, 4.2 & 4.4 36
Solving k-LiHoReCoCos
k
2-kiHoReCoCo
k-LiHoReCoCo: a c a a =c a +c a
n i n i n 1 n−1 2 n−2
i 1
Characteristic Equation is:
k
r ci r k i 0
k
r2 − c1r − c2 = 0
i 1
Theorem
If there are k distinct roots ri , then the solutions to
the recurrence are of the form:
k
an wi ri n an = w1r1n + w2r2n
i 1
Solving k-LiHoReCoCos
Example
Find the solution to the recurrence relation
an = 6an-1 – 11an-2 + 6an-3
with the initial conditions a0 = 2, a1 = 5, and a2 = 15.
The characteristic equation is:
r3 - 6r2 + 11r – 6 = (r - 1)(r - 2)(r - 3)
The characteristic roots are r = 1, r = 2, and r = 3
an = w11n + w22n + w33n
By using the initial conditions
a0 = 2 = w1 + w2 + w3
a1 = 5 = w1 + w2 x 2 + w3 x 3
a2 = 15 = w1 + w2 x 4 + w3 x 9
Therefore, w1 = 1, w2 = -1 and w3 = 2
As a result, an = 1 - 2n + 2 x 3n
Ch. 4.1, 4.2 & 4.4 38
Solving k-LiHoReCoCos
with same roots
Let c1, c2, ..., ck be real numbers
Suppose that the characteristic equation
rk – c1rk-1 – ··· – ck = 0
has t distinct roots r1, r2, ..., rt with
multiplicities m1, m2, ..., mt
i.e. ri appear mi times
m1 + m2 + ··· + mt = k
Solving k-LiHoReCoCos
Special case for k=2, One distinct root
an = w1r0n + w2nr0n
with same roots an = (w1 + w2n)r0n
A sequence {an} is a solution of the recurrence relation
an = c1an-1 + c2an-2 + ... + ckan-k
If and only if Multiplicities for ri
mi 1
t n
wi , j n ri
j
i 1 j 0
for n = 0,1,2, ..., where wi,j are constants for 1 ≤ i ≤ t and
0 ≤ j ≤ mi-1
Ch. 4.1, 4.2 & 4.4 40
m1 1
an (wroots
Solving k-LiHoReCoCos with same 1, 0 w1,1n ... w1, m1 1n )r1n
(w2,0 w2,1n ... w2,m2 1n m2 1 )r2n
Example ... (wt ,0 wt ,1n ... wt ,mt 1n mt 1 )rt n
Find the solution to the recurrence relation
H n H n 1 3H n 2 5H n 3 2 H n 4
with the initial conditions H 1,H 0, H 1,H 2
0 1 2 3
Characteristic equation: x 4 x 3 3x 2 5 x 2 0
( x 2)( x 1) 3 0
Roots: 1, 1, 1, 2
Therefore: H n ( c1 c2 n c3 n 2 )( 1) n c4 2 n
By initial conditions:
H 0 c1 c4 1 7 1 2
c1 , c2 , c3 0, c4
H c c c 2c 0 9 3 9
1 1 2 3 4
H 2 c1 2c2 4c3 4c4 1 Hn
7 1 2
(1) n n(1) n 2n
H 3 c1 3c2 9c3 8c4 2 9 3 9
Solving k-LiHoReCoCos
Summary k
Given : an c a
i 1
i n i and ai = ci , where i = 1, 2, …, k
k
1.Characteristic equation: r k
i 0
c r
i 1
k i
mi 1
t n
1. n i , j ri is the solution of k-LiHoReCoCos
j
a w n
i 1 j 0
where mi is the multiplicity of ri
mi 1t
2. solve wi by ap = cp wi , j p j ri p
i 1 j 0
where p = 1, 2, ..., k
Ch. 4.1, 4.2 & 4.4 42
Small Exercise
What is the solution of the recurrence relation
an = an-1 + an-2 - an-3 with initial conditions a0 =
0, a1 = 8 and a2 = 4?
Small Exercise
the recurrence relation: an = an-1 + an-2 - an-3
Initial conditions a0 = 0, a1 = 8 and a2 = 4
Characteristic Equation: r3 – r2 – r + 1 = 0
(r – 1)(r – 1)(r + 1) = 0
Characteristic Root: r1 = 1, r2= 1, r3 = -1
Therefore, an = (c1 + c2 n) (1)n + c3 (-1)n
Using the initial condition
a0 = 0 = c1 + c3
a1 = 8 = c1 + c2 – c3
a2 = 4 = c1 + 2c2 + c3
c1 = 3, c2 = -3, c3 = 2
Therefore, an = 3 (1 – n) (1)n + 2 (-1)n
Ch. 4.1, 4.2 & 4.4 44
Solving LiNoReCoCos
Linear nonhomogeneous recurrence of
degree k with constant coefficients
(k-LiNoReCoCos) contain some terms F(n)
that depend only on n but not ai
General form:
an = c1an−1 + … + ckan−k + F(n)
Solving LiNoReCoCos
If { an( p ) } is a particular solution of the
nonhomogeneous linear recurrence relation with
constant coefficients
an = c1an-1 + c2an-2 + ... + ckan-k + F(n)
Therefore, we have 3
an a a
( p) (h) a n
( p)
n
n n 2
3
n c3n an( h ) c3n
2
By using a1 = 3
3 = -1 - 3/2 + 3c
c = 11/6
As a result,
Solving LiNoReCoCos
F ( n ) : Particular
(b n t b n tSolution
1
... b n b )sn
t t 1 1 0
Example 1
s is not a root ( pt n t pt 1n t 1 ... p1n p0 ) s n
What form does a particular solution t of the tlinear
1
s is a root n m
nonhomogeneous recurrence relation( pt n pt 1n ... p1n p0 ) s n
t 1
s is not a root ( pt n pt 1n ... p1n p0 ) s
t n
Summary
k-LiHoReCoCos with m same roots (without F(x))
Find the root of characteristic equation
an (1,0 1,1n ... 1,m 1n )r1
m 1
1 n
1
( 2,0 2,1n ... 2,m 1n m 1 )r2n
2
2
Small Exercise
Find all solutions to an = 7an−1+(2n2+2)3n,
which solution has a1 = 10?
( p)
Need to do is find one an
an = 7an−1+(2n2+2)3n
Small Exercise a0 = 10
Now, F(n) = (2n2+2)3n
( p)
an = (an2 + bn + c)3n
an = 7an-1 + (2n2+2)3n
(an2+bn+c)3n = 7(a(n-1)2+b(n-1)+c)3n-1 + (2n2+2)3n
3an2+3bn+3c = 7an2 - 14an + 7a + 7bn – 7b + 7c + 6n2 + 6
0 = 4an2 - 14an + 7a + 4bn – 7b + 4c + 6n2 + 6
0 = n2(4a+6)+n(4b-14a) +(4c +7a-7b+6 )
4a+6=0 4b-14a=0 4c +7a-7b+6=0
a=-3/2 b=-21/4 c=-129/16
an( p ) (3n 2 / 2 21n / 4 129 / 6)3n
Ch. 4.1, 4.2 & 4.4 58
an = 7an−1+(2n2+2)3n
Small Exercise a0 = 10
Therefore, we have
an an( p ) an( h ) an( p ) (3n 2 / 2 21n / 4 129 / 6)3n
By using a0 = 10
a0 = 10 = -129/6 + c
c = 189/6
As a result,
an (3n 2 / 2 21n / 4 129 / 6)3n 189 7 n / 6
Generating Functions
Generating functions ( G(x) ) are used to
represent sequences efficiently by coding the
terms of a sequence as coefficients of
powers of a variable x in a formal power
series
Generating function for the sequence
a0, a1, a2, …, ak, … of real numbers is the
infinite series
G( x) a0 x a1x ak x ak xk
0 1 k
k 0
{1, 1, 1, 1, 1}
4
1 + x + x2 + x3 + x4 = x
k 0
k
k 0 1 ax
1
f x 1 f x
1 x 1 ax
is generating function is generating function
of the sequence of the sequence
1,1,1,1, ... 1, a, a2, a3, ...
k 0
f x g x a x b x k
k
k
k
k 0 k 0
(a0 x 0 a x ...)(b0 x 0 b1 x1 ...)
1
1
k 0 j 0
Ch. 4.1, 4.2 & 4.4 63
Example
1
Let h( x) ,
(1 x ) 2
Find the coefficients a0, a1, a2, ... in the expansion
h ( x ) k 0 ak x k
1 1 1
h(x)
1
(1 x) 2 (1 x) (1 x)
f x xk
1 x k 0 k k
x x
k 0 k 0
f x ak x k
g x bk x k
k 0 k 0
k
x k
f x g x ak bk x k
k 0 j 0
k 0
f x g x a j bk j x k
k
ak=k+1 (k 1) x k
k 0 j 0
k 0
G( x) a0 x a1x ak x ak xk
0 1 k
k 0
Example 1
Find the number of solutions of e1 + e2 + e3 = n when n = 17,
where e1 ,e2, e3 are nonnegative integers with 2 e1 5,
3 e2 6, 4 e3 7
( x 2 x3 x 4 x5 )
ak x k ( x 3 x 4 x 5 x 6 )
k 0 ( x4 x5 x6 x7 )
As n = 17, a17, which is the coefficient of x17, is the solution
Answer is 3
Example 2
In how many different ways can eight identical
cookies be distributed among three distinct children
if each child receives at least two cookies and no
more than four cookies?
k ( x 2 x3 x 4 )( x 2 x3 x 4 )( x 2 x 3 x 4 )
a x
k 0
k
The coefficient of x8 is 6
Example 3
Solve the recurrence relation ak = 3ak-1 for k=1, 2,
3, … and initial condition a0=2
Let G(x) be the generating function for the
sequence {ak}, that is
1
a
k 0
k
xk
1 ax
Example 4
Solve the recurrence relation ak = -ak-1 + 6ak-2 with
initial conditions a0 = 0 and a1 = 5
Let G(x) be the generating function for the
sequence {ak}, that is
−ak−1 + 6ak−2
ak−1 6 ak−2
Example 4
ak−1 6 ak−2
ak−1 6 ak−2
ak−1 6 ak−2
6 a0 = 0 and a1 = 5
2 3
Example 4
2 3
2 3
1
2x 3 1 ax
Example 5
Solve the recurrence relation an = - 2an-1 - an-2 with
initial conditions a0 = 5 and a1 = -6
Let G(x) be the generating function for the
sequence {ak}, that is
2ak−1 ak−2
ak−1 ak−2
Example 5
ak−1 ak−2
ak−1 ak−2
ak−1 ak−2
a0 = 5 and a1 = -6
1
1 ax
Example 5
1−
When k =0, −1 =0
Example 5
1−
an = 5 (-1)n + n (-1)n
Example 6
The sequence {an} satisfies the recurrence
relation
an = 8an-1 + 10n-1
and the initial condition a1 = 9
Use generating functions to find an explicit
formula for an
1
ak xk
k 0 1 ax
1
k 0
a x
k k
1 ax
1 n
an 8 10 n
2
Ch. 4.1, 4.2 & 4.4 78
Discrete Mathematic
Chapter 9: Graphs
9.1
Graphs and Graph Model
9.2
Graph Terminology and
Special Types of Graphs
9.3
Representing Graphs and
graph Isomorphism
9.4
Connectivity
Yan Huang
School of Computer Science and Engineering
South China University of Technology
Agenda
Graph
Terminology
Connectivity
Isomorphism
2
Graph
A graph G = (V, E) consists of a set of vertices V,
and a set of edges E
Vertex (d)
d 4 Vertices (V)
1 e |V|: the number of vertices
5
4
7 Edges (E)
c 3 Sometimes referred as arc
a 2
Connection between a pair
1 f of vertices (v, w), where v
b and w belong to V
Edge (b, e)
|E|: the number of edges
V = { a, b, c, d, e, f } Weight may be included
E = { (a,b), (a,c), (a,d), (b,e), (c,d), (c,e), (d,e), (e,f) }
Graph Structure
Key questions about Graph Structure
Directed / Undirected Edge?
Single / Multiple Connection?
Loop?
4
Graph Structure
Directed/Undirected?
Undirected Graph a d
Edges are not directed
c
If (a,b), then (b,a)
b d
Directed Graph (Digraph)
Edges are directed a d
(a,b) does not mean (b,a)
c
b e
Graph Structure
Single/Multiple Connection?
Simple Graph a d
No two edges connects the same
pair of vertices c
Loop is not allowed
Multigraph b d
Two vertices may be connected by
more than one edges a u d
y
An edge cannot be identified
uniquely by a pair of vertices z c v
x t
Additional name is needed
E.g. (c,d) means u or v
b e
w
6
Graph Structure
Loop?
Multigraph does not allow a u d
y
loop
z c v
x t
Pseudograph is a special
multigraph allows loop b
w
e
a u d
y
Sometimes, the meanings
z c v
of Pseudograph and x t
a
Multigraph are the same
b e
w
Graph Structure
Summary
No Loop Loop
Pesudograph
Multiple Edge Multigraph
(Multigraph)
No Loop Loop
Simple Directed
Directed Single Edge /
Graph
Directed
Multiple Edge Mixed Graph
Multigraph
8
Adjacent / Neighbor
Undirected graph Directed graph
Let (v1, v2) is an edge Let (v1, v2) is an edge
v1 and v2 are endpoints v1 is initial vertex
v1 is adjacent to v2 v2 is terminal (end)
Also mean vertex
“v2 is adjacent to v1” v1 is adjacent to v2
since (v1, v2) = (v2, v1) v2 is adjacent from v1
Do not mean
“v2 is adjacent to v1”
v1 v2 v1 v2
Adjacent / Neighbor
e incidents with v1 and v2 e
v1 v2
e connects v1 and v2
Example:
a & b are adjacent w is adjacent to z
b & a are adjacent z is not adjacent to w
a d w x
c z
b e y v
10
Neighbor Set
Neighbor Set N(v) contains all adjacent
vertices of v
For example: N(c) = {a,b,d}
N(z) = {y}
a d w x
c z
b e y v
11
Degree
Undirected graph Directed graph
Degree: number of edges In-Degree: in-bound edge
containing that vertex number
(Adjacent vertex number) Out-Degree: out-bound
Isolated vertex: deg = 0 edge number
Pendant vertex: deg = 1 E.g. deg-(z) = 2
E.g. deg(c) = 3 deg+(z) = 1
a d w x
c z
b e y v
12
Degree: Example
What are the degrees of the following
vertices?
deg(a) = 2 deg-(g) = 2 deg+(g) = 0 a c e
13
Degree Sequence
A degree sequence is a monotonic
nonincreasing sequence of the degrees of
vertices in an undirected graph.
2 2 0
a c e (2,3,2,2,0,1) Not monotonic nonincreasing
2 2
a d
3
(3,3,2,2,2) Degree sequence
c
3 2
b e
14
Degree
Handshaking Theorem 1
For any undirected graph G = (V, E),
Example 1
How many edges are there in a graph with 10
vertices each of degree six?
Total degree = 10 x 6 = 60
According to Handshaking Theorem
|E| = 60/2 = 30
16
Degree: Handshaking Theorem 1
Example 1
Is there a graph with degree sequence…
(2,2,2)? Yes (3,3,3,3)? Yes
a a
d
b c b c
??
b c b c
17
Degree
Handshaking Theorem 2
Undirected graph has an even number of
vertices of odd degree
a c e a a
d
b d f b c
b c
vertices of odd degree vertices of odd degree vertices of odd degree
2 4 2
18
Degree
Handshaking Theorem 2
Proof
Let Vo and Ve be the set of vertices of odd and
even degree
Degree
Handshaking Theorem 3
For any directed graph G = (V, E),
c Vertex a to b
a>b Length = 1 Simple
Cycle (Circuit)
A path connects vi to itself
A cycle is simple if the path is simple, except
the first and last vertices are the same
b e
22
Acyclic
A graph without cycle is called acyclic
A directed graph without cycles is called a
Directed Acyclic Graph (DAG)
a a a
b c b c b c
d e f d e f d e f
Not a DAG Not a DAG
Undirected Acyclic
23
Connectedness
Vertices v, w are connected if and only if
there is a path starting at v and ending at w
Every graph consists of separate connected
pieces called connected components
24
Connectedness
Undirected graph Directed graph
Connected: if there is at Weakly connected: Directed
least one path from any graph without considering
vertex to any other directions is connected
(Only one connected Strongly connected: Directed
component) graph with considering
direction is connected
a d a d a d a d
c c c c
b e b e b e b e
Connected Not Connected Strongly Weakly
Connected Connected
25
Maximal/Minimal graph
A graph G is said to be a maximal graph
(minimal graph) with respect to a property P if
G has property P and no proper supergraph
(subgraph) of G has the property P
b d b d
a f a f
b d c e c e
a f maximal cycle
c e b d
b d
a f a f
c e c e
minimal connected graph
26
Graph Operation
Given G1=(V1,E1) and G2=(V2,E2)
Complement G1
(V1, {uv | u ≠ v, uv E1} )
Intersection G1 ∩ G2
(V1 ∩ V2 , E1 ∩ E2 )
Union G1 U G2
(V1 U V2 , E1 U E2 )
Join G1 + G2 if V1 ∩ V2 =
(V1 U V2 , E1 U E2 U {uv | uV1 and vV2})
Cartesian Product G1 G2
(V1 V2 , {(u1, u2), (v1, v2) |
(u1 = v1 and {u2, v2}E2) or
(u2 = v2 and {u1, v1}E1)})
27
Graph Operation
Example 1
a b a a b a a b
c d c c c d c
A B A A∩ B AU B
y 1 2
z 3 y 1 2 y1 y2 y3
C D z 3 z1 z2 z3
C+D CD
28
Graph Operation
Example 2
a b a
c d c
b1 b2 b3
A B
b
y 1 2 a1 a2 a3
a 1 2
z 3
c 3 c1 c2 c3
C D
A+D AD
29
Graph Operation
Example 3
a c
e
b d
W4
a c a c
b d b d
K4 C4
30
Graph Operation
Example 4
1 a
b
2 c
K2 K3
1 a
b
2 c
K2 K3
31
Graph Operation
Example 5
1a 1b 1c
2a 2b 1c
K2 K3
1a 1b 1c
2a 2b 1c
K2 K3
32
Type of Graph
Complete Graph
Complete graph Kn if there is an edge
between every pair of vertices, where n is the
number of vertices
Complete Undirected Complete Directed
Graph Graph
a c a c
K4
b d b d
33
Type of Graph
Cycle Graph
Cycle graph Cn is a circular graph with V =
{0,1,2,…,n-1} where vertex i is connected to
(i+1) mod n and to (i-1) mod n
like a polygon
a a c
a a b
b c b d
C1 C2 C3 C4
34
Type of Graph
Wheel Graph
Wheel graph Wn is a cycle graph with an
extra vertex in the middle which contact to
each of other vertices
b a a c
a a c b d e
b c b d
W1 W2 W3 W4
35
Type of Graph
Cube
n-cube Qn is defined recursively.
Q0 is just a vertex
Qn+1 is gotten by taking 2 copies of Qn and
joining each vertex v of Qn with its copy v’
e' g'
e g
a' c'
a a a a' a c
a'
a c
c'
Q0 Q1 Q2 Q3 Q4
36
Type of Graph
Bipartite Graph
A graph is bipartite if all vertices can be
separated into two partitions, (i.e. V = V1 V2
and Ø = V1 V2) so that any two adjacent
vertices are in different partitions
(V1, V2) is called a bipartition of V of G
a b a b a b
e f e f f e
g h g h d c
c d c d g h
37
Type of Graph
g h d c
c d g h
38
Type of Graph
39
Type of Graph
b d
a f
c e
NO
For example, consider a, b, and c. There is
two adjacent vertices are assigned the same
color if only two colors are allowed
40
Type of Graph
Subgraph
Let G = (V,E) and H = (W,F) be graphs. H is
a subgraph of G, if W V and F E
Subgraph is a graph inside another group
A subgraph H of G is a proper subgraph of G
if H ≠ G a d
Subgraph c a d Subgraph
a d d
b c
c a
b e c
Not
b e c Subgraph Subgraph Not
Subgraph
b e
42
Subgraph: Example
How many different Q2 subgraphs does Q3
have?
6
b d
a c
Q3
f h b d
e g a c
f h
a c e g
Q2
b d
43
Tree
Tree is an undirected, connected and acyclic graph
n vertices has (n-1) edges
a c a a
b
a b b b c
d
d d e d e f
Theorem 1
A tree with at least two vertices has at least two leaves
a
Assume P is a longest path in a tree T b c
Prove its endpoints are leaves d e f
Suppose v is not a leaf, g
then v has at least two neighbors, x and y
One of them (say x) must not in P, otherwise a cycle
Let P’ be the path that begins at x followed by P
This is a longer path than P which is contradict to the
assumption
45
Tree
Theorem 2
A tree on n vertices has n − 1 edges
For N(1)
If n = 1, then T has no edges
Assume N(k) is true
T with n vertices has exactly n − 1
Show N(k+1)
46
Tree
Theorem 2
Show T with n+1 vertices has exactly n − 1
47
Tree
Theorem 3
Let G be a graph with n vertices. Then the
following are equivalent:
1. G is a tree
2. G is a maximal acyclic graph
3. G is a minimal connected graph
4. G is acyclic and it has n − 1 edges
5. G is connected and it has n − 1 edges
6. Between any two distinct vertices of G there
exists a unique path
48
Tree
Spanning Tree
Spanning Tree in a connected graph G is a sub-
graph H of G that includes all the vertices of G and
is also a tree
b d b d
a f a f
c e c e
b d Not Spanning Tree Spanning Tree
(not all vertices)
a f
c e b d b d
a f a f
c e c e
Not Spanning Tree Spanning Tree
(not a tree)
49
Tree
1 3 a 1
d
4 5
c b 2 6
5 2 6 e f 3 4
Yes Yes Yes
Different Labels Different Positions Different Label
and Positions
51
Graph Isomorphism
Two graphs, A and B, which contain the same
number of graph vertices connected in the
same way are said to be isomorphic, A B
Applications
Checking fingerprint
Testing molecules
52
Graph Isomorphism
If G1 G2, do they have
the same number of vertices? Yes |V| = 6
|E| = 4
the same number of edges? Yes
2, 2, 2, 1, 1, 0
the same degree sequence? Yes a b c
Graph Isomorphism
G1 = (V1,E1) G2 = (V2,E2) if there is a
bijective function f : V1 V2 such that for all
(u, v) E1:
(u, v) E1 iff (f (u), f (v)) E2
54
Graph Isomorphism (u, v) E1 iff (f (u), f (v)) E2
Example
f (a) = 3 a 1
f (b) = 1 b 2
a b 1 c 3
f (c) = 2
d 4
2 f (d) = 4 one-to-one
onto
c d 3 4
(a,b) ( f (a), f (b)) = (3,1)
G1 = (V1, E1) G2 = (V2, E2)
(a,c) ( f (a), f (c)) = (3,2)
V1 = {a, b, c, d} V2 = {1, 2, 3, 4}
E1 = {(a,b), (a,c), E2 = {(1,3), (1,4), (a,d) ( f (a), f (d)) = (3,4)
(a,d), (b,d), (2,3), (2,4),
(b,d) ( f (b), f (d)) = (1,4)
(c,d)} (3,4)}
(c,d) ( f (c), f (d)) = (2,4)
55
Graph Isomorphism
Self-complementary
A graph G is called self-complementary
if G G
C5 and C5 are self-complementary (C5 C5)
a c a c
C4 C4
b d b d
a a
C5 b c C5 b c
d e d e
56
Graph Isomorphism
Showing Isomorphism is not easy
No general method which is more efficient than
trying all possibilities
57
Graph Isomorphism
Showing non-isomorphic is simpler
Violate any isomorphic-preserving property
Example: Are they isomorphism? NO
Degree is 2
a b 1
2
c d 3 4
Degree is 2 Degree of all nodes is 3
58
Discrete Mathematic
Chapter 9: Graphs
9.5
Euler and Hamilton
Paths
9.7
Planar Graphs
9.8
Graph Coloring
Yan Huang
School of Computer Science and Engineering
South China University of Technology
Agenda
Euler Path
Hamilton Path
Planar Graph
Coloring
Euler Path
Seven Bridges of Königsberg
Königsberg is built on both banks of the Preger river
Now a city in Russia called Kaliningrad
Is it possible to walk through the city that would
cross each of bridges once
C
A D
B
Ch. 9.5, 9.7 & 9.8 4
Euler Path
Leonhard Euler, the Swiss mathematician,
was also unable to find such a route
Euler figured out how to
show for certain that
no such route existed
Euler Path
Euler Path: a path visits every edge exactly once
Euler Cycle: Euler path which starts and stops at
the same vertex
A connected graph G is called Eulerian if it contains
an Euler path
c b c b c b c b
a a a a
d f d f d f d f
Euler Path YES Euler Path YES Euler Path NO Euler Path YES
Euler Cycle YES Euler Cycle NO Euler Cycle NO Euler Cycle NO
Eulerian YES Eulerian YES Eulerian NO Eulerian YES
Ch. 9.5, 9.7 & 9.8 6
Euler Path
Observation from an Euler path,
a>c>a>d>e>a>b a>c>b>a>d>f>a
Euler Path Euler Cycle
c b c b
a a
d e d e
Starting / Intermediate deg(a) = 5 (O) deg(a) = 4 (E) Starting / Intermediate / End
Euler Path
Observation from an Euler path,
Intermediate vertex
Degree must be even
(Entrance and exist connection)
Starting and end vertices
If the same (cycle),
degree are even
If different (non-cycle),
degrees are odd (in or out)
Euler Path
2 2 2 1 2 1 2 2
c b c b c b c b
4 a 5 a 5 a 5 a
2 d 2 f 2 d 2 f 1 d 1 f 3d 2 f
Euler Path YES Euler Path YES Euler Path NO Euler Path YES
Euler Cycle YES Euler Cycle NO Euler Cycle NO Euler Cycle NO
Eulerian YES Eulerian YES Eulerian NO Eulerian YES
Starting/End Starting/End
Vertices must be Vertices must be
a and c a and d
Euler Path
Fleury’s Algorithm
Identify Euler Path
1. If there are 0 odd vertices, start anywhere. If
there are 2 odd vertices, start at one of them
2. Follow edges one at a time. If you have a
choice between a bridge and a non-bridge,
always choose the non-bridge
3. Stop when you run out of edges
“Don’t burn bridges” so that we can come
back to a vertex and traverse remaining
edges
Ch. 9.5, 9.7 & 9.8 12
Euler Path a
Fleury’s Algorithm
d f
b
c e
The bridge will be burnt
if we choose this! g
a a a a a a a
d f d f d f d f d f d f d f
b b b b b b b
c e c e c e c e c e c e c e
g g g g g g g
burn
a a a a a a a a bridge
d f d f d f d f d f d f d f d f
b b b b b b b b
c e c e c e c e c e c e c e c e
g g g g g g g g
Euler Path
Hierholzer’s Algorithm
Identify Euler Cycle
1. Select a node v as a starting node
2. Form a cycle using non-traveled edges and end
at v (remove the visited edges)
3. While all edges have been traversed, stop
a) Find a node u on the previous cycles that’s
connected to a non-traveled edge
b) Form a cycle using non-traveled edges and
end at u (remove the visited edges)
c) Merge both tours at the node u
Hierholzer’s Algorithm
2. Form a cycle using non-traveled edges and end at v
(remove the visited edges)
3. While all edges have been traversed, stop
a) Find a node v on the previous cycles that’s connected
to a non-traveled edge
a b) Form a cycle using non-traveled edges and end at v
(remove the visited edges)
c) Merge both tours at the node v
d f
a > d> f > a
b d > b> e> c > d
c e f > b> c > g> e> f
g
a >d >f >a
a > d >b >e >c >d > f >b >c >g >e >f >a
Ch. 9.5, 9.7 & 9.8 15
Euler Path
Example 1
Is it possible to begin in a room or the outside
and take a walk that goes through each door
exactly once? If yes, how?
Example 1
4 4
d
A B
a 7 b
c e
D
f g
h i j
C
5
A B A B A B
D D D
C C C
Euler Path
Example 2
Is it possible to walk through and around this
building passing through each and every
doorway exactly once?
Example 2
3
OUT
4 5 4
EW ME EE
2 CW CE
2
2 12 2
WW GH EW
C1 C2 C3 C4
2 4 4 2
Euler Path
Example 2
OUT OUT
EW ME EE EW ME EE
CW CE CW CE
WW GH EW WW GH EW
3
C1 C2 C3 C4 C1 C2 C3 C4
OUT
4 5 4 OUT OUT
EW ME EE
EW ME EE EW ME EE
2 CW CE 2 CW CE CW CE
WW GH EW WW GH EW
2 WW GH
12 EW
2
C1 C2 C3 C4 C1 C2 C3 C4
C1 C2 C3 C4 OUT OUT
2 4 4 2 EW ME EE EW ME EE
CW CE CW CE
WW GH EW WW GH EW
C1 C2 C3 C4 C1 C2 C3 C4
Dodecahedron puzzle
Ch. 9.5, 9.7 & 9.8 21
Hamilton Path
Hamilton Path: a path visits every vertex exactly
once
Hamilton Cycle: Hamilton path which starts and
stops at the same vertex
Self-loop and multiple edges can be ignored
b b c c b a b
c a
a d c d
e d
d e d f e f
Ham. Path YES Ham. Path YES Ham. Path NO Ham. Path YES
Ham. Cycle YES Ham. Cycle YES Ham. Cycle NO Ham. Cycle NO
Dirac’s Theorem
Theorem: If each vertex of a simple graph with n
vertices and n 3 has degree n/2, there is
Hamilton circuit
2 3 3 1 3 1 2
2 b 2 b c c b a b
c a 4 2 1 3
2 a d c d
2
e d 3 3 1 2 2 3
d e d f e f
Ham. Path YES Ham. Path YES Ham. Path NO Ham. Path YES
Ham. Cycle YES Ham. Cycle YES Ham. Cycle NO Ham. Cycle NO
Hamilton Path
Ore’s Theorem
Theorem: If every pair of non-adjacent vertices u
and v in a simple graph with n vertices and n 3
has deg(u)+deg(v) n, there is a Hamilton circuit
2 3 3 1 3 1 2
2 b 2 b c c b a b
c a 4 2 1 3
2 a d c d
2
e d 3 3 1 2 2 3
d e d f e f
Ham. Path YES Ham. Path YES Ham. Path NO Ham. Path YES
Ham. Cycle YES Ham. Cycle YES Ham. Cycle NO Ham. Cycle NO
Hamilton Path
Unfortunately, no good algorithm to find the
Hamilton path or cycle
Just “trial and error” (and good luck!)
Planar Graph
Planar Graph is a graph can be drawn in the plane
without edges crossing
A planar graph drawn in the plane without edges
crossing is called Plane Graph
Plane graph is also called a planar representation
Isomorphism
b d a c
b d b d
a b c
a c
f h f h
f h
e g e g d e f
Planar Graph Planar Graph Planar Graph Planar Graph
Plane Graph
Plane Graph
Plane Graph
Plane Graph
Ch. 9.5, 9.7 & 9.8 28
Planar Graph
A graph that is drawn in the plane is also said to be
embedded (or imbedded) in the plane
A planar graph can generate different plane graphs
Application: Circuit Layout Problems
a d a d a d
b e b e b e
Embedding
c f c f c f
(unbounded)
a R3 a (unbounded)
R1 R1 (unbounded) a R4 e
b e b e R1
b e b R3
R2
R2
c d c d c d a
Planar Graph
Euler’s Formula
If G be a connected planar simple graph with
e edges, v vertices, and r regions, then
r=e–v+2
Assume rn = en – vn + 2 is true
a a a
Add {an+1, bn+1}
b
b b
Gn Gn+1
Ch. 9.5, 9.7 & 9.8 37
Planar Graph
v = 20
Sum of degree = 20 x 3 = 60 = 2e
e = 30
r = e – v + 2 = 30 – 20 + 2 = 12
Ch. 9.5, 9.7 & 9.8 40
Planar Graph
Planar Graph
b c
K5 has circuit of length three, 5 vertices and
10 edges
As e = 10 and 3v – 6 = 9, e ≤ 3v – 6 is false
Therefore, K5 is nonplanar
If a connected planar simple graph has e edges
and v vertices with v ≥ 3, then e ≤ 3v – 6
d e f
K3,3 has no circuit of length three, 6 vertices
and 9 edges
As e = 9 and 2v – 4 = 8, e ≤ 2v – 4 is false
Therefore, K3,3 is nonplanar
If a connected planar simple graph has e edges and
v vertices with v ≥ 3 and no circuits of length three,
then e ≤ 2v – 4
Ch. 9.5, 9.7 & 9.8 43
Planar Graph
Homeomorphic
The graphs are called homeomorphic if they
can be obtained from the same graph by a
sequence of elementary subdivision
If a graph is planar, it will be any graph obtained
by removing an edge {u,v} and adding a new
vertex w with edges {u,w} and {w,v}
Obtain G from H
a d a d
f Remove {a, b}, Add {a, e}, {e, b}
e g Remove {a, c}, Add {a, f}, {f, c}
b c b c Remove {f, c}, Add {f, c}, {c, g}
G H
Ch. 9.5, 9.7 & 9.8 44
Planar Graph
Kuratowski’s Theorem
A graph is not planar if it contains a non-
planar subgraph
Kuratowski’s Theorem
A graph is nonplanar iif it contains a
subgraph homeomorphic to K3,3 or K5
Proof is neglected
e
a b c
a d
b c d e f
Ch. 9.5, 9.7 & 9.8 45
Example
H and K5 are homeomorphic
Determine whether the H can be obtained from K5
following graph is planar by removing {g,e} and
adding {g,f} and {f,e}
j i
g g g
k f h f
a e a e a e
d
b c b c b c
G HG H K5
As G contains a subgraph (H) homeomorphic to
K5, it is not planar
Ch. 9.5, 9.7 & 9.8 46
Coloring
Two regions sharing a border
are assigned different colors
Represent a map by
a graph (called Dual Graph)
Vertex: Region c
Edge: Constraint a d
the color cannot be the
same for adjacent regions b
Map Coloring
What is the largest complete graph
represented by a map?
Planar Planar Planar Planar nonPlanar
a c a c a
a a c b e
b b d c d
b c
d a
4 3 2 1
max min
Coloring
Chromatic number ( (G) )
The smallest number of colors needed to
produce a proper coloring of G
Coloring: Example
Complete Graph (K) Tree (T)
a
a
a b b c d
b e
e f g h i
c d c d j k l m
n
(T)= 2
(Keven)= n (Kodd)= n
a b a b a b a b
e f f e f e e f
g h d c d c g h
c d g h g h c d
Coloring
No formula for Chromatic number
Discussion
Given a graph of size k
> k: not possible
= k: for a complete graph
< k: other graphs except the complete one
Analyzing a subgraph of a graph may be helpful
If a subgraph is complete of size k, ≥ k
C
Bipartite
C C
B D E E
B B
A E A D A D
F F F
Ch. 9.5, 9.7 & 9.8 55
Coloring: Application 2
Examination of subject S1 S2 S3 S4
Vertex: Course
3
Edge: a student take
the two courses
A C A C A C
D J D J D J
Bipartite
Coloring: Application 3
1 1
7 2 7 2
6 3 6 3
5 4 5 4
1
K4
1 1
7 2
7 2 7 2
6 3
6 3 6 3
5 4 5 4 5 4
Bipartite 1
Answer is 4 7 2
7 is not
connected to 4 6 3
5 4
Ch. 9.5, 9.7 & 9.8 58