0% found this document useful (0 votes)
12 views553 pages

Ds Final Syllabus Compiled

The document covers predicates and quantifiers in discrete mathematics, focusing on predicate logic, universal and existential quantifiers. It explains how predicates function as declarative statements with variables, and how quantifiers express the extent of truth over a range of elements. The document also includes examples and exercises to illustrate these concepts.

Uploaded by

fa24-bcs-099
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views553 pages

Ds Final Syllabus Compiled

The document covers predicates and quantifiers in discrete mathematics, focusing on predicate logic, universal and existential quantifiers. It explains how predicates function as declarative statements with variables, and how quantifiers express the extent of truth over a range of elements. The document also includes examples and exercises to illustrate these concepts.

Uploaded by

fa24-bcs-099
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 553

CSC102 - Discrete Structures

(Discrete Mathematics)
Lecture # 6
Lecture Outline

• Ch. 1.4 Predicates and Quantifiers


– Predicate Logic/First Order Logic
– Quantifier
– Universal, Existential
– Translation of Quantified Statements
Predicate Logic
Or
First Order Logic
Predicates

• A predicate is a declarative statement with at least one


variable (i.e. unknown value).

• A predicate, or propositional function,(usually denoted


by P,Q,R etc.) is a function that takes some variable(s) as
arguments and returns True or False.
Propositional Function- Definition

• In the statements “x is less than 5” or (x <5)


The variable x: subject of the statement
“is less than 5”: predicate
P(x): propositional function P at x (P(x) becomes a proposition when x is
assigned a certain value)
• Consider P(x) = x < 5
P(x) has no truth values (x is not given a value)
P(1) is true: The proposition 1<5 is true
P(10) is false: The proposition 10<5 is false
Thus P(x) will create a proposition when x is given a certain value
Predicate Logic

Proposition, YES or NO?

10+4= 14 YEs

X+2=5 NO
X + 2 = 5 for all of X in {1, 2, 3} No
X + 2 = 5 for some X in {1, 2, 3}
YES
Why Predicate Logic
• Propositional Logic is not expressive enough
– It cannot adequately express the meaning of statements in mathematics
and in natural language
How can we express
⚫ “every computer in CS department is protected by intrusion detection
system”
⚫ “There are some student who have brown hair”.
No rules of propositional logic allow us to conclude the truth of the
statement.
• Predicate Logic is more expressive and powerful
Propositional Functions-Examples

• Let P(x) = “x is a multiple of 5”


For what values of x is P(x) true?
• Let P(x) = x + 3=7
For what values of x is P(x) true?
• Let A(x) = “Computer x is under attack by an intruder.”
Suppose computers on campus, only CS2 and MATH1 are currently under attack by
intruders.
What are truth values of A(CS1), A(CS2), and A(MATH1)?
Propositional Functions-Examples

Let P(x) = “the word x contains the letter a.”


What are these truth values?
P(orange)
P(lemon)
P(true)
P(false)
Propositional Functions (multiple varaibles)

⚫Functions with multiple variables:


▪ P(x,y) = x + y == 0
P(1,2) is ----, P(1,-1) is -----
▪ Q(x,y,z) = x + y == z
Q(3,4,5) is ---- Q(1,2,3) is -----
▪ P(x1,x2,x3 … xn) = …
⚫Anatomy of a propositional function
P(x,y) = x + 5 > y

variables predicate
Predicates-Exercises

Suppose Q(x,y) = “x > y”

Q(3,4)
Q(7,9)

Let Q(x) be the statement “x + 1 > 2x.” If the domain consists


of all integers, what are these truth values?
a) Q(0) b) Q(-2) c) Q(2)
Quantification
Quantification

⚫Quantification expresses the extent to which a predicate is


true over a range of elements.

⚫In English, the words all, some, many, none, and few are
used in quantifications.

⚫The area of logic that deals with predicates and quantifiers is


called the predicate calculus.
Quantifiers

Types of Quantifiers

⚫A quantifier is “an operator that limits the variables of a


propositional function”

⚫Two types:
▪ Universal
▪ Existential
Universal Quantifiers - Definition
• The universal quantification of P(x) is the
statement “P(x) for all values of x in the domain.”

• The notation ∀ , upside-down A, represents universal


quantifier.

• ∀x P(x) denotes the universal quantification of P(x).

• We read ∀xP(x) as “for all xP(x)” or “for every xP(x).”

• An element for which P(x) is false is called a


counterexample of ∀xP(x).
Universal quantifiers
Let P(x) = x+1 > x
We can state the following:
▪ x P(x)
▪ English translation: “for all values of x, P(x) is true”
▪ English translation: “for all values of x, x+1>x is
true”

Universal quantifier for all can be expressed in


many other ways: “for every”, “all of”, “for
each”, “given any”, “for arbitrary”, and “for
any”.
Universal quantifiers-Domain

specify the universe of quantification!


The domain must always be specified when a universal
quantifier is used; without it, the universal
quantification of a statement is not defined.
– What values 𝑥 can represent
– Called the “domain of discourse” or “universe of
discourse”
– Or just “domain” or “universe”

• The meaning of the universal quantification of P(x)


changes when we change the domain.
Universal quantifiers

⚫ In order to prove that a universal quantification is true, it


must be shown for ALL cases

⚫ In order to prove that a universal quantification is false, it


must be shown to be false for only ONE case

⚫ Given some propositional function P(x) And values in the


universe x1 .. xn

The universal quantification x P(x) implies:


P(x1)  P(x2)  …  P(xn)

Note: AND of all predicates , as to prove universal quantification


is true, it must be true for ALL cases
Universal quantifiers -example

⚫ Let the universe of discourse be the real numbers.

P(x) = x/2 < x

▪ Not true for the negative numbers.

▪ Thus, x P(x) is false as domain is all the real


numbers
Universal quantification- Example

• Let P(x) is “𝑥 2 > 0.” To show that the


statement ∀xP(x) is false where the universe
of discourse consists of all integers, we give a
counterexample.

• x = 0 is a counterexample because 𝑥 2 = 0
when x = 0, so that 𝑥 2 is not greater than 0
when x = 0.
Universal quantification- Example

• What is the truth value of ∀𝑥 𝑃 (𝑥), where 𝑃(𝑥) is


the statement x 2 < 10 and the domain consists of
the positive integers not exceeding 4?

Solution:
• The statement ∀𝑥𝑃(𝑥) is the same as the
conjunction
𝑃 1 ∧ 𝑃 2 ∧ 𝑃 3 ∧ 𝑃(4),
• Because 𝑷 𝟒 ≡ 𝟒𝟐 < 𝟏𝟎, is false, it follows that
∀𝒙 𝑷(𝒙) is false.
Universal quantification- Example

• What does the statement ∀xN(x) mean if


N(x) is “Computer x is connected to the network”
domain = all computers on campus
Solution: The statement ∀xN(x) means that
“For each computer x on campus, that computer
x is connected to the network”.
OR
“Every computer on campus is connected to the
network.”
Existential quantification

The existential quantification of P(x) is the proposition


“There exists an element x in the domain such that P(x).”

⚫ Represented by a backwards E: 
▪ It means “there exists”
▪ Let P(x) = x+1 > x
⚫ We can state the following:
x P(x)
▪ English translation: “there exists (a value of) x such that P(x) is true”
▪ English translation: “for at least one value of x, x+1>x is true”
▪ English translation: “for some x, P(x)”
Existential quantification

⚫Let P(x) = x== 8, Where domain is set of all integers.


▪ There is a numerical value for which x==8
▪ In fact, it’s true for only one value of the values of x
▪ Thus,  x P(x) is true

⚫Let P(x) = x+1 < x, Where domain is set of all integers.


▪ There is no numerical value x for which x+1<x
▪ Thus, x P(x) is false
Existential quantification

⚫In order to show an existential quantification


is true, you only have to find ONE value
⚫In order to show an existential quantification
is false, you have to show it’s false for ALL
values
⚫You still have to specify your universe or
domain for variables.
– The meaning of ∃xP(x) changes when the domain
changes.
– Without specifying the domain, the statement
∃xP(x) has no meaning.
Existential quantification

⚫Given some propositional function P(x) And values in the


universe x1 .. xn

⚫The existential quantification x P(x) implies:

P(x1)  P(x2)  …  P(xn)

It is true if P(x) is true for at least one value of x in the


domain
Existential Quantification

• Example: Let P(x) denote the statement “x > 3.”


What is the truth value of the quantification
∃xP(x), where the domain consists of all real
numbers?

Solution: Because “x > 3” is sometimes true—for


instance, when x = 4 the existential quantification
of P(x), which is ∃xP(x), is true.
Existential Quantification

• Example: Let Q(x) is “x ==x + 1.”


What is the truth value of the quantification
∃xQ(x), where the domain consists of all real
numbers?

• Solution: Because Q(x) is false for every real


number x, the existential quantification of
Q(x), which is ∃xQ(x), is false.
Uniqueness Quantification

• Denoted by ∃! or ∃1
• The notation ∃!xP(x) [or ∃xP(x)] states “There
exists a unique x such that P(x) is true.”
• “there is exactly one” and “there is one and
only one.”
Example: ∃!x(x - 1 = 0), where the domain is the
set of real numbers.
There is a unique real number x such that x - 1 =
0. This is a true for x = 1 only.
Summary

Statement When True? When False?


xP(x) P(x) is true for every x. There is an x for which P(x) is
false.

∃x P(x) There is an x for which P(x) is false for every x.


P(x) is true.
Binding variables

• When a quantifier is used on a variable x, we say that


this occurrence of the variable is bound.

• An occurrence of a variable that is not bound by a


quantifier or not set equal to a particular value is said
to be free.

• The part of a logical expression to which a quantifier is


applied is called the scope of the quantifier.

• All the variables that occur in a logical expression must


be bound or set equal to a particular value to turn into
a proposition.
Free and bound variables
⚫A variable is bound if it is known or
quantified. Otherwise, it is free.

⚫Examples:
⚫P(x) ⚫x is free
⚫P(5) ⚫x is bound to 5
⚫x P(x)
⚫x is bound by quantifier
Scope of quantifier

• x (P(x)  Q(x))  (xR(x))


» All variables are bound.
• The scope of the first quantifier, ∃x, is the
expression P(x) ∧ Q(x) because ∃x is applied only
to P(x) ∧ Q(x), and not to the rest of the
statement.
• Similarly, the scope of the second quantifier, ∀x,
is the expression R(x).
• That is, the existential quantifier binds the
variable x in P(x) ∧ Q(x) and the universal
quantifier ∀x binds the variable x in R(x).
Binding variables -Exercise
⚫(x P(x))  Q(x)
▪ The x in Q(x) is not bound; thus not a proposition
⚫(x P(x))  (x Q(x))
▪ Both x values are bound; thus it is a proposition
⚫(x P(x)  Q(x))  (y R(y))
▪ All variables are bound; thus it is a proposition
⚫(x P(x)  Q(y))  (y R(y))
▪ The y in Q(y) is not bound; thus not a proposition
Universal quantification- Example

B(x) = “x is wearing sneakers.”


L(x) = “x is at least 21 years old.” Universe of discourse
is students in this
Y(x)= “x is less than 24 years old.” room.

Are either of these propositions true?

a) x (Y(x) → B(x))
b) x (Y(x)  L(x))
Chapter Reading

• Chapter 1, Kenneth H. Rosen, Discrete Mathematics and Its


Applications, Section 1.4

Chapter Exercise (For Practice)

Question # 1, to 8
CSC102 - Discrete Structures
(Discrete Mathematics)
Lecture # 8
Lecture Outline
• Ch. 1.4 Predicates and Quantifiers
– Translation of Quantified Statements
– Negating Quantified Statements
– Four Aristotelian forms
Summary

Statement When True? When False?


xP(x) P(x) is true for every There is an x for which
x. P(x) is false.

∃x P(x) There is an x for P(x) is false for every x.


which P(x) is true.
Quantifiers with Restricted
Domain
Quantifiers with Restricted Domain

• An abbreviated notation is often used to


restrict the domain of a quantifier.
• In this notation, a condition (a variable must
satisfy ) is included after the quantifier.

• ∀𝑥 < 0 𝑥 2 > 0 where domain is real


numbers
Restricted Domain-Rule for universal
Quantification

• ∀𝑥 < 0 𝑥 2 > 0 ≡ ∀𝑥 (𝑥 < 0) → (𝑥 2 > 0)

• The restriction of a universal quantification is


the same as the universal quantification of a
conditional statement.
Restricted Domain-Rule for universal
Quantification

∀𝑦 ≠ 0 𝑦 3 ≠ 0

≡ ∀𝑦 𝑦 ≠ 0 → 𝑦 3 ≠ 0
Restricted Domain-Rule for
Existential Quantification

• ∃𝑧 > 0 𝑧 2 = 2 ≡ ∃𝑧 𝑧 > 0 ∧ 𝑧 2 = 2

• The restriction of an existential quantification


is the same as the existential quantification of
a conjunction.
Precedence of Quantifiers

⚫The quantifiers  and  have higher


precedence then all logical operators
from propositional calculus.

⚫ e.g x P(x)  Q(x) is the disjunction of


x P(x) and Q(x).
A Note on quantifiers
• Recall that a proposition is a statement that is either true
or false
– P(x) is not a proposition

• Recall that P(x) is a propositional function/Predicate


– Let P(x) be “x == 0”

• There are two ways to change a propositional function into


a proposition:
– Supply it with a value
» For example, P(5) is false, P(0) is true
– Provide a quantification
» For example, x P(x) is false and x P(x) is true
» Let the universe of discourse be the real numbers
Translating From English

• Express the statement “Every student in this


class has studied calculus” using predicates
and quantifiers.
• Solution:
“For every student x in this class, x has studied
calculus.”
Domain: Class
C(x) = “x has studied calculus.”

∀xC(x)
Translating From English
Re-express the statement with domain for all people.
“For every person x, if person x is a student in this class then x
has studied calculus.”
Let C(x) = “x has studied calculus.”
S(x) = “person x is a student in this class.”
The domain for x consists of all people.

• The statement can be expressed as ∀x(S(x) → C(x)).

Note: Our statement cannot be expressed as ∀x(S(x) ∧ C(x))


because this statement says that all people are students in this
class and have studied calculus!
Translating From English to Logical Expressions

• Let R(x) = “x can speak Russian”


C(x) = “x knows the computer language C++.”

The domain for quantifiers consists of all students of university.

• Some student in your university can speak Russian and know C++ .

∃𝒙 𝑹 𝒙  𝑪 𝒙
Translating From English to Logical Expressions

• Let R(x) = “x can speak Russian”


C(x) = “x knows the computer language C++.”

• There is a student in the university who can


speak Russian but who doesn’t know C++.

∃𝒙 𝑹 𝒙  ¬𝑪 𝒙
Translating From English to Logical Expressions

• Let R(x) = “x can speak Russian”


C(x) = “x knows the computer language C++.”

• Every student either can speak Russian or knows C++.

∀𝒙 𝑹 𝒙 𝑪 𝒙
Translating From English to Logical Expressions

• Let R(x) = “x can speak Russian”


C(x) = “x knows the computer language C++.”

• No student can speak Russian or knows C++.

∀𝒙¬ 𝑹 𝒙 𝑪 𝒙 /¬∃𝒙 𝑹 𝒙 𝑪 𝒙
Negating Quantified Expressions

• Negation of Universal Quantification


“Every student in this class has studied calculus.”
• This statement is a universal quantification, namely, ∀xC(x),
– C(x) is the statement “x has studied calculus”
– Domain consists of the students in the class.
• The negation of this statement is
– “It is not the case that every student in this class has studied calculus.”
– This is equivalent to “There is a student in this class who has not studied
calculus.”
• This is simply the existential quantification of the negation of the
original propositional function, namely, ∃x ¬C(x).
Negating Quantified Expressions
• Negation of Existential Quantification
What is the negation of the statement “There is an honest
politician”?

Solution:
• Let H(x) denote “x is honest politician.”
• The statement is represented by ∃xH(x), where the domain consists
of all politicians.
• Negation= It is not the case that there is an honest politician(not
even a single one). Which means every politician is dishonest. ∀x
¬H(x)
Negating Quantified Expressions

Negation Equivalent When is When False?


Statement Negation
True?
¬∃x P(x) ∀x ¬ P(x) For every x, There is an x
P(x) is false. for which
P(x) is true.

¬∀x P(x) ∃x ¬ P(x) There is an x P(x) is true for


for which P(x) every x.
is false.
Negating Quantified Expressions
• Consider the statement:
– All students in this class have red hair

• What is required to show the statement is false?


– There exists a student in this class that does NOT
have red hair

• To negate a universal quantification:


– change to an existential quantification
– negate the propositional function
– ¬x P(x) = x ¬P(x)
Negating Quantified Expressions

Example:
What is the negation of the statement “All Americans eat
cheeseburgers”?
Solution:
• C(x) denote “x eats cheeseburgers.”
• The statements represented by ∀xC(x), where the domain
consists of all Americans.
• The negation of this statement is ¬∀xC(x), which is equivalent
to ∃x¬C(x).
• This negation can be expressed as “Some American does not
eat cheeseburgers” and “There is an American who does not
eat cheeseburgers.”
Negating Quantified Expressions
Negating Quantified Expressions

x ( x  x )
2
x ( x = x )
2

 x ( x  x )
2
 x ( x = x )
2

 x( x  x )
2
 x( x = x )2

 x ( x  x )
2
 x ( x  x )
2
De Morgan’s Laws for Quantifiers

• 𝑥 𝑃(𝑥) ≡ 𝑃(𝑥1)  𝑃(𝑥2)  …  𝑃(𝑥𝑛)


• ∃𝑥𝑃 𝑥 ≡ 𝑃(𝑥1 )  𝑃(𝑥2 )… . 𝑃 𝑥𝑛

• ¬∃𝑥𝑃 𝑥 ≡ ¬(𝑃(𝑥1 )  𝑃(𝑥2 )… . 𝑃 𝑥𝑛 )


≡ ¬𝑃(𝑥1 )  ¬𝑃(𝑥2 )  … . ¬(𝑃 𝑥𝑛 )
≡ ∀𝑥¬𝑃(𝑥)

• ¬∀𝑥𝑃 𝑥 ≡ ¬(𝑃(𝑥1 )  𝑃(𝑥2 )  … . 𝑃 𝑥𝑛 )


≡ ¬𝑃(𝑥1 )  ¬𝑃(𝑥2 )  … . ¬(𝑃 𝑥𝑛 )
≡ ∃𝑥¬𝑃(𝑥)
The Four Aristotelian Forms

These are four of the most common quantificational


sentences used in quantificational reasoning.

1. All A's are B's


2. Some A's are B's
3. No A's are B's
4. Some A's are not B's
The First Aristotelian Form
• The Form: All A's are B’s

• Example: All comedian are funny.


– Rephrase: For every x, if x is a comedian then x is
funny
– Translation: ∀x (Comedian(x) → Funny(x))
– This translation has the form: ∀x (A(x) → B(x))

• General Fact
– All A's are B's translates as ∀x (A(x) → B(x))
The Second Aristotelian Form

• The Form: Some A's are B’s

• Example: Some comedian are funny


– Rephrase: Some thing x is both comedian and funny
– Translation: x (Comedian(x)  Funny(x))
– This translation has the form: x (A(x)  B(x))

• General Fact
– Some A's are B's translates as x (A(x)  B(x))
The Third Aristotelian Form

• The Form: No A's are B’s

• Example: No students are failed


– Rephrase: For every x, if x is a student then x is not
failed
– Translation: ∀x (Student(x) → Failed(x))
– This translation has the form: ∀x (A(x) → B(x))

• General Fact
– No A's are B's translates as ∀x (A(x) → B(x))
The Fourth Aristotelian Form
• The Form: Some A's are not B’s

• Example: Some excuses are not believable


– Rephrase: For some x, x is an excuse and x is not
believable
– Translation: x (Excuse(x)  Believable(x))
– This translation has the form: x (A(x)  B(x))

• General Fact
– Some A's are not B's translates as x (A(x)  B(x))
Summary

• The Aristotelian Forms and Their Translations

– All A's are B's ∀x (A(x) → B(x))


– Some A's are B's x (A(x)  B(x))
– No A's are B's ∀x (A(x) → B(x))
– Some A's are not B’s x (A(x)  B(x))
Predicates - Examples
L(x) = “x is a lion.”
F(x) = “x is fierce.”
C(x) = “x drinks coffee.”
Assuming that the domain consists of all creatures.

• All lions are fierce.


x (L(x) → F(x))
• Some lions don’t drink coffee.
x (L(x)  C(x))
• Some fierce creatures don’t drink coffee.
x (F(x)  C(x))
Chapter Reading and Exercises

• Chapter 1, Kenneth H. Rosen, Discrete Mathematics and Its


Applications, Section 1.4

• Question # 1 to 14, 17, 18, 33,35, 61(a, b, c), 62( a, b, c), 63(a, b,
c, d)
CSC102 - Discrete Structures
(Discrete Mathematics)
Lecture # 10
Lecture Outline
• Ch. 1.6 Rules of Inference

• Rules of Inference
– What is an argument and argument form?
– Rules of inference
– Proof using rules of Inference
– Fallacy
Rules of Inference

• Rules of inference are templates for


constructing valid arguments.

• Rules of inference are basic tools for


establishing the truth of statements.

• Valid means that the conclusion of the


argument must follow from the truth of the
preceding statements of the argument.
Argument
• An Argument is a sequence of propositions,
that end with conclusion.

1. “If you have the current password, then you


can log onto the network.”
2. “You have a current password.”
Therefore,
3. “You can log onto the network.”
Premises and Conclusion

1. If you have the current password,


then you can log onto the network.” Premises
2. “You have a current password.”

Therefore,
Conclusion
3. “You can log onto the network.”

• All but the final proposition are called premises.


• The final proposition is called the conclusion.
Valid Arguments
1. If you have the current password,
then you can log onto the network.” Premises true
2. “You have a current password.”

Therefore,

3. “You can log onto the network.” Conclusion true

• An argument is valid if the truth of all premises implies


that conclusion is true.
Valid Arguments
• An Argument form in propositional logic is sequence
of compound propositions involving propositions
variables.

• An argument form is valid if no matter which


particular propositions are substituted for the
propositional variables in its premises, the
conclusion is true if the premises are all true.

• An argument form is valid if the truth of all premises


implies that conclusion is true.
– i.e. (p1  p2  …  pn) → q is a tautology
Valid Arguments
1. “If you have the current password, then you
can log onto the network.”
2. “You have a current password.”
Therefore,
3. “You can log onto the network.”
Valid Arguments (Argument Form)
1. “If you have the current password, then you
can log onto the network.”
2. “You have a current password.”
Therefore,
3. “You can log onto the network.”
Argument form: Hypothesis
1
1. If p, then q p→q
2. p p Hypothesis
therefore 2
3. q q q
Conclusion
Rules of Inference

Rule of inference: use to validate or invalidate a logical


implication without resorting to truth table (which will
be large if the number of variables are large)

• Modus Ponens/ Rule of Detachment


• Modus Tollens
• Addition
• Simplification
• Conjunction
• Rules of Syllogism
• Rule of resolution
Modus Ponens

• In particular, modus ponens tells us that if a


conditional statement and the hypothesis of
this conditional statement are both true, then
the conclusion must also be true.

p Tautology:
p→q
q (p  (p → q)) → q
Modus Ponens
• The tautology (p  (p→q)) → q is basis of
modus ponens.
p q p→q p(p→q)) (p(p→q)) → q
T T T T T
T F F F T
F T T F T
F F T F T

p Tautology:
p→q
q (p  (p → q)) → q
Modus Ponens Example

• Assume you are given the following two


statements:
– “you are in this class”
– “if you are in this class, you will get a grade”

• Let p = “you are in this class”


• Let q = “you will get a grade”

• By Modus Ponens, you can conclude that “you


will get a grade”.
Modus Ponens Example

• Consider the following statements


– “If it snows today, then we will stay at home”
– “It is snowing today”

• Let p = “it is snowing today”


• Let q =“we will stay at home”
Modus Ponens Example
• Consider the following statements
– “If it snows today, then we will stay at home”
– “It is snowing today”

• Let p = “it is snowing today”


• Let q =“we will stay at home”

• By Modus Ponens, you can conclude that “We


will stay at home”.
Modus Tollens
• Assume that we know: ¬q and p → q
– Recall that p → q  ¬q → ¬p
• Thus, we know ¬q and ¬q → ¬p
• We can conclude ¬p

q
Tautology:
p→q
(q  (p → q)) → p
p
Modus Tollens Example
• Assume you are given the following two
statements:
– “you will not get a grade”
– “if you are in this class, you will get a grade”

• Let p = “you are in this class”


• Let q = “you will get a grade”

• By Modus Tollens, you can conclude that you


are not in this class
Modus Tollens Example-2

I am not a great skater.


If I am Erik, then I am a great skater.

 I am not Erik!
q Tautology:
p→q (q  (p → q)) → p

 p
Addition & Simplification
• Addition: If you know that p is true, then p  q will
ALWAYS be true i.e. p → p  q
p Tautology:
pq p → (p  q)

• Simplification: If p  q is true, then p will ALWAYS be true


i.e. p  q → p
Tautology:

pq (p  q) → p

p
Addition Example

• Assume you are given the following statements:


• “ It is below freezing now.
• Therefore, “it is either below freezing or raining now”

• Let p = “It is below freezing now”.


• Let q = “It is raining now”.

• Then this argument is of the form


p
pq
Simplification Example
• Assume you are given the following statements:
• “ It is below freezing and raining now”.
• Therefore, “it is below freezing now”

• Let p = “It is below freezing now”.


• Let q = “It is raining now”.

• This argument is of the form


pq
p
Disjunctive Syllogism

I am a great eater or I am a great skater.


I am not a great skater.

 I am a great eater!

pq Tautology:
q ((p  q)  q) → p
p
Hypothetical Syllogism

• If p → q is true, and q → r is true, then p → r


must be true

p→q
Tautology:
q→r
((p → q)  (q → r)) → (p → r)
∴p→r
Hypothetical Syllogism Example
• Assume you are given the following
statements:
“If it rains today, then we will not have a
barbecue today”.
“If we do not have a barbecue today, then we
will have a barbecue tomorrow”.
Therefore,
“if it rains today, then we will have a barbecue
tomorrow”.
Hypothetical Syllogism Example
• Assume you are given the following statements:
• If it rains today, then we will not have a barbecue
today. If we do not have a barbecue today, then we will
have a barbecue tomorrow. Therefore, if it rains today,
then we will have a barbecue tomorrow.

• Let p = “It is raining today,”


• Let q = “We will not have a barbecue today,”
• Let r =“We will have a barbecue tomorrow.”
Hypothetical Syllogism Example
• Assume you are given the following statements:

“If it rains today, then we will not have a barbecue today”. “If we do not
have a barbecue today, then we will have a barbecue tomorrow”.
Therefore,
“ if it rains today, then we will have a barbecue tomorrow”.

• Let p = “It is raining today,”


• Let q = “We will not have a barbecue today,”
• Let r =“We will have a barbecue tomorrow.”

• Then this argument is of the form


p→q
q→r
∴p→r
Summary: Rules of Inference
Rules of Inference Tautology Name
p (p ∧ (p → q)) → q Modus ponens
p→q
∴q
¬q (¬q ∧ (p → Modus tollens
p→q q))→¬p
∴ ¬p
p→q ((p → q) ∧ (q → r)) Hypothetical
q→r → (p → r) syllogism
∴p→r
p∨q ((p ∨ q)∧¬p) → q Disjunctive
¬p syllogism
∴q
Summary: Rules of Inference

Rules of Inference Tautology Name


p p → (p ∨ q) Addition
∴p∨q
p∧q (p ∧ q) → p Simplification
∴p
p ((p) ∧ (q)) → (p ∧ q) Conjunction
q
∴p∧q
p∨q ((p ∨ q) ∧ (¬p ∨ r)) Resolution
¬p ∨ r → (q ∨ r)
∴q∨r
Exercise
• What rule of inference is used in each of these arguments?

a) “Alice is a mathematics major”. Therefore, “Alice is either a


mathematics major or a computer science major”.
Addition

b) “Jerry is a mathematics major and a computer science major”.


Therefore, “Jerry is a mathematics major”.
Simplification

c) “If it is rainy, then the pool will be closed”. “It is rainy”.


Therefore, “the pool is closed”.
Modus Ponens
Exercise

d) If it snows today, then university will close. The university is


not closed today. Therefore, it did not snow today.
Modus Tollens

e) If I go swimming, then I will stay in the sun too long. If I stay in


the sun too long, then I will sunburn. Therefore, if I go
swimming, then I will sunburn.
Hypothetical Syllogism
Exercise-Validity of Argument
Find the argument form for the following argument and
determine whether it is valid. Can we conclude that the
conclusion is true if the premises are true?
If George does not have eight legs, then he is not
a spider. George is a spider. Therefore George
has eight legs.
Exercise
What rule of inference is used in each of these arguments?
a) Kangaroos live in Australia and are marsupials.
Therefore, kangaroos are marsupials.

b) It is either hotter than 100 degrees today or the


pollution is dangerous. It is less than 100 degrees
outside today. Therefore, the pollution is dangerous.

c) Linda is an excellent swimmer. If Linda is an excellent


swimmer, then she can work as a lifeguard. Therefore,
Linda can work as a lifeguard.
Exercise

d) Steve will work at a computer company this summer.


Therefore, this summer Steve will work at a computer
company or he will be on vacations.

e) If I work all night on this homework, then I can answer


all the exercises. If I answer all the exercises, I will
understand the material. Therefore, if I work all night on
this homework, then I will understand the material.
Chapter Reading

• Chapter 1, Kenneth H. Rosen, Discrete


Mathematics and Its Applications, Section 1.6
Chapter Exercise (For Practice)

Section 1.6: Question # 1 to 10, 13


CSC102 - Discrete Structures
(Discrete Mathematics)
Lecture # 11-12
Lecture Outline
• Ch. 1.6 Rules of Inference

– Rules of inference
– Proof using rules of Inference
– Fallacy
– Rules of inference with quantifiers
Summary: Rules of Inference
Rules of Inference Tautology Name
p (p ∧ (p → q)) → q Modus ponens
p→q
∴q
¬q (¬q ∧ (p → Modus tollens
p→q q))→¬p
∴ ¬p
p→q ((p → q) ∧ (q → r)) Hypothetical
q→r → (p → r) syllogism
∴p→r
p∨q ((p ∨ q)∧¬p) → q Disjunctive
¬p syllogism
∴q
Summary: Rules of Inference

Rules of Inference Tautology Name


p p → (p ∨ q) Addition
∴p∨q
p∧q (p ∧ q) → p Simplification
∴p
p ((p) ∧ (q)) → (p ∧ q) Conjunction
q
∴p∧q
p∨q ((p ∨ q) ∧ (¬p ∨ r)) Resolution
¬p ∨ r → (q ∨ r)
∴q∨r
Steps for Proof

1. Identify the atomic propositions and


represent using propositional variable.
2. Make the argument from
3. Proof using rules of inference
Example -1 Proof
Argument:

It is not sunny this afternoon and it is colder


than yesterday; We will go swimming only if it is
sunny this afternoon. If we do not go swimming,
then we will take a canoe trip. If we take a
canoe trip, then we will be home by sunset.
Therefore we will be home by sunset.

Step1: Identify the atomic propositions and


represent using propositional variable.
Example-1 Proof
Step1: Identify the atomic propositions and represent using
propositional variable.

We have four hypotheses:


H1: “It is not sunny this afternoon and it is colder than
yesterday”
H2: “We will go swimming only if it is sunny this afternoon”
H3: “If we do not go swimming, then we will take a canoe trip”
H4: “If we take a canoe trip, then we will be home by sunset”

Conclusion: “we will be home by sunset”

s = “It is sunny this afternoon”


c = “it is colder than yesterday”
m = “We will go swimming”
t = “we will take a canoe trip”
h = “we will be home by sunset”
Example-1 Proof
Step2: Make the argument from
– H1: “It is not sunny this afternoon and it is colder than yesterday”
– H2: “We will go swimming only if it is sunny this afternoon”
– H3: “If we do not go swimming, then we will take a canoe trip”
– H4: “If we take a canoe trip, then we will be home by sunset”

H1: s  c
H2: m→ s
H3: m → t
H4 t →h
C:  h
(( s  c)  (m → s)  ( m → t)  (t → h)) → h ???
Example-1 of Proof H1: s  c
H2: m→s
Step3: Proof using rules of inference H3: m → t
H4 t→h

1. ¬s  c H1 C:  h

2. ¬s Simplification using step 1


3. m → s H2
4. ¬m Modus tollens using steps 2 & 3
5. ¬m → t H3
6. t Modus ponens using steps 4 & 5
7. t → h H4
8. h Modus ponens using steps 6 & 7
Hence we get conclusion, h
Example-2 Proof
• “If it does not rain or it is not foggy, then the sailing race will be
held and the lifesaving demonstration will go on”
( r   f) → (s  d)

• “If the sailing race is held, then the trophy will be awarded”
s→t

• “The trophy was not awarded” H1: (¬𝑟 ∨ ¬𝑓) → (𝑠 ∧ 𝑑)


t H2: s→𝑡
H3: ¬𝑡
C: ∴𝑟
• Can you conclude: “It rained”?
Example-2 of Proof H1: (r  f ) → ( s  d )
H2: s → t
H3: t

1. ¬t 3rd hypothesis
C: r
2. s→t 2nd hypothesis
3. ¬s Modus tollens using steps 1 & 2
4. (¬r¬f)→(sd) 1st hypothesis
5. ¬(sd)→¬(¬r¬f) Contrapositive of step 4
6. (¬s¬d)→(rf) De Morgan’s and double negation law
7. ¬s¬d Addition from step 3
8. rf Modus ponens using steps 6 & 7
9. r Simplification using step 8
Example-3 Proof
• We have hypotheses
“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”
The conclusion “If I do not finish writing the program, then I will
wake up feeling refreshed.”

• Let p = “You send me an e-mail message,” H1: p → q


• q = “I will finish writing the program,” H2: p → r
• r = “I will go to sleep early,”
• s = “I will wake up feeling refreshed.” H3: r→s
C: q → s
Example-3 Proof H1: p→q
H2: p → r
H3: r→s
1. p→q 1st Hypothesis C: q → s
2. ¬q →¬p Contrapositive of 1

3. ¬p → r 2nd Hypothesis

4. ¬q → r Hypothetical syllogism using 2 and 3

5. r→s 3rd Hypothesis

6. ¬q → s Hypothetical syllogism using 4 and 5


Fallacies

• Rule of inference: are valid argument form


that can be used to demonstrate that
arguments are valid.

• Fallacy: An invalid argument form often used


incorrectly as a rule of inference (or
sometimes, more generally, an incorrect
argument)
Fallacies
Example - Fallacies
• If you do the every problem in this book, then you
will learn discrete mathematics. You learned discrete
mathematics
Therefore
You did every problem in this book
Let p = “you do the every problem in this book”
q = “you learned discrete mathematics”

p→q
q
p
Rules of Inference for Quantified
Statements
Rule of Inference Name
∀xP(x)
Universal instantiation
∴ P(c)
P(c) for an arbitrary c
Universal generalization
∴ ∀xP(x)

∃xP(x)
Existential instantiation
∴ P(c) for some element c
P(c) for some element c
Existential generalization
∴ ∃xP(x)
Rules of Inference for the Universal Quantifier

• Assume that we know that x P(x) is true, Then we can


conclude that P(c) is true
– Here c is particular value in domain
– This is called “universal instantiation”
– Example: All women are wise therefore Lisa is wise.

• Assume that we know that P(c) is true for all value of c in


domain
– Then we can conclude that x P(x) is true
– This is called “universal generalization”
– Example: Student s has taken calculus therefore All students
has taken calculus.
Example x( D ( x) → C ( x ))
D ( Ali )
 C ( Ali )
• Given the hypothesis:
“Everyone in this discrete mathematics class has taken a
course in computer science” and “Ali is in this discrete
mathematics class” imply the conclusion “Ali has taken a
course in computer science.”

• Let D(x) = “x is in this discrete mathematics class,”


• Let C(x) = “x has taken a course in computer science.”

• The hypothesis are ∀x(D(x) → C(x)) and D(Ali).


• The conclusion is C(Ali).
Example x( D ( x) → C ( x ))
D ( Ali )
 C ( Ali )
• The following steps can be used to establish the conclusion from
the hypothesis.

• Step Reason
1. ∀x(D(x) → C(x)) Hypothesis
2. D(Ali)→C(Ali) Universal instantiation from 1
3. D(Ali) Hypothesis
4. C(Ali) Modus ponens from 2 and 3
Rules of Inference for the Existential Quantifier
• Assume that we know that x P(x) is true then we can
conclude that P(c) is true for some value of c
– This is called “existential instantiation”.
– Example: There is a fish in a pool therefore Some fish a is in
pool.

• Assume that we know that P(c) is true for some value of c


Then we can conclude that x P(x) is true
– This is called “existential generalization”.
– Example: Ali is in the store therefore There is a person in store.
Example x(C ( x)  B ( x ))
x(C ( x) → P ( x ))
x( P ( x )  B ( x ))
• Given the hypothesis
“A student in this class has not read the book,” and “Everyone in
this class passed the first exam” imply the conclusion “Someone
who passed the first exam has not read the book.”

• Let C(x) = “x is student in this class,”


• Let B(x) = “x has read the book,”
• Let P(x) = “x passed the first exam.”

• The hypothesis are ∃x(C(x)∧¬B(x)) and ∀x(C(x) → P(x)).


• The conclusion is ∃x(P(x)∧¬B(x)).
Example Proof x(C ( x)  B( x))
x(C ( x) → P( x))
x( P( x)  B ( x))
1. ∃x(C(x)∧¬B(x)) Hypothesis
2. C(a)∧¬B(a) Existential instantiation from 1
3. C(a) Simplification from 2
4. ∀x(C(x) → P(x)) Hypothesis
5. C(a) → P(a) Universal instantiation from 4
6. P(a) Modus ponens from 3 and 5
7. ¬B(a) Simplification from 2
8. P(a)∧¬B(a) Conjunction from 6 and 7
9. ∃x(P(x)∧¬B(x)) Existential generalization from 8
Combination of Rules of Inference and Quantified
Statement
Universal Modus Ponens

• Universal Instantiation + Modus Ponens

• If x(P(x) →Q(x)) is true, and if P(a) is true for a particular


element ‘a’ in the domain of the universal quantifier, then Q(a)
must also be true.

x(P(x) →Q(x))
P(a), where a is a particular element in the domain

 Q(a)
Combination of Rules of Inference and Quantified
Statement
Universal Modus Tollens

• Universal Instantiation + Modus Tollens

• If x(P(x) →Q(x)) is true, and if Q(a) is false (or ¬Q(a) is true) for
a particular element ‘a’ in the domain of the universal quantifier,
then P(a) must also be false.

x(P(x) →Q(x))
¬Q(a), where a is a particular element in the domain

 ¬P(a)
Example of Proof

• Given the hypotheses:


– “Maria is a student in this class, owns a red
convertible.”
– “Everybody who owns a red convertible has gotten a
speeding ticket”
• Can you conclude: “Somebody in this class has gotten a
speeding ticket”?
• Let C(x) = “x is student in this class”.
• Let R(x) = “x has owns a red convertible”.
• Let T(x) = “x has gotten speeding ticket”.

• The hypothesis are x (R(x)→T(x)), C(Maria) and R(Maria).


• The conclusion is x (C(x)T(x)).
Example of Proof

1. x (R(x)→T(x)) Hypothesis
2. R(Maria) → T(Maria) Universal instantiation using 1
3. R(Maria) Hypothesis
4. T(Maria) Modes ponens using 2 and 3
5. C(Maria) Hypothesis
6. C(Maria)  T(Maria) Conjunction using 5 and 4
7. x (C(x)T(x)) Existential generalization using 6
Chapter Reading

• Chapter 1, Kenneth H. Rosen, Discrete


Mathematics and Its Applications, Section 1.6
Exercise Questions

Exercise 1.6: Q 1 to 9, 13, 19, 23, 24.


CSC102 - Discrete Structures
(Discrete Mathematics)
Lecture # 16-17
Chapter 2.1,2.2,8.5

Set
Lecture Outline
• Sets
– Set Terminologies
– Power Set
– Cartesian Product
– Set notation with Quantifier
– Set Operations
– Set Identities
– Membership Tables
– Inclusion-Exclusion Principle of Sets (8.5 From Rosen 8th
ed.)

5/9/2025 CSC102 - Discrete Structures 3


Application of Sets

• Databases
• Data-type or type in computer programming
• Constructing discrete structures
• Finite state machine
• Modeling computing machine
• Representing computational complexity of
algorithms
Set
• A set is an unordered collection of objects.
• The objects in a set are called the elements, or
members, of the set.
• A set is said to contain its elements.
Example:
– Cities in the Pakistan: {Lahore, Karachi, Islamabad, … }
– Sets can contain non-related elements: {3, a, red, Gilgit }
Properties:
• Order does not matter
– {1, 2, 3, 4, 5} is equivalent to {3, 5, 2, 4, 1}
• Sets do not have duplicate elements
– Consider the list of students in this class
– It does not make sense to list somebody twice
Specifying a Set
• Capital letters (A, B, S…) for sets
• Italic lower-case letter for elements (a, x, y…)
• Two ways of specifying set
– Roster method
– Set builder notation
Roster method
• Easiest way: list all the elements within curly braces, “{“ and “}”
– A = {1, 2, 3, 4, 5}, Not always feasible!
• May use ellipsis (…) to describe a set without listing all of its
elements : B = {0, 1, 2, 3, …}
May cause confusion. C = {3, 5, 7, …}. What’s next?
If the set is all odd integers greater than 2, it is 9
If the set is all prime numbers greater than 2, it is 11
Set Builder

• Set builder:
Characterize all elements in the set by stating properties they must
have.

• Example:
O= {x | x is an odd positive integer less than 10}
O= {x ∈ 𝒁+ | x is odd and x<10}
O= {1,3,5,7,9}
The vertical bar means “such that”
Important Sets

• Set of natural numbers


• 𝐍 = {1,2,3,…}
• Set of integers
• 𝐙 = {…,-2,-1,0,1,2,…}
• Set of positive integers
• 𝐙 + = {1,2,3,…}
• Set of rational numbers
• 𝐐 = {p/q | p ∈ 𝐙, q ∈ 𝐙, and q ≠ 0}

• Set of real numbers


• 𝐑
Set Membership

• a is an element of the set A, denoted by a ∈ A.

• a is not an element of the set A, denoted by a ∉ A.

• S1 = { N, Z, Q, R }
– S1 has 4 elements, each of which is a set.

• S2 = {x | x ∈ N and ∃k k ∈ N, x = k 2 }
– Set of squares of natural numbers
Sets Membership (example)
Equality of Sets
The Universal Set

• U is the universal set – the set containing all


objects or elements under consideration, and
of which all other sets are subsets
– For the set {-2, 0.4, 2}, U would be the real numbers
– For the set {0, 1, 2}, U could be the N, Z, Q, R depending on
the context
– For the set of the vowels of the alphabet, U would be all
the letters of the alphabet
Venn Diagrams

• Sets can be represented graphically using Venn diagram.

• The box represents the universal set


• Circles represent the set(s)
• Consider set S, which is the set of all vowels in the
alphabet
• The individual elements are usually not written in a
Venn diagram
Empty Set and Singleton Set
Sets Of Sets

• Sets can contain other sets


S = { {1}, {2}, {3} }
T = { {1}, {{2}}, {{{3}}} }
V = { { {1}, {{2}} } , {{{3}}} , { {1}, {{2}}, {{{3}}} } }

• Note that 1 ≠ {1} ≠ {{1}} ≠ {{{1}}}


• They are all different
Subset-  Notation

• Let A and B be sets, A is a subset of B if and only if


every element of A is also an element of B, denoted
by A ⊆ B.
• A ⊆ B if and only if ∀x (x ∈ A → x ∈ B).

• Every non-empty set S is guaranteed to have at least


two subsets, the empty set and the set itself; i.e.

∀ set S,
•Ø⊆S
•S⊆S
Subset
• Show ∀ set S, Ø ⊆ S.

Proof:
We want to show ∀x (x ∈ Ø → x ∈ S).
• Ø contains no element, so x ∈ Ø is false.
• Hypothesis of conditional statement is false,
so
x ∈ Ø → x ∈ S is true.
• Thus, ∀x (x ∈ Ø → x ∈ S) is true.
Subset
• Show ∀ set S, S ⊆ S.

Proof:
We want to show ∀x (x ∈ S → x ∈ S).
• If x ∈ S is true, then hypothesis and conclusion of
conditional statement are both true and (x ∈ S → x
∈ S) is true.
• If x ∈ S is false, then hypothesis and conclusion of
conditional statement are both false and (x ∈ S → x
∈ S) is true.
• Thus, ∀x (x ∈ S → x ∈ S) is true.
Subset and Equality

IF A ⊆ B, ∀ x (x ∈ A → x ∈ B)
and
B ⊆ A, ∀ x (x ∈ B → x ∈ A)
then
Equality holds for A and B
A = B, ∀ x (x ∈ A x ∈ B)
Subset (example)

• Q and R
Q⊆R

• N and Z
N⊆Z

• A = {x | x ∈ 𝐙+ and x<10}
B = {x | x ∈ 𝐙 + , x is even and x<10}
B⊆A
Proper Subset

Let A and B be sets.

• A is a proper subset of B if and only if A ⊆ B


but A ≠B, denoted A ⊂ B.

• A ⊂ B if and only if ∀x (x ∈ A → x ∈ B) ˄ x (x
∈ B ˄ x ∉ A).
Subset Example
• If S is a subset of T, and S is not equal to T, then S is a
proper subset of T
Let T = {0, 1, 2, 3, 4, 5} and S = {1, 2, 3}
• S is not equal to T, and S is a subset of T

• Let Q = {4, 5, 6}. Q is neither a subset of T nor a proper


subset of T

• The difference between “subset” and “proper subset”


 is to , as < is to .
Subset Example
Subset Example
Subset Example
Size of Sets-Cardinality
Example-Cardinality

Compute cardinality.
1. |{1, -13, 4, -13, 1}|
2. |{3, {1,2,3,4}, }|
3. |{}|
4. |{ {}, {{}}, {{{}}} }|
Example-cardinality
Hint: After eliminating the redundancies just look at
the number of top level commas and add 1 (except
for the empty set).

1. |{1, -13, 4, -13, 1}| = |{1, -13, 4}| = 3


2. |{3, {1,2,3,4}, }| = 3. To see this, assume S = {1,2,3,4}.
Compute the cardinality of {3,S, }
3. |{}| = || = 0
4. |{ {}, {{}}, {{{}}} }| = |{ , {}, {{}}| = 3
cardinality
The set S is said to be finite if its cardinality is a
nonnegative integer. Otherwise, S is said to
be infinite.
EG: N, Z, Z+, R, Q are each infinite.

Note: We’ll see later that not all infinities are


the same. In fact, R will end up having a
bigger infinity-type than N, but surprisingly,
N has same infinity-type as Z, Z+, and Q.
The Power Set
• Let S be a set, the power set of S is the set of all
subsets of S, denoted by P(S).

Examples:
P({ a ,b }) = {Ø ,{a} ,{b} ,{ a ,b }}
P({1,2,3}) = { Ø, {1}, {2}, {3}, {1,2}, {2,3}, {1,3}, {1,2,3} }
P(Ø) = {Ø}
P({Ø}) = {Ø, {Ø}}
The Cardinality of the Power Set

• Assume A is finite.
• |P(A)| = ?
Solution:
• A = {a} P(A) = {Ø, {a}} |P(A)| = 2
• A = {a,b} P(A) = {Ø, {a}, {b}, {a,b}} |P(A)| = 4
• A = {a,b,c} P(A)={Ø,{a},{b},{c},{a,b},{a,c},{b,c},{a,b,c}} |P(A)| = 8

• |P(A)| = 2|A| ; If a set has n elements , then its power set will have
2n elements
Cartesian Product

Let A and B be sets, the Cartesian product of A


and B, denoted by A x B, is the set of all ordered
pairs (a,b), where a ∈ A and b ∈ B.

• A x B = {(a,b) | a ∈ A ˄ b ∈ B}
Cartesian Product- Order Matters

• As opposed to sets, repetition and ordering do


matter with cartesian product.
(11, 11, 11, 12, 13)  ( 11, 12, 13 )
Example:
A = {0,1,2} and B = {a,b}
Are A x B and B x A equal?
Solution:
A x B = {(0,a),(0,b),(1,a),(1,b),(2,a),(2,b)}
B x A = {(a,0),(a,1),(a,2),(b,0),(b,1),(b,2)}
So, A x B ≠ B x A.
Cartesian Product

• Let A1, A2, …, An be sets.

• The Cartesian product of A1, A2, …, An , denoted


by
A1 x A2 x …x An, is the set of all ordered n-tuples
(a1, a2, …, an), where ai ∈ Ai for i = 1,2,…,n.

• A1 x A2 x …x An = {(a1, a2, …, an) | ai ∈ Ai , ∀i ∈


{1,2,…,n}}
Ordered n-tuple

• The ordered n-tuple (𝑎1 , 𝑎2 , … , 𝑎𝑛 ) is the


ordered collection that has 𝑎1 as its first
element, 𝑎2 as its second element, …, and 𝑎𝑛 as
its nth element.
• Example:
(a,b) is an ordered 2-tuple (ordered pair).
(a,b,c) is an ordered 3-tuple.
Ordered n-tuple (example)

• Assume c ≠ b.
• Are ordered 3-tuples (a,b,c) and (a,c,b) equal?

Solution:
• a = a but b ≠ c and c ≠ b.
• So, (a,b,c) and (a,c,b) are not equal.
The Cardinality of Cartesian Product

Assume A and B are finite. |AxB| = ?


1. A = {a} B={0}
AxB = {(a,0)} |AxB| = 1

2. A = {a,b} B={0}
AxB = {(a,0),(b,0)} |AxB| = 2

3. A = {a,b} B={0,1}
AxB={(a,0),(a,1),(b,0),(b,1)} |AxB| = 4

• |AxB| = |A|.|B|
The Cardinality of Cartesian product

A = {1,2}, B = {3,4}, C = {5,6,7}


A B C = { (1,3,5), (1,3,6), (1,3,7),
(1,4,5), (1,4,6), (1,4,7),
(2,3,5), (2,3,6), (2,3,7),
(2,4,5), (2,4,6), (2,4,7) }
|AxBxC| = |A|.|B|.|C|

• The cardinality of the Cartesian product is the


product of the cardinalities:
| A1  A2  … An | = |A1||A2| … |An|
Using Set Notation with Quantifiers

• x P(x) where domain: S

x ∈ S (P(x))

x (x ∈ S → P(x))
Using Set Notation with Quantifiers

• x P(x) where domain: S

x ∈ S (P(x))

x (x ∈ S ˄ P(x))
Example

• What does the following statement mean?


x ∈ R (x 2 ≥ 0)

Solution:
• For every real number x, (x 2 ≥ 0).
• The square of every real number is
nonnegative.
Example

• What does the following statement mean?


∃x ∈ Z (x 2 = 1)

Solution:
• There is an integer x such that x 2 = 1.
• There is an integer whose square is 1.
Truth Sets of Predicates

• Let P be a predicate and D is a domain.

• The truth set of P is the set of elements x in D


for which P(x) is true.

• The truth set of P(x) is {x ∈ D | P(x)}.


Example
Let P(x) be |x| = 1 where the domain is the set of integers.
What is the truth set of P(x)?
Solution:
The truth set of P(x) is {-1,1}.

Let R(x) be |x| = x where the domain is the set of integers.


What is the truth set of R(x)?
Solution:
The truth set of R(x) is 𝑥 ≥ 0.

Let Q(x) be x 2 = 2 where the domain is the set of integers.


What is the truth set of Q(x)?
Solution:
The truth set of Q(x) is Ø.
Truth Set of Quantifiers

• ∀x P(x) is true over the domain D if and only if


the truth set of P is the set D.

• ∃x P(x) is true over the domain D if and only if


the truth set of P is nonempty.
Exercises
• List the member of the set
C = {x | x is the square of an integer and x<100}
• Determine Subset
The set of people who speak English, the set of
people who speak English with an Australian accent
The set of students studying discrete mathematics,
the set of students studying data structures
• How many elements does P(P(Ø)) set have.
Exercises

• Translate each of these quantifications into


English and determine its truth value.
∃ x∈R (x3 = -1)
∀ x∈Z (x - 1 ∈ Z)
• Find the truth set of each of these predicates
where the domain is the set of integers.
P(x): x3= 1
R(x):2x + 1 = 0
Set Operations

• Two sets can be combined in many different


ways.

• Set operations can be used to combine sets.


Set Operations-Union
• Let A and B be sets, the union of A and B, denoted by
A∪B, is the set containing those elements that are either
in A or in B, or in both.
A ∪ B = {x | x ∈ A ˅ x ∈ B}

• Examples
• {1, 2, 3}  {3, 4, 5} = {1, 2, 3, 4, 5}
• {a, b}  {3, 4} = {a, b, 3, 4}
• {1, 2}   = {1, 2}
Set Operations-Union
Properties of the union operation

A =A Identity law

AU=U Domination law

AA=A Idempotent law

AB=BA Commutative law

A  (B  C) = (A  B)  C Associative law
The Cardinality of the Union of Sets
• |𝑨 ∪ 𝑩| = |𝑨| + |𝑩| − |𝑨 ∩ 𝑩|

Example:
Let 𝐴 = {1,2,3}
𝐵 = {2,3,4}
𝐴 ∩ 𝐵 = {2,3} 𝐴 ∪ 𝐵 = {1,2,3,4}
|𝑨| = 𝟑 |𝑩| = 𝟑 𝑨 ∩ 𝑩 =𝟐
𝑨∪𝑩 =𝟑+𝟑−𝟐=𝟒

51
Set Operations-Intersection
• Let A and B be sets, the intersection of A and B,
denoted by A ∩ B, is the set containing those
elements in both A and B.
A ∩ B = {x | x ∈ A ˄ x ∈ B}

Examples
{1, 2, 3} ∩ {3, 4, 5} = {3}
{a, b} ∩ {3, 4} = 
{1, 2} ∩  = 
Set Operations-Intersection
Properties of the intersection operation

A∩U=A Identity law

A∩= Domination law

A∩A=A Idempotent law

A∩B=B∩A Commutative law

A ∩ (B ∩ C) = (A ∩ B) ∩ C Associative law
Set Operations-Disjoint Sets
• Two sets are called disjoint if their intersection is empty.

• Examples
{even integers} and {odd integers} are disjoint
{a, b} and {3, 4} are disjoint
{1, 2} and  are disjoint
Complement
• Let U be the universal set and A be a set, the
complement of A, denoted by 𝐀ഥ , is U - A.
ഥ= 𝐱 𝒙∉𝐀}
• 𝑨
Examples:
assuming U = Z
{1, 2, 3}c = { …, -2, -1, 0, 4, 5, 6, … }
{a, b}c = Z
Properties of complement sets
(Ac)c = A Complementation law
A  Ac = U Complement law
A ∩ Ac =  Complement law
Set Operations-Difference
• Let A and B be sets, the difference of A and B, denoted
by A - B, is the set containing those elements that are
in A but not in B. (also called complement of B with
respect to A).
• A - B = {x | x ∈ A ˄ x ∉ B}
= A ∩ Bc
Examples:
{1, 2, 3} - {3, 4, 5} = {1, 2}
{a, b} - {3, 4} = {a, b}
{1, 2} -  = {1, 2}
The difference of any set S with the empty set will be the set S
Summary Set Operations

Operation Notation
Union A ∪ B = {x | x ∈ A ˅ x ∈ B}
Intersection A ∩ B = {x | x ∈ A ˄ x ∈ B}
Difference A - B = {x | x ∈ A ˄ x ∉ B}
Complement (U - A) ഥ= x x∉A}
A
Set identities
A=A
Identity Law
AU=A
AA=A
Idempotent Law
AA=A
AU=U
Domination law
A=
(Ac)c = A Complementation Law

A  (A  B) = A
Absorption Law
A  (AB) = A

A  Ac = U A  Ac = 
Complement Law
Uc =   c= U
Set identities
AB=BA
Commutative Law
AB=BA
A  (B  C) = (A  B)  C
Associative Law
A  (B  C) = (A  B)  C
(A  B)c = Ac  Bc
De Morgan’s Law
(A  B)c = Ac  Bc
A  (B  C) = (A  B)  (A  C)
Distributive Law
A  (B  C) = (A  B)  (A  C)
A  B  C iff A  C and B  C
Subset Laws
C  A  B iff C  A and C  B

A – B = A  Bc Set Difference
How to Prove a Set Identity

Four methods:

• Use membership tables


• Use the basic set identities
• Prove each set is a subset of the other
• Use set builder notation and logical equivalences
What is a membership table

• Membership tables show all the combinations


of sets an element can belong to
• 1 means the element belongs, 0 means it does not
• Consider the following membership table:
A B A∪B A∩B A-B
1 1 1 1 0
1 0 1 0 1
0 1 1 0 0
0 0 0 0 0
Proof using Membership Table
A ∪ (B ∩ C) = (A ∪ B) ∩ (A ∪ C)
Distributive Law

A B C B∩ A ∪ (B ∩ C) A∪B A∪C (A ∪ B) ∩ (A ∪ C)
C

1 1 1 1 1 1 1 1
1 1 0 0 1 1 1 1
1 0 1 0 1 1 1 1
1 0 0 0 1 1 1 1
0 1 1 1 1 1 1 1
0 1 0 0 0 1 0 0
0 0 1 0 0 0 1 0
0 0 0 0 0 0 0 0
Proof using Set Identities (example)

• Show A ∪ (B ∩ C) = (Cത ∪ B ഥ
ഥ) ∩ A
Proof using Set Identities (example)

• Show A ∪ (B ∩ C) = (Cത ∪ B ഥ
ഥ) ∩ A

Solution:
ഥ∩ B∩C
=A By DeMorgan′ s Law

= ഥA ∩ B
ഥ ∪ Cത By DeMorgan′ s Law

ഥ ∩ Cത ∪ B
=A ഥ By CommutativeLaw

= (Cത ∪ B ഥ
ഥ) ∩ A (By Commutative Law)
Proof using Set Identities

A  ( B − A) = A  B
L.H .S = A  ( B − A)
= A  ( B  A) Difference Law
= ( A  B )  ( A  A) Distribution Law
= ( A  B)  Complement Law
= A B Identity Law
= R.H .S
Proof by showing each set is a subset
of the others
(A  B)c = Ac  Bc
We need to show that
(A  B)c  Ac  Bc and Ac  Bc  (A  B)c
(i) x  (A  B)c
 x  (A  B)
  (x  A  B)
  (x  A  x B )
  (x  A)   (x  B)
xAxB
 x  Ac  x  B c
 x  Ac  B c
(ii) Similarly we show that Ac  Bc  (A  B)c
Proof by set builder notation

(A  B)c ={x | x  A  B} by definition of complement

={x |¬(x ∈ (A  B))} by definition of membership

={x |¬(x ∈ A ∧ x ∈ B)} by definition of intersection

={x |¬(x ∈ A) ∨¬(x ∈ B)} by the first De Morgan law

={x | x  A ∨ x  B} by definition of membership

={x | x ∈ Ac ∨ x ∈ Bc} by definition of complement

={x | x ∈ Ac  Bc } by definition of union

= Ac  Bc by meaning of set builder notation


Inclusion-Exclusion Principle of
Sets
The Cardinality of the Union of Sets
• |𝑨 ∪ 𝑩| = |𝑨| + |𝑩| − |𝑨 ∩ 𝑩|
Generalization of union of any arbitrary number
of sets is called Principle of inclusion-exclusion.

Example:
Let 𝐴 = {1,2,3}
𝐵 = {2,3,4}
𝐴 ∩ 𝐵 = {2,3} 𝐴 ∪ 𝐵 = {1,2,3,4}
|𝑨| = 𝟑 |𝑩| = 𝟑 𝑨 ∩ 𝑩 =𝟐
𝑨∪𝑩 =𝟑+𝟑−𝟐=𝟒
69
Inclusion-Exclusion Principle of Sets

For 2 set
|A ∪ B| = |A| + |B| - |A ∩ B|

For 3 set
|A ∪ B ∪ C | = |A| + |B| +|C| - |A ∩ B| - |A ∩ C| - |B ∩ C| + |A
∩B∩C|
2 - Set Venn Diagram
• Region I represents the elements in set A that are not
in set B.
• Region II represents the elements in both sets A and
B.
• Region III represents the elements in set B that are not
in set A.
• Region IV represents the elements in the universal set
that are in neither set A nor set B.
2 – Set Example

Suppose a list A contains the 30 students in a


mathematics class, and a list B contains the 35 students in
an English class, and suppose there are 20 names on both
lists. Find the number of students:
• only on list A
• only on list B
• on list A or B (or both)
• on exactly one list.
2 – Set Example
A contains the 30 students in a mathematics
B contains the 35 students in an English
20 names on both lists.
• only on list A 30 − 20 = 10 names are only on list A.

• only on list B 35 − 20 = 15 are only on list B.

• on list A or B (or both)


• |A ∪ B|= |A| + |B| − |A ∩ B| = 30 + 35 − 20 = 45.
• on exactly one list.
• 10 + 15 = 25 names are only on one list; that is,
• |A ⊕ B| = 25.
3 - Set Venn Diagram
• Region I represents the elements in set A but not in set B or set C.
• Region II represents the elements in set A and set B but not in set C.
• Region III represents the elements in set B but not in set A or set C.
• Region IV represents the elements in sets A and C but not in set B.
• Region V represents the elements in sets A, B, and C.
• Region VI represents the elements in sets B and C but not in set A.
• Region VII represents the elements in set C but not in set A or set B.
• Region VIII represents the elements in the universal set U, but not in set A,
B, or C.
3 - Set Example
Consider the following data for 120 mathematics
students at a college concerning the languages
French, German, and Russian:
65 study French, 45 study German,
42 study Russian , 20 study French and German,
25 study French and Russian, 15 study German and
Russian. 8 study all three languages.

Determine how many students study exactly 1


language course and fill the correct numbers of
students in each eight region of Venn diagram shown
in figure.
U = 120
F = 65
G = 45
R = 42
F  G = 20
F  R =25
G  R =15
F  G  R =8

𝑹𝟏 = 𝟔𝟓 − 𝟏𝟐 − 𝟖 − 𝟏𝟕 = 𝟐𝟖
𝑹𝟑 = 𝟒𝟓 − 𝟏𝟐 − 𝟖 − 𝟕 = 𝟏𝟖
𝑹𝟕 = 𝟒𝟐 − 𝟏𝟕 − 𝟖 − 𝟕 = 𝟏𝟎
𝑹𝟐 = 𝟐𝟎 − 𝟖 = 𝟏𝟐
𝑹𝟒 = 𝟐𝟓 − 𝟖 = 𝟏𝟕
𝑹𝟔 = 𝟏𝟓 − 𝟖 = 𝟕
𝑹𝟓 = 𝟖
𝑭 ∪ 𝑮 ∪ 𝑹 =65+45+42−20−25−15+8=100
𝑹𝟖 − 𝑼 − 𝑭 ∪ 𝑮 ∪ 𝑹 = 𝟏𝟐𝟎 − 𝟏𝟎𝟎 = 𝟐𝟎
Example
• Total number of students exactly registered in
one course = 28+18+10=56
Exercise
• In a class of 50 , there are 30 girls, and there
are 35 students with dark hair. Show that
there are at least 15 girls with dark hair.
Chapter Reading and Exercise Questions

Topic # 2.1
Question # 1-11,2122,23,32 33,34,45-48
Topic # 2.2
Question # 1- 6,15,16, 19- 27
CSC102 - Discrete Structures
(Discrete Mathematics)
Lecture # 19
Chapter 2.3

Functions
Lecture Outline

• Functions
– What is a function?
– Function Arithmetic
– One-to-one, Onto and Bijective Functions
– Identity and Inverse Function
– Composition of Functions

5/11/2025 CSC102 - Discrete Structures 3


Application of Functions

• Define discrete structures such as sequences


and strings
• Represent the time that a computer takes to
solve problems of a given size
• Represent the complexity of algorithms
• …
Functions

• Each student in a discrete structures class is


assigned a letter grade from the set {A, B, C, D,
F}.
• This assignment is an example of a function.

Ali A
Babar B
Umer C
Imran D
Hamza F
Functions
• Let A and B be nonempty sets.

• A function f from A to B is an assignment of


exactly one element of B to each element of A.

• If b is the unique element of B assigned by the


function f to the element a of A, we write f(a) = b.

• If f is a function from A to B, we write f: A → B.


Arrow Diagram of Functions

2 12
The arrow diagram for a function f 3 20
has the following two properties: 4 24
5 8
• Every element of A has an arrow 6 16
coming out of it.
• No elements of A has two arrows
coming out of it that point to two 𝒇 𝒙 = 𝟒𝒙
different elements of B.
𝒇 𝟐 =𝟖
𝒇(𝟑) = 𝟏𝟐

Functions and Non-Functions
• Which of the arrow diagrams define functions from
• A = {2,4,5,6,7} to B = {1,2,4,6,8}.

Domain Co-domain Domain Co-domain


2 1
2 1
4 2
4 2
5 4
5 4
6 6
6 6
7 8
7 8

A B A B

Not a Function Not a Function


Functions
• A function takes an element from a set and
maps it to a UNIQUE element in another set.
f maps R to Z
Domain R Z Co-domain
f

f(4.3)
4.3 4

Pre-image of 4 Image of 4.3


Functions

• If f is a function from A to B, we say that A is the


domain of f and B is the codomain of f.
• if f(a) = b, we say that b is the image of a and a
is the pre-image of b.
• The range of f is the set of all images of
elements of A.
• Also, if f is function from A to B, we say that f
maps A to B.
Arrow Diagram – Function Terminologies

The pre-image The image


Domain Co-domain of 1 of “a”
Ali A “a” 1

Babar B “bb“ 2

Umer C “cccc” 3

Hamza D “dd” 4

Amir F “e” 5

A class grade function A string length function

g(Ali) = A f(x) = length x


g(Babar) = C f(“a”) = 1
g(Umer) = A f(“bb”) = 2
… …
Arrow Diagram – Function Terminologies

The range of f is the set of all images of elements of


A.

Domain Range
a 1
e 2
i 3 Co-domain
o 4
u 5
Example
• Let f : Z → Z : assign the square of an integer to this
integer
• What is f (x) =?
– f(x) = x2
• What is domain of f ?
– Set of all integers
• What is codomain of f ?
– Set of all integers
• What is the range of f ?
– {0, 1, 4, 9, . . . }. All integers that are perfect
squares
One-to-One Function-Injective
• A function is one-to-one if each element in the
co-domain has a unique pre-image
• Formal definition: A function f is one-to-one if
f(a) = f(b) implies a = b for all a and b in the
domain of f.
a 1
a 1 e 2
e 2 i 3
i 3 o 4
o 4 5
5
A function that is
A one-to-one function not one-to-one
One-to-One Function-Injective

• 𝑓 is one-to-one using quantifiers as

∀𝑎∀𝑏 𝑓 𝑎 = 𝑓 𝑏 → 𝑎 = 𝑏 or equivalently
∀𝑎∀𝑏 𝑎 ≠ 𝑏 → 𝑓(𝑎) ≠ 𝑓 𝑏

a 1
e 2

Note that there can be un-used i 3

elements in the co-domain o 4


5
A one-to-one function
Example - one-to-one (Injective)

• Determine whether the function 𝑓 from {𝑎, 𝑏, 𝑐, 𝑑} to


{1, 2, 3, 4, 5} with 𝑓 𝑎 = 4, 𝑓 𝑏 = 5, 𝑓 𝑐 =
1, 𝑎𝑛𝑑 𝑓(𝑑) = 3 is one-to-one.
Onto Functions- Surjective
• A function is onto if each element in the co-
domain is an image of some pre-image
• Formal definition: A function f is onto if for all
b  B, there exists a  A such that f(a) = b.
a 1 a 1
e 2 e 2
i 3 i 3
o 4 o 4
u 5

An onto function A function that


is not onto
Onto functions- Surjective

• A function 𝑓 is onto if ∀𝑏∃𝑎(𝑓 𝑎 = 𝑏),


where the domain for 𝑎 is the domain of the
function and the domain for 𝑏 is the codomain
of the function.

a 1
e 2
Note that there can be multiple i 3
used elements in the co-domain o 4
u

An onto function
Example onto (Surjective) function

• Determine whether the function 𝑓 from


{𝑎, 𝑏, 𝑐, 𝑑} to {1, 2, 3} defined by 𝑓 𝑎 =
3, 𝑓 𝑏 = 2, 𝑓 𝑐 = 1, 𝑎𝑛𝑑
𝑓(𝑑) = 3. Is 𝑓 an onto function?
Onto vs One-to-One
• Are the following functions onto, one-to-one,
both, or neither?
a 1 a 1 a 1
b 2 b 2 b 2
c 3 c 3 c 3
4 d 4 4
1-to-1, not onto Both 1-to-1 and onto Not a valid function

a 1 a 1

b 2 b 2

c 3 c 3

d d 4

Onto, not 1-to-1 Neither 1-to-1 nor onto


Example
• Determine whether the function f (x) = 𝑥 2 from the
set of integers to the set of integers is one-to-one.
𝑓: 𝑍 → 𝑍; 𝑓 𝑥 = 𝑥 2
Example
• Determine whether the function f (x) = 𝑥 + 1 from
the set of integers to the set of integers is onto.
𝑓: 𝑍 → 𝑍; 𝑓 𝑥 = 𝑥 + 1
Bijections OR One-to-One Correspondence

• A function that is both one-to-one and onto is a one-to-


one correspondence, or a bijection.
a 1
b 2
Example: c 3
Determine whether the following d 4

functions are bijective or not?


𝑓: 𝑅 → 𝑅; 𝑓 𝑥 = 𝑥 3
𝑥+1
𝑓: 𝑅 − 0 → 𝑅; 𝑓 𝑥 =
𝑥
Function Arithmetic

• Just as we are able to add (+), subtract (-), multiply (*), and
divide (÷) two or more numbers, we are able to + , - , * , and ÷
two or more functions.

• Let f and g be functions from A to R. Then f + g, f – g, f * g


and f/g are also functions from A to R defined for all x ∈ A by:
• (f + g)(x) = f(x) + g(x)
• (f - g)(x) = f(x) - g(x)
• (f *g)(x) = f (x)*g(x)
• (f/g)(x) = f(x)/g(x) given that g(x)≠0
Function Arithmetic
• Let f1 and f2 be functions from R to R such that:
f1(x) = 2x f2(x) = x2

f1+f2 = (f1+f2)(x) = f1(x)+f2(x) = 2x+x2


f1*f2 = (f1*f2)(x) = f1(x)*f2(x) = 2x*x2 = 2x3

• Let f and g be functions from R to R such that:


f (x) = 3x+2 g (x) = -2x + 1
f*g = (f*g) (x) = f (x)*g(x) = (3x+2)*(-2x+1)
= -6x2- x +2
Function Arithmetic

• let f(x)=5x+2 and g(x)=x2 -1,


At x=4, f(4)=22 and g(4)=15.
Arithmetic Expression Combine evaluate Evaluate, then combine
(f+g)(x) (f+g)(4) f(4)+g(4)
(5x+2) + (x2-1) 42+5(4)+1 =16+20+1 22+15
=x2+5x+1 =37 =37
(f-g)(x) (f-g)(4) f(4)-g(4)
(5x+2) - (x2-1) -42+5(4)+3 22-15
=-x2+5x+3 =-16+20+3 =7 =7
(f*g)(x) (f*g)(4) f(4)*g(4)
(5x+2)*(x2-1) 5(43)+2(42)-5(4)-2 22*15
=5x3+2x2-5x-2 =5(64)+2(16)-20-2 =330 =330
(f/g)(x) (f/g)(4) f(4)/g(4)
(5x+2)/(x2-1) [5(4)+2]/[42-1] 22/15
=22/15
Some Useful Function-Floor and Ceiling
• Floor(x) = X is the largest integer that is less than or
equal to x.
• Ceiling(x) = X is the smallest integer that is greater
than or equal to x
• The floor and ceiling functions give you the nearest
integer up or down.
Sample value
Floor 𝒙 Ceiling 𝒙
x
12/5 = 2.4 2 3
2.7 2 3
−2.7 −3 −2
−2 −2 −2
Some Useful Function-Floor and Ceiling

How many bytes are required to encode n bits of data


where n equals

a) 7? b) 1001? c) 28,800?
Some Useful Function-Factorial

• Factorial is denoted by n!

• n! = n * (n-1) * (n-2) * … * 2 * 1

• Thus, 6! = 6 * 5 * 4 * 3 * 2 * 1 = 720

• Note that 0! is defined to equal 1


Some Useful Function-Identity Functions

• A function such that the image and the pre-image


are ALWAYS equal

• f(x) = 1*x
• f(x) = x + 0

• The domain and the co-domain must be the same


set.
Inverse Function

• Let f be a one-to-one correspondence from


the set A to the set B.
• The inverse function of f is the function that
assigns to an element in b belonging to B the
unique element a in A such that f(a) = b.
• The inverse function of f is denoted by f −𝟏 .
• Hence , f −𝟏 (b) = a when f(a) = b.
Inverse Functions

If f(a) = b, then f-1(b) = a

A B

f
a= f-1(b) f(a)=b
f-1

A=domain of f B=Co-domain of f
Inverse Functions

If f(x) = y, then f-1(y) = x


Let f(x) = 2*x
f(x)=y
R f R

f-1

f(4.3)
4.3 8.6
f-1(8.6)

Then f-1(y) = y/2


More on Inverse Functions

• Can we define the inverse of the following


functions?
a 1 a 1
b 2 b 2
c 3 c 3
4 d

What is f-1(2)? What is f-1(2)?


Not onto! Not 1-to-1!

• An inverse function can ONLY be done defined


on a bijection
More on Inverse Functions

• A one-to-one correspondence is called


invertible because we can define an inverse of
this function.

• A function is not invertible if it is not a one-to-


one correspondence, because the inverse of
such a function does not exist.
Example

• Let f be the function from {a, b, c} to {1, 2, 3}


such that
f (a) = 2, f (b) = 3, and f (c) = 1.
• Is f invertible, and if it is, what is its inverse?
Example

• Let g be the function from {a, b, c, d} to {1, 2,


3, 4}
such that
g(a) = 3, g (b) = 4, g(c) = 1, and g(d) = 3.
• Is g invertible, and if it is, what is its inverse?
Working Rule to Find Inverse Function

• Let f: X →Y be a one-to-one correspondence


defined by the formula f(x) = y.
1. Solve the equation f(x) = y for x in terms of y.
2. f −𝟏 (y) equals the right hand side of the
equation found in step 1.
Example- Inverse Function

Let f : Z → Z be such that f (x) = x + 1. Is f


invertible, and if it is, what is its inverse?
Example- Inverse Function

• Find the inverse function of f(x) = x3+ 1.


Compositions of Functions

• Let g be a function from the set A to the set B


and let f be a function from the set B to the
set C. the compositions of the functions f and
g, denoted by f °g, is defined by

(f °g)(𝒂) = f (g(a))
Compositions of Functions

(f °g)(a) = f(g(a))

f °g
A B C
g f

g(a) f(b)
a f(g(a))
b = g(a)

(f °g)(a)
Compositions of Functions

Let g(x) = 3x+2 Let f(x) = 2x+3


f°g
R R R
g f

g(1) f(5) f(g(1))=13


1
g(1)=5

(f ° g)(1)

f(g(x)) = 2(3x+2)+3 = 6x+7


Compositions of Functions

Do f(g(x)) = g(f(x))?

Let f(x) = 2x+3 Let g(x) = 3x+2

f(g(x)) = 2(3x+2)+3 = 6x+7


Not equal!
g(f(x)) = 3(2x+3)+2 = 6x+11

Function composition is not commutative!


Example-Compositions of Functions

• Find f ◦ g and g◦f,


where f(x) = x2+ 1 and g(x) = x + 2, are
functions from R to R.

• Find f + g and f.g for the functions f and g


given in
Examples-Compositions of Functions
• Let A = {1,2,3,4,5}
f : A → A and g : A → A
f(1) = 3, f(2) = 5, f(3) = 3, f(4) = 1, f(5) = 2
g(1) = 4, g(2) = 1, g(3) = 1, g(4) = 2, g(5) = 3
Find the composition functions f ◦ g and g ◦ f .
f◦g g◦f
(f ◦ g ) (1) = f(g(1)) = f(4) =1 (g ◦ f ) (1) = g(f(1)) = g(3) = 1
(f ◦ g ) (2) = ? (g ◦ f ) (2) = ?
(f ◦ g ) (3) = ? (g ◦ f ) (3) = ?
(f ◦ g ) (4) = ? (g ◦ f ) (4) = ?
(f ◦ g ) (5) = ? (g ◦ f ) (5) = ?
Compositions of Functions
• Let A = {1,2,3,4,5}
f : A → A and g : A → A
f(1) = 3, f(2) = 5, f(3) = 3, f(4) = 1, f(5) = 2
g(1) = 4, g(2) = 1, g(3) = 1, g(4) = 2, g(5) = 3
Find the composition functions f ◦ g and g ◦ f .
f◦g g◦f
(f ◦ g ) (1) = f(g(1)) = f(4) =1 (g ◦ f ) (1) = g(f(1)) = g(3) = 1
(f ◦ g ) (2) = 3 (g ◦ f ) (2) = 3
(f ◦ g ) (3) = 3 (g ◦ f ) (3) = 1
(f ◦ g ) (4) = 5 (g ◦ f ) (4) = 4
(f ◦ g ) (5) = 3 (g ◦ f ) (5) = 1
Compositions of Functions

Let g : A → A be the function, Set A = {a, b, c} such


that g(a) = b, g(b) = c, and g(c) = a.

Let f : A → B be the function, Set A = {a, b, c} to the


set B = {1, 2, 3} such that f (a) = 3, f (b) = 2, and f (c)
= 1.

What is the composition of f and g, and what is the


composition of g and f?
Compositions of Functions
Let g : A → A be the function, Set A = {a, b, c} such that g(a) = b, g(b) = c,
and g(c) = a.

Let f : A → B be the function, Set A = {a, b, c} to the set B = {1, 2, 3} such that
f (a) = 3, f (b) = 2, and f (c) = 1.

What is the composition of f and g, and what is the composition of g and f?


Solution:
The composition f ◦ g is defined by
(f ◦ g)(a) = f (g(a)) = f (b) = 2,
(f ◦ g) (b) = f (g(b)) = f (c) = 1,
(f ◦ g)(c) = f (g(c)) = f (a) = 3.
g ◦ f is not defined, because the range of f is not a subset of
the domain of g.
Reading and Exercise Questions

Topic # 2.3
Questions 1, 2, 8, 9,10,11,12, 22, 23, 38, 39
CSC102 - Discrete Structures
(Discrete Mathematics)
Lecture # 20-21
Lecture Outline

• Relations
– What is a Relation?
– Binary Relation
– Representation of Relation
– Relation Properties
– Combining Relations
– Composition of Relation with itself

5/18/2025 CSC102 - Discrete Structures 2


Relations
• The connections between people and things.

• Between people, family relation


– 'to be brothers' x is a brother of y
– 'to be older' x is older than y
– 'to be parents' x and y are parents of z
• Between things, numerical relations
– 'to be greater than' x > y on the real numbers
– 'to be divisible by' x is divisible by y on the set of
integers
• Between things and people, legal relations
– 'to be an owner' x is an owner of y
Cartesian Product

• The Cartesian product of sets A and B, denoted by A × B, is


the set of all ordered pairs of elements from A and B.
• 𝐴 × 𝐵 = {(𝑎, 𝑏)|𝑎 ∈ 𝐴 ‫}𝐵 ∈ 𝑏 ٿ‬

• The elements of the Cartesian product are ordered pairs. In


particular 𝑎, 𝑏 = 𝑐, 𝑑 𝑎 = 𝑐 ‫)𝑑 = 𝑏( ٿ‬

• 1, 2 × 𝑎, 𝑏 = 1, 𝑎 , 1, 𝑏 , 2, 𝑎 , 2, 𝑏
• {𝑀𝑜𝑛, 𝑇𝑢𝑒} × {𝐽𝑎𝑛, 𝐹𝑒𝑏} =
{(𝑀𝑜𝑛, 𝐽𝑎𝑛), (𝑀𝑜𝑛, 𝐹𝑒𝑏), (𝑇𝑢𝑒, 𝐽𝑎𝑛), (𝑇𝑢𝑒, 𝐹𝑒𝑏)}
Cartesian Product of More Than Two Sets
• Instead of ordered pairs we may consider ordered
triples, or, more general, k-tuples
• (𝑎, 𝑏), an ordered pair
• (𝑎, 𝑏, 𝑐), an ordered triple
• (𝑎, 𝑏, 𝑐, 𝑑), an ordered quadruple
• (𝑎1 , 𝑎2 , … , 𝑎𝑘 ), a k-tuple

• Pairs, triples, quadruples, and k-tuples are elements


of Cartesian products of 2, 3, 4, and k sets,
respectively
Relations

• Relationship between elements of sets are


represented using the structure called a
relation, which is just a subset of the cartesian
product of sets.

6
Binary Relation

• Let A and B be sets. A binary relation from set


A to set B is any subset of 𝐴 × 𝐵.
• Binary relations represent relationship
between two sets.
Example

• 𝐴 = {𝐴𝑙𝑖, 𝐽𝑢𝑛𝑎𝑖𝑑, 𝐻𝑎𝑠𝑠𝑎𝑛}


• 𝐵 = 𝐶𝑆𝐶102, 𝐶𝑆𝐶222, 𝐶𝑆𝐶106
• 𝑅: “𝑟𝑒𝑙𝑎𝑡𝑖𝑜𝑛 𝑜𝑓 𝑠𝑡𝑢𝑑𝑒𝑛𝑡𝑠 𝑒𝑛𝑟𝑜𝑙𝑙𝑒𝑑 𝑖𝑛 𝑐𝑜𝑢𝑟𝑠𝑒𝑠”
• 𝐴 × 𝐵 = { 𝐴𝑙𝑖, 𝐶𝑆𝐶102 , 𝐴𝑙𝑖, 𝐶𝑆𝐶222 , 𝐴𝑙𝑖, 𝐶𝑆𝐶106 ,
Juanid, CSC102 , Juanid, CSC222 , Juanid, CSC106 ,
Hassan, CSC102 , Hassan, CSC222 , Hassan, CSC106 }
• 𝑅 = 𝐽𝑢𝑛𝑎𝑖𝑑, 𝐶𝑆𝐶102 , 𝐻𝑎𝑠𝑠𝑎𝑛, 𝐶𝑆𝐶222

• (𝐽𝑢𝑛𝑎𝑖𝑑, CSC102) ∈ 𝑅
• (𝐴𝑙𝑖, CSC102) ∉ 𝑅
• (𝐽𝑢𝑛𝑎𝑖𝑑, 𝐶𝑆𝐶222) ∉ 𝑅
• (𝐴𝑙𝑖, 𝐶𝑆𝐶106) ∉ 𝑅
More Relations

• Relations can be generalized to subsets of


cartesian products of more than two sets

• Any subset of the Cartesian product of 3 sets


is called a ternary relation
– 'x and y are parents of z' ⊆ People × People × People

• Any subset of the Cartesian product of k sets


is called a k-ary relation
Functions as Relations

• A function f:A→B is a relation from A to B


• A relation from A to B is not always a function
f:A→B
• Relations are generalizations of functions!
Cardinality of Relations
If |A| = m and |B| = n , Then the number of elements
in A  B are m  n. Now as we know that the total
number of and the total number of relations from A
to B are 2m  n.

Example : Find all binary relations from {0,1} to {1}


Let A = {0,1} & B = {1}
Then A  B = {(0,1), (1,1)}

All binary relations from A to B are in fact all subsets of A


B, which are:
R1=  R2={(0,1)}
R3={(1,1)} R4={(0,1), (1,1)} = A  B
Relations on a Set

• A (binary) relation from a set A to itself is


called a relation on the set A.
A = {1, 2, 3, 4}
R1 = {(a, b) a divides b}
A  A = {(1,1), (1, 2), (1,3), (1, 4), (2,1), (2, 2), (2, 3), (2, 4),
(3,1), (3, 2), (3,3), (3, 4), (4,1), (4, 2), (4,3), (4, 4)}

R1 = {(1,1),(1, 2),(1,3),(1, 4),(2, 2),(2, 4),(3, 3),(4, 4)}


R1  A  A
Relation On a Set

• A (binary) relation from a set A to itself is


called a relation on the set A.
A = {1, 2, 3, 4}
𝑅1 = {(𝑎, 𝑏)|𝑎 > 𝑏}

𝑅1 = { 2,1 , 3,1 , 3,2 , 4,1 , 4,2 , (4,3)}

R1  A  A
Describing Binary Relations- Ordered tuples

• A binary relation can be described using a list


of pairs.
A = {1, 2, 3, 4}
R1 = {(a, b) a divides b}
R1 = {(1,1),(1, 2),(1,3),(1, 4),(2, 2),(2, 4),(3,3),(4, 4)}
Describing Binary Relations-Matrix

• A binary relation can also be described using a


matrix.
– Rows are labeled with elements of A
– Columns are labeled with elements of B.
• We write 1 in row a, column b if and only if (a,
b) ∈ R; otherwise we write 0.
Describing Binary Relations-Matrix

A = {1, 2, 3, 4}
R1 = {(a, b) a divides b}
R1 = {(1,1),(1, 2),(1,3),(1, 4),(2, 2),(2, 4),(3,3),(4, 4)}

1 1 1 1
0 1 0 1
MR1=  
0 0 1 0
 
0 0 0 1
Describing Binary Relations-Matrix

A = {1, 2, 3, 4}
𝑅1 = {(𝑎, 𝑏)|𝑎 + 𝑏 = 4}

𝑅1 = {(1,3), (2,2), (3,1)}


Describing Binary Relations-Directed Graph

• A binary relation can also be described using a


directed graph.
• A graph of a relation R ∈ A × B consists of two
sets of vertices labeled by elements of A and
B.
• A vertex a is connected to a vertex b with an
edge (arc) if and only if (a, b) ∈ R.
Describing Binary Relations-Directed Graph

R3
1 1
2 2
3 3
4 4 2
A:
1 3

4
Properties of Relations
Note: from now on we will consider only binary
relations on A. i.e. such relations are subsets of
𝐴 × 𝐴.

Properties of Relations
Reflexive
Symmetric
Anti-symmetric
Transitive
Properties of Relations-Reflexive

Reflexive: A binary relation R ⊆ 𝐴 × 𝐴 is said to


be reflexive if ∀𝑎 ∈ 𝐴, (𝑎, 𝑎) ∈ 𝑅
Irreflexive: A relation is irreflexive if ∀𝑎 ∈ 𝐴, (a,a)
 R.
Let A = {1, 2, 3, 4} and define relations R1,R2, R3, R4 on A
as follows:
• R1 = {(1, 1), (3, 3), (2, 2), (4, 4)}
• R2 = {(1, 1), (1, 4), (2, 2), (3, 3), (4, 3)}
• R3 = { (1, 2), (2, 1), (2, 4), (3, 1)}
Properties of Relations-Reflexive
• 𝑅 = {(𝑎, 𝑏) |(𝑎, 𝑏) ∈ 𝑍 × 𝑍, 𝑎 ≤ 𝑏 is reflexive}

• Consider a reflexive relation: ≤


– Let A = { 1, 2, 3, 4, 5 }
• If the main diagonal is
1 1 1 1 1 all 1’s, a relation is
0 1 1 1 1
reflexive.
 • If elements in the main
M  = 0 0 1 1 1
  diagonal are all 0’s
0 0 0 1 1
then relation is
0 0 0 0 1
irreflexive.
Properties of Relations : Symmetricity

• Symmetric: A binary relation R ⊆ 𝐴 × 𝐴 said to be


symmetric if,
∀𝑎, 𝑏 ∈ 𝐴, (𝑎, 𝑏) ∈ 𝑅 → (𝑏, 𝑎) ∈ 𝑅

𝐸𝑥𝑎𝑚𝑝𝑙𝑒:
𝑅 = 𝑎, 𝑏 𝑎, 𝑏 ∈ 𝑝𝑒𝑜𝑝𝑙𝑒 × 𝑝𝑒𝑜𝑝𝑙𝑒, 𝑎 𝑎𝑛𝑑 𝑏 𝑎𝑟𝑒 𝑠𝑖𝑏𝑙𝑖𝑛𝑔𝑠
is symmetric, because if a is a sibling of b, then b is a
sibling of a
Properties of Relations : Symmetricity

∀𝑎, 𝑏 ∈ 𝐴, (𝑎, 𝑏) ∈ 𝑅 → (𝑏, 𝑎) ∈ 𝑅

* 0 1 1
If, every value and the value in  
0 * 0 0
its transposed position, is same
then the relation is symmetric.
1 0 * 1 
If MR=MRt
 
then Symmetric 1 0 1 *
Else 
Not Symmetric
Properties of Relations - Anti-Symmetricity

A binary relation R ⊆ 𝐴 × 𝐴 said to be


Anti-symmetric if
∀𝑎, 𝑏 ∈ 𝐴, 𝑎, 𝑏 ∈ 𝑅 ∧ 𝑏, 𝑎 ∈ 𝑅 → 𝑎 = 𝑏

∀𝑎, 𝑏 ∈ 𝐴 𝑖𝑓 𝑎, 𝑏 ∈ 𝑅 ∧ 𝑏, 𝑎 ∈ 𝑅 𝑡ℎ𝑒𝑛 𝑎 = 𝑏 Anti-Symmetricity


Case 1 True True True
Case 2 True False False
Case 3 False True

Example: The relation Motherhood ('x is the mother of y')


is anti-symmetric, because if x is a mother of y, then y is
not the mother of x.
Properties of Relations : Anti-Symmetricity

• If, every value in the


Matrix and the value in its
transposed position are
not same then the
relation is anti- symmetric,
except the diagonal
elements.
• It can be reflexive.
Properties of Relations : Anti-Symmetricity
∀𝑎, 𝑏 ∈ 𝐴 𝑖𝑓 𝑎, 𝑏 ∈ 𝑅 ∧ 𝑏, 𝑎 ∈ 𝑅 𝑡ℎ𝑒𝑛 𝑎 = 𝑏 Anti-Symmetricity
Case 1 True True True
Case 2 True False False
Case 3 False True
Exercise

• Is R reflexive, symmetric or anti symmetric?


Reflexive: as all the diagonal elements are 1.
Symmetric, as elements in transpose positions are same.
It is also easy to see that R is not antisymmetric.
Properties of Relations : Symmetricity

• Let A = {1,2,3,4} and define the following


relations on A.
R1 = {(1,1),(2,2),(3,3)}
R2 = {(1,2),(2,2), (2,3), (3,4), (4,1)}
R3={(1,3),(2,2), (2,4), (3,1), (4,2)}
R4={(1,3),(2,4), (3,1), (4,3)}
Properties of Relations : Symmetricity

R1 = {(1,1),(2,2),(3,3)}
anti-symmetric + symmetric

R2 = {(1,2),(2,2), (2,3), (3,4), (4,1)}


anti-symmetric but not symmetric because (1,2)  R2but (2,1)  R2.

R3={(1,3),(2,2), (2,4), (3,1), (4,2)}


R3 is not anti-symmetric since (1,3) & (3,1)  R3 but 1  3. Note that R3 is
symmetric.

R4={(1,3),(2,4), (3,1), (4,3)}


R4is neither anti-symmetric because (1,3) & (3,1)  R4 but 1  3 nor symmetric
because (2,4)  R4 but (4,2) R4
Properties of Relations : Transitivity

• Transitivity: A binary relation R ⊆ 𝐴 × 𝐴 said to


be transitive if, ∀𝑎, 𝑏, 𝑐 ∈ 𝐴, 𝑎, 𝑏 ∈ 𝑅 ∧ (𝑏, 𝑐) ∈
𝑅 → (𝑎, 𝑐) ∈ 𝑅
Example: 𝑅 = {(𝑎, 𝑏)| (𝑎, 𝑏) ∈ 𝑍 × 𝑍, 𝑎 ≤ 𝑏 } is transitive, because if, ,
𝑎 ≤ 𝑏 and , b ≤ c then , 𝑎 ≤ c.

∀𝑎, 𝑏, 𝑐 If 𝑎, 𝑏 ∈ 𝑅 ∧ 𝑏, 𝑐 ∈ 𝑅 𝒕𝒉𝒆𝒏 (𝑎, 𝑐) ∈ 𝑅 Transitive


∈ 𝐴,
Case 1 True True True
Case 2 True False False
Case 3 False True
Properties of Relations -Transitivity
Let R1={(1,1),(1,2), (1,3),(1,4), (2,2),(2,4), (3,3),(4,4)}

Then MR x MR= MR2

𝑴𝑹 𝑴𝟐𝑹 Transitive
Non-Zero Non-Zero True
Non-Zero Zero True
Zero Non-Zero False
Summary of properties of relations

reflexive a (a, a)  R

irreflexive a (a, a)  R

symmetric  a, b  A, (a,b)  R  (b,a)  R


 a, b  A, ((a,b)  R  (b,a)  R)  a=b
antisymmetric
 a, b  A, ((a,b)  R  a  b)  (b,a)  R)
transitive  a, b, c  A, ((a,b)  R  (b,c)  R)  (a,c)  R
Equivalence Relations
• A relation on a set A is called an equivalence
relation if it is reflexive, symmetric, and
transitive.
Examples: Let R be relation defined on A={1,2,3,4}

• R= {(1, 1), (1, 2), (2, 1), (2, 2), (3, 3), (4, 4)}
R is Reflexive, Symmetric and transitive therefore equivalence
relation.
• R= Ø (empty relation defined on A)
R is not reflexive therefore not an equivalence relation. But R is
symmetric and Transitive.
• R= AxA
R has all the possible ordered pairs therefore it is reflexive,
symmetric and transitive, therefore it is an equivalence relation.
Example
• Which of these relations on {0, 1, 2, 3} are equivalence
relations? Determine the properties of an equivalence
relation that the others lack
• { (0,0), (1,1), (2,2), (3,3) }
– Has all the properties, thus, is an equivalence relation
• { (0,0), (0,2), (2,0), (2,2), (2,3), (3,2), (3,3) }
– Not reflexive: (1,1) is missing
– Not transitive: (0,2) and (2,3) are in the relation, but not (0,3)
• { (0,0), (1,1), (1,2), (2,1), (2,2), (3,3) }
– Has all the properties, thus, is an equivalence relation
• { (0,0), (0,1) (0,2), (1,0), (1,1), (1,2), (2,0), (2,2), (3,3) }
– Not symmetric: (1,2) is present, but not (2,1)
– Not transitive: (2,0) and (0,1) are in the relation, but not (2,1)
Combining Relations

• Relations from A to B are subsets of A × B,


Therefore all the set operations can be defined
on relations.(Intersection, Union, Difference,
Symmetric difference, complement)

• Let 𝐴 = 1, 2, 3 𝑎𝑛𝑑 𝐵 = {1, 2, 3, 4}


• The relations 𝑅1 = 1,1 , 2,2 , 3,3 𝑎𝑛𝑑
𝑅2 = 1,1 , 1,2 , 1,3 , (1,4)
• 𝑅1 ∪ 𝑅2 𝑅1 ∩ 𝑅2
• 𝑅1 − 𝑅2 𝑅1  𝑅2 𝑅1
Combining Relations
• Let 𝐴 = 1, 2, 3 𝑎𝑛𝑑 𝐵 = 1, 2, 3, 4
𝑅1 = 1,1 , 2,2 , 3,3
𝑅2 = 1,1 , 1,2 , 1,3 , (1,4)
• 𝑅1 ∪ 𝑅2 = { 1,1 , 1,2 , 1,3 , 1,4 , 2,2 , 3,3 }
• 𝑅1 ∩ 𝑅2 = { 1,1 }
• 𝑅1 − 𝑅2 = { 2,2 , 3,3 }
• 𝑅2 − 𝑅1 = { 1,2 , 1,3 , 1,4 }
• 𝑅1  𝑅2 = { 1,2 , 1,3 , 1,4 , 2,2 , 3,3 }

1,2 , 1,3 , 1,4 ,


2,1 , 2,3 , 2,4 ,
• 𝑅1 = AxB - 𝑅1 =
3,1 , 3,2 , 3,4
Combining Relations

• Let 𝑅 be a relation from a set 𝐴 to a set 𝐵 and 𝑆 be a


relation from 𝐵 to a set 𝐶.
• The composite of 𝑹 and 𝑺 is the relation consisting of
ordered pairs 𝑎, 𝑐 , where a ∈ 𝐴, 𝑐 ∈ 𝐶, and for which
their exists an element b ∈ 𝐵 such that (a, b) ∈ 𝑅 and
b, c ∈ 𝑆. We denote the composite of 𝑅 and 𝑆 by
𝑆°𝑅.
Example: What is the composite of the relations 𝑅 and 𝑆,
where 𝑅 is the relation from {1, 2, 3} 𝑡𝑜 1, 2, 3, 4
with
𝑅 = 1, 1 , 1, 4 , 2, 3 , 3, 1 , 3, 4
and 𝑆 is the relation from {1, 2, 3, 4} 𝑡𝑜 {0, 1, 2} with
𝑆 = {(1, 0), (2, 0), (3, 1), (3, 2), (4, 1)}?
Composition of Relations

𝑅 = 1, 1 , 1, 4 , 2, 3 , 3, 1 , 3, 4
𝑆 = 1, 0 , 2, 0 , 3, 1 , 3, 2 , 4, 1
𝑆°𝑅
If (a, b) ∈ 𝑅 and b, c ∈ 𝑆 𝑡ℎ𝑒𝑛 𝑎, 𝑐 will be the member of
𝑆°𝑅.
(1,1) ∈ 𝑅, 1, 0 ∈ 𝑆 𝑇ℎ𝑒𝑟𝑒𝑓𝑜𝑟𝑒 1, 0 ∈ 𝑆°𝑅
(1,4) ∈ 𝑅, 4, 1 ∈ 𝑆 𝑇ℎ𝑒𝑟𝑒𝑓𝑜𝑟𝑒 1, 1 ∈ 𝑆°𝑅
(2,3) ∈ 𝑅, 3, 1 ∈ 𝑆 𝑇ℎ𝑒𝑟𝑒𝑓𝑜𝑟𝑒 2,1 ∈ 𝑆°𝑅
(2,3) ∈ 𝑅, 3, 2 ∈ 𝑆 𝑇ℎ𝑒𝑟𝑒𝑓𝑜𝑟𝑒 2,2 ∈ 𝑆°𝑅
(3,1) ∈ 𝑅, 1,0 ∈ 𝑆 𝑇ℎ𝑒𝑟𝑒𝑓𝑜𝑟𝑒 (3,0) ∈ 𝑆°𝑅
(3,4) ∈ 𝑅, 4, 1 ∈ 𝑆 𝑇ℎ𝑒𝑟𝑒𝑓𝑜𝑟𝑒 (3,1) ∈ 𝑆°𝑅

𝑆°𝑅 = { 1,0 , 1,1 , 2,1 2,2 , (3,0), 3,1 }


Set Operations using Matrix
Set Operations using Matrix
Composition of Relation using Matrix
Composition of Relation using Matrix
Composition of Relation using Matrix
Composition of Relation to itself

• The powers of a relation R can be recursively


defined from the definition of a composite of
two relations.
R2= R o R
R3= R2 o R …
Exercise

1. Find 𝑅°𝑅. Let 𝑅 = 1, 1 , 2, 1 , 3, 2 , 4, 3

2. Find 𝑆°𝑅 using matrix representing of the


relations. Let 𝑅 is the relation from
{1, 2, 3} 𝑡𝑜 1, 2, 3, 4 with
𝑅 = {(1, 1), (1, 4), (2, 3), (3, 1), (3, 4)} and
𝑆 is the relation from {1, 2, 3, 4} 𝑡𝑜 {0, 1, 2} with
𝑆 = 1, 0 , 2, 0 , 3, 1 , 3, 2 , 4, 1 .
Exercises
Determine whether the relations for the directed graphs shown in
Figure 6 are reflexive, symmetric,
antisymmetric, and/or transitive.
Exercises

A = {1, 2, 3, 4}

𝑅1 = {(𝑎, 𝑏)|𝑎 + 𝑏 = 4}

𝑅2 = {(𝑎, 𝑏)| 𝑎 > 𝑏}

• Describe R1 and R2 as list of pairs, Matrix and


directed graph.
• Describe their properties(reflexive, irreflexive,
symmetric, anti-symmetric, transitive)
Chapter Reading and Exercise

Chapter # 9
Topic # 9.1
Q-1,2,3,10,11-14, 18-21,30,32
Topic # 9.3
Q-1-8,13-c,14,23-28
Lecture 22-23

Sequences

Chapter #2
Topic 2.4
Lecture Outline

–Arithmetic Sequence and Geometric


Sequence
–Determine a sequence formula
– Summation
– Evaluate a summation
–Shifting the index of summation
–Double Summation
6/9/2025 CSC102 - Discrete Structures 2
Sequences

– A sequence is a discrete structure used to represent an


ordered list of elements.

EXAMPLES:
1. 1, 2, 3, 4, 5, …
2. 4, 8, 12, 16, 20,…
3. 2, 4, 8, 16, 32, …
4. 1, 1/2, 1/3, 1/4, 1/5, …
5. 1, 4, 9, 16, 25, …
6. 1, -1, 1, -1, 1, -1, …
Sequences

• A sequence is a function from a subset of the


set integers Z (usually the set {0,1,2,…} or the
set {1,2,3,…}) to a set S.

• The notation 𝑎𝑛 denotes the image of the


integer 𝑛.
• 𝑎𝑛 : a term of the sequence
• {𝑎𝑛 } : entire sequence Z S
– Same notation as sets!
n an
Sequences

• Consider the sequence {an}, where an = 1/n.


– The list of the terms of this sequence beginning with
a1:
a1, a2, a3, a4, …
{1, 1/2, 1/3, 1/4 , … }

• Consider the sequence {an}, where an = 3n.


– The list of the terms of this sequence beginning with
a1:
{3, 6, 9, 12 , …}
Geometric Sequence/Progression
A geometric progression is a sequence of the form
𝑎, 𝑎𝑟, 𝑎𝑟 2 , … . , 𝑎𝑟 𝑛 , …
Where the initial term a and the common ratio r are real
numbers.
• Every term (after the first) is obtained from the preceding
term by multiplying it with a constant number.
• Common ratio: The constant number, being the ratio of
any two consecutive terms is called the common ratio
denoted by “r”.
EXAMPLE:
1, 2, 4, 8, 16, … (common ratio = 2)
3, - 3/2, 3/4, - 3/8, … (common ratio = - 1/2)
0.1, 0.01, 0.001, 0.0001, … (common ratio = 0.1 = 1/10)
General Term of Geometric Progression

• Let a be the first term and r be the common ratio


of a geometric sequence. Then the sequence is
𝑎, 𝑎𝑟, 𝑎𝑟 2 , 𝑎𝑟 3 , …
• If 𝑎𝑛 , for n ≥ 1, represents the terms of the
sequence then
𝑎1 = first term = 𝑎 = 𝑎𝑟1−1
𝑎2 = second term = 𝑎𝑟 = 𝑎𝑟 2−1
𝑎3 = third term = 𝑎𝑟 2 = 𝑎𝑟 3−1
By symmetry
𝑎𝑛 = nth term = 𝑎𝑟 𝑛−1 for all integers n ≥ 1.
Examples-Geometric Progression

• Is {2(5)𝑛−1 } geometric progression?


2,10,50,250,…
Yes, a=2 and r=5

• Is {6(1Τ3)𝑛−1 } geometric progression?


6,2,2/3,2/9,…
Yes, a=6 and r=1/3
Examples-Geometric Progression

• Find the 8th term of the following geometric


sequence 4, 12, 36, 108, …

Here a = first term = 4


r = common ratio = 12/4 = 3
n = term number = 8
a8 = value of 8th term = ?
Since an = a r n-1; n  1
 a8 = (4)(3)8-1
= 4 (2187)
= 8748
Arithmetic Sequence/Progression
An arithmetic progression is a sequence of the form
𝑎, 𝑎 + 𝑑, 𝑎 + 2𝑑, … . , 𝑎 + 𝑛𝑑, …
Where the initial term a and the common difference d are
real numbers.
• Every term (after the first )is obtained from the preceding term by
adding a constant number is
• The difference of any two consecutive terms is called the common
difference “d”.
EXAMPLES:
5, 9, 13, 17, … (common difference = 4)
0, -5, -10, -15, … (common difference = -5)
x + a, x + 3a, x + 5a, … (common difference = 2a)
General Term of Arithmetic Progression

• Let a be the first term and d be the common


difference of an arithmetic sequence. Then the
sequence is
𝑎, 𝑎 + 𝑑, 𝑎 + 2𝑑, 𝑎 + 3𝑑, …
• If 𝑎𝑛 , for n ≥ 1, represents the terms of the
sequence then
𝑎1 = first term = 𝑎 = 𝑎 + (1 − 1)𝑑
𝑎2 = second term = 𝑎 + 𝑑 = 𝑎 + (2 − 1)𝑑
𝑎3 = third term = 𝑎 + 2𝑑 = 𝑎 + (3 − 1)𝑑
By symmetry
𝑎𝑛 = nth term = 𝑎 + (𝑛 − 1)𝑑 for all integers n ≥ 1
11
Arithmetic Progression (Example)

• Is {4𝑛 − 5} Arithmetic progression?


-1,3,7,11,…
Yes, a = -1 and d = 4

• Is {10 − 3𝑛} Arithmetic progression?


7,4,1,-2,…
Yes, a=7 and d=-3
Arithmetic Progression (Example)
• Find the 20th term of the arithmetic sequence
3, 9, 15, 21, …

SOLUTION:
Here a = first term = 3
d = common difference = 9 - 3 = 6
n = term number = 20
a20 = value of 20th term = ?
Since an = a + (n - 1) d; n 1
 a20 = 3 + (20 - 1) 6
= 3 + 114
= 117
Arithmetic Progression (Example)
• Which term of the arithmetic sequence
4, 1, −2, … , 𝑖𝑠 − 77
SOLUTION:
Here a = first term = 4
d = common difference = 1 - 4 = -3
an = value of nth term = - 77
n = term number = ?
Since
an = a + (n - 1) d n 1
 - 77 = 4 + (n - 1) (-3)
 - 77 - 4 = (n - 1) (-3)
OR
−81
= n −1
OR −3
27 = n – 1
n = 28
Hence –77 is the 28th term of the given sequence.
Useful Sequences
Determining the Sequence Formula

• Given values in a sequence, how do you


determine the formula?
• Steps to consider:
– Is it an arithmetic progression (each term a constant amount
from the last)?
– Is it a geometric progression (each term a factor of the previous
term)?
– Does the sequence repeat itself (or cycle among the terms)?
– Does the sequence combine previous terms (in a certain way)?
– Are there runs of the same value? (same value occur many
times in a row)

16
Sequences (Example)

• Find a formula for the following sequence.


1, 0, 1, 1, 0, 0, 1, 1, 1, 0, 0, 0, 1, …
Solution:
The sequence alternates 1’s and 0’s, increasing the number of
1’s and 0’s each time.

• Find formula for the following sequence.


1, −1, 1, −1, 1, …
Solution:
{ −1 𝑛−1 } It is a geometric progression. a=1 and r=-1
Sequences (Example)

• Find formula for the following sequence.

1, 3, 5, 7, 9, …
Solution:
{2𝑛 − 1}
It is a arithmetic progression.
a=1 and d=2
Sequences (Example)

• How can you produce the terms of the


following sequence?

1, 2, 2, 3, 3, 3, 4, 4, 4, 4, …
A rule for generating this sequence is that integer n appears
exactly n times.

2, 3, 3, 5, 5, 5, 7, 7, 7, 7, 11, 11, 11, 11, 11, …


Sequence in which the n th prime number is listed n times
Sequences (Example)

• How can you produce the terms of the


following sequence?
5, 11, 17, 23, 29, 35, 41, …
Sequences (Example)
• How can you produce the terms of the
following sequence?
5, 11, 17, 23, 29, 35, 41, …
Solution:
• The formula for expressing arithmetic
sequences in their explicit form is:
𝑎𝑛=𝑎1+(𝑛−1)⋅𝑑
The explicit form of this arithmetic sequence is:
𝑎𝑛=5+(𝑛−1)⋅6= 6n-1
A rule for generating this sequence is 6𝑛 − 1
Sequences (Example)

• Find a formula for the following sequence.

15, 8, 1, −6, −13, −20, −27, …

Solution:

Each term is 7 less than the previous term.


𝑎𝑛 = 22 − 7𝑛
Sequences (Example)

• Find a formula for the following sequence?

2, 16, 54, 128, 250, 432, 686, …

Solution:

Each term is twice the cube of 𝑛.


𝑎𝑛 = 2 ∗ 𝑛3
Sequences (Example)

• Find formula for the following sequence.

1, 7, 25, 79, 241, 727, 2185, …

Solution:

Compare it to {3𝑛 }.
{3𝑛 −2}
Summations/Series
Summations

• The sum of the terms 𝑎𝑚 , 𝑎𝑚+1 , … , 𝑎𝑛 from the


sequence {𝑎𝑛 } is:
𝑎𝑚 , 𝑎𝑚+1 , … , 𝑎𝑛
𝑛

෍ 𝑎𝑗
𝑗=𝑚
• σ𝑚≤𝑗≤𝑛 𝑎𝑗 , where σ donates summation and j
is the index of summation.
• m is lower limit and n is upper limit.
Summations
The symbol “” takes a sequence of numbers
and turns it into a sum.
Symbolically:
n

a
i =0
i = a0 + a1 + a2 + ... + an

This is read as “the sum from i =0 to i =n of ai”


• Note how “” converts commas into plus signs.
• One can also take sums over a set of numbers:

x
xS
2
Summations/Series

• A summation:
𝑛

෍ 𝑎𝑗
𝑗=𝑚
is like a for loop:
int sum = 0;
for ( int j = m; j <= n; j++ )
sum += a(j);
Summations (Example)

Express the sum of the first 100 terms of the


sequence {1/n} for n=1,2,3,… .

Solution:

100

෍ 1ൗ𝑛
𝑛=1
Summations on Sets (Example)
Summations (Example)

3
What is the value of ෌𝑖=1 𝑖 2 ?

Solution:

෍ 𝑖 2 = 1 + 4 + 9 = 14
𝑖=1
More Summations (Example)

• σ5𝑘=1(𝑘 + 1) = 1 + 1 + 2 + 1 + 3 + 1 +
4+1 + 5+1 =2 + 3 + 4 + 5 + 6 =
20

• σ4𝑘=0(−2)𝑘 = −2 0 + −2 1 + −2 2 +
−2 3 + −2 4 = 1 + −2 + 4 + −8 +
16 = 11

• σ10
𝑘=1 3 = 3 + 3 + 3 + 3 + 3 + 3 + 3 +
3 + 3 + 3 = 30
More Summations (Example)
10
Evaluate ෌𝑘=1൫2𝑘 − 2𝑘−1 ) = ?

Solution:

10

෍ ൫2𝑘 − 2𝑘−1 ) = (21 − 𝟐𝟎 ) + (22 − 21 ) + (23 − 22 ) + (24 − 23 ) +


𝑘=1
25 − 24 ) + (26 − 25 ) + (27 − 26 ) + (28 − 27 ) + (29 − 28 ) + (𝟐𝟏𝟎 − 29

= −𝟏 + 𝟐𝟏𝟎 = −1 + 1024 = 1023


Properties of Summations
Example
𝑛 𝑛

3 ෍ (2𝑘 − 3) + ෍ (4 − 5𝑘)
𝑘=1 𝑘=1

n n
= 3 (2k − 3) +  (4 − 5k )
k =1 k =1
n n
= 3 (2k − 3) +  (4 − 5k )
k =1 k =1
n
=  [3(2k − 3) + (4 − 5k )]
k =1
n n n
=  ( k − 5) = k − 5
k =1 k =1 k =1
n
=  k − 5n
k =1
Shifting the Index of Summation

• Shifting the index of summation is often done


when two sums need to be added but their
indices of summation do not match.
• Make the appropriate changes in the
corresponding sum and index.
Example:
σ5𝑗=1 𝑗 2 shift the index of summation from 0 to 4
rather than from 1 to 5. to do this,
Shifting the Index of Summation
Example:
σ5𝑗=1 𝑗 2 shift the index of summation from 0 to 4 rather than
from 1 to 5.
Solution:
Here j starts with 1 and we want to start with 0. So assume
k=j-1 so, j= k + 1

It is easily checked that both sums are


1 + 4 + 9 + 16 + 25 = 55.
Double Summations

• Like a nested for loop


4
• ෍ σ3𝑗=1 𝑖𝑗
𝑖=1

Is equivalent to:
int sum = 0;
for ( int i = 1; i <= 4; i++ )
for ( int j = 1; j <= 3; j++
)
sum += i*j;
Double Summations

4
• ෍ σ3𝑗=1 𝑖𝑗
𝑖=1
• Solution:
Example

3
2
𝑆𝑜𝑙𝑣𝑒 ෍ ෌𝑗=1(𝑖 − 𝑗).
𝑖=1
Some Useful Summations
Example

100
Find σ𝑘=50 𝑘 2 .
Example

200
Find σ𝑘=100 𝑘.
200 3
Find σ𝑘=99 𝑘 .
Exercise Questions

Chapter # 2
Topic # 2.4
Questions 1, 2,3, 4, 25, 26, 29, 30,31, 32, 33, 34,
39, 40,41,42
CSC102 - Discrete Structures
(Discrete Mathematics)
Counting Techniques

Lecture 24-25
Lecture Outline

• Counting
– Product Rule
– Sum Rule
– Product and Sum rule mix questions
– Inclusion-Exclusion Principle

6/9/2025 CSC102 - Discrete Structures 3


Counting Applications

• Counting has many applications in computer


science and mathematics.

• For example,
– Counting the number of operations used by an
algorithm to study its time complexity
– Counting the successful outcomes of experiments
– Counting all the possible outcomes of experiments
– …
Basic Counting Principles

• Two basic counting principles


– The product rule
– The sum rule
The product rule

• Also called the multiplication rule


• If there are n1 ways to do task 1, and n2 ways to do
task 2
– Then there are n1n2 ways to do both tasks in sequence
– This applies when doing the “procedure” is made up of
separate tasks
– We must make one choice AND a second choice

6
The Product Rule
• Suppose that a procedure can be broken into a
sequence of two tasks.
• Assume there are n1 ways to do the first task.
• Assume for each of these ways of doing the
first task, there are n2 ways to do the second
task.
• So, there are n1 n2 ways to do the procedure.
– This applies when doing the “procedure” is made
up of separate tasks
– We must make one choice AND a second choice
The Product Rule
Example
T-1

F-1 T-2

T-3

T-1

F-2 T-2

T-3
Ice cream
T-1

F-3 T-2

T-3

T-1

F-4 T-2

T-3
Example

• There are 18 math majors and 25 CS majors


• How many ways are there to pick one math major and
one CS major?
Course

• Solution: Math CS
• Break the procedure into tasks
– Task 1: Math major 18 25
– Task 2: CS major
– By product rule, There are 18 * 25 = 450 ways to pick
courses.
Example

• There are 32 microcomputers in a computer center.


Each microcomputer has 24 ports. How many different
ports to a microcomputer in the center are there.

• Solution:
• Break the procedure into tasks
– Task 1: Choosing a microcomputer
– Task 2: Choosing a port
– By product rule, There are 32*24 = 768 ways to choose a
port to a microcomputer.
Example

• The chairs of an auditorium are to be labeled


with a letter and a positive integer not exceeding
100. How many chairs can be labeled differently?

• Solution:
• Break the procedure into tasks
– Task 1: assigning one of the 26 letters
– Task 2: assigning one of the 100 possible integers
– By product rule, There are 26*100 = 2600 ways to
assign labels to the chairs.
Example
• A new company with just two employees,
rents a floor of a building with 12 offices. How
many ways are there to assign different offices
to these two employees? Office

• Solution: Employee-1 Employee-2

Break into tasks


– Task 1: assigning an office to employee 1 12 11
– Task 2: assigning an office to employee 2
– There are 12 *11 = 132 ways to assign offices to two employees.
Extended Version of The Product Rule

• A procedure can be broken down into a


sequence of tasks T1 , T2 , … , Tm
• Assume each task Ti (i = 1,2, … , m), can be
done in 𝑛𝑖 different ways, regardless of how
the previous tasks were done.
• The procedure can be done in
n1 . n2 … nm different ways.
Example

• How many different bit strings of length seven are there?


• Solution:
• Break the procedure into tasks b7 b6 b5 b4 b3 b2 b1
– Task 1: assigning bit 1 to 0 or 1 2 2 2 2 2 2 2
– Task 2: assigning bit 2 to 0 or 1
– …
– Task 7: assigning bit 7 to 0 or 1
• Count different ways of doing each task and then use the
product rule
– Each task can be done in 2 different ways.
– By product rule, There are 27 = 128 different bit strings of length
seven.
Example

• How many uppercase English letter strings of


length three are there?
L1 L2 L3
= 263
26 26 26
• Other versions of above question:
L1 L2 L3
(Same letter not repeated)
26 25 24

A L2 L3
(Start with Letter A)
1 26 26

A L2 L3
(Start with Letter A and same letter not repeated)
1 25 24
Example
• The format of telephone numbers in North America is
specified by a numbering plan.
– Let X denote a digit between 0 and 9. X N Y
– Let N denote a digit between 2 and 9. 10 8 2
– Let Y denote a digit between 0 and 1.
– In the old plan, The format of telephone numbers is NYX-
NNX-XXXX.
– In the new plan, The format of telephone numbers is NXX-
NXX-XXXX.
• How many north American telephone numbers are
possible under the old plan and under the new plan.
Example
In the old plan, the formats of the area code, office code,
and station code are NYX, NNX, and XXXX, respectively, so
that telephone numbers had the form NYX-NNX-XXXX.
Solution: X N Y
10 8 2
• 8 ∗ 2 ∗ 10 = 160 area codes with format NYX.
• 8 ∗ 8 ∗ 10 = 640 office codes with format NNX.
• 10 ∗ 10 ∗ 10 ∗ 10 = 10,000 station codes with format
XXXX.
• Consequently, applying the product rule again, it follows
that under the old plan, 160 ∗ 640 ∗ 10,000 =
1,024,000,000
• Under the new plan, 800 ∗ 800 ∗ 10,000 =
6,400,000,000
Example

• How many strings of 4 decimal digits, do not


contain the same digit twice?

• Solution:
d 4 d3 d 2 d1
10 9 8 7
10 ∗ 9 ∗ 8 ∗ 7 = 5040 𝑤𝑎𝑦𝑠
Example

• How many different license plates are


available if each plate contains a sequence of
three letters followed by three digits?
L1 L2 L3 D1 D2 D3
26 26 26 10 10 10

• 26 ∗ 26 ∗ 26 ∗ 10 ∗ 10 ∗ 10 =
17,576,000 possible license plates
Example
• If repetitions of letters is not allowed:
L1 L2 L3 D1 D2 D3
26 25 24 10 10 10 26 * 25* 24 *10 *10 *10

• If repetitions of letters and digits are not allowed:


L1 L2 L3 D1 D2 D3
26 25 24 10 9 8 26 * 25* 24 *10 *9*8
• If sequence of letters is LHE and repetitions of
digits are not allowed:
L H E D1 D2 D3
1*1*1*10 *9*8
1 1 1 10 9 8
Example
• What is the value of k after the following code
has been executed?
int k = 0;
for (int i = 1; i  7; i + +)
for (int j = 1; j  8; j + +)
for (int n = 1; n  10; n + +)
k = k + 1;

• Solution:
• 7 ∗ 8 ∗ 10 = 560
Example
• What is the value of k after the following code
has been executed?

• Solution:
• Task i: traversing the i-th loop. (1≤i≤m)
• By the product rule, the nested loops traversed
n1 n2 … nm times.
• So the final value of k is n1 n2 … nm .
The Sum Rule
The sum rule

• If there are n1 ways to do task 1, and n2 ways to do


task 2
• Also called the addition rule
– If these tasks can be done at the same time, then…
– Then there are n1+n2 ways to do one of the two tasks
– We must make one choice OR a second choice

25
The Sum Rule
• Also called the addition rule.
• Assume a task can be done either in one of n1
ways or in one of n2 ways.
• Assume none of the set of n1 ways is the same
as any of the set n2 ways.
• If these tasks can be done at the same time,
then there are n1 + n2 ways to do the task.
• We must make one choice OR a second choice.

26
The Sum Rule
Example
• There are 18 math majors and 25 CS majors
• How many ways are there to pick one math
major or one CS major?
• Solution:

– There are 18 ways to pick Math major


– There are 25 ways to pick CS major

• By the sum rule, there are 18 + 25= 43


different ways to pick courses.
Example
• Assume there are 37 members of the
mathematics faculty and 83 mathematics majors.
• Either a member of the mathematics faculty or a
student who is a mathematics major is chosen as
a representative to a university committee.
• How many different ways to choose this
representative? Representative

Solution:
37+83=120 Faculty Students

37 83
Extended Version of The Sum Rule

• Suppose a task can be done in one of n1 ways,


in one of n2 ways, …, or in one of nm ways.
• Assume none of the set of ni ways of doing
the task is the same as any of the set of
nj ways, for all pairs 𝑖 and 𝑗 with 1 ≤ 𝑖 <
𝑗 ≤ 𝑚.
• The task can be done in n1 + n2 + ⋯ + nm
different ways.
Example
• A student can choose a computer project from
one of three lists. The three lists contains 23, 15
and 19 possible projects. No project is on more
than one list.
• How many possible projects are there to choose
from?
Project
• Solution:
List-1 List-2 List-3
23 + 15 + 19 = 57

23 15 19
Example
• What is the value of k after the following code
has been executed?
int k = 0;
for (int i = 1; i  7; i + +)
k = k + 1;
for (int j = 1; j  8; j + +)
k = k + 1;
for (int n = 1; n  10; n + + )
k = k + 1;
• Solution:
• 7 + 8 + 10 = 25
Example
• What is the value of k after the following code
has been executed?

• Solution:
• Task i: traversing the i-th loop. (1 ≤ 𝑖 ≤ 𝑚 )
• By the sum rule, the final value of k is n1 + n2 +
⋯ + nm .
The Product Rule and The Sum Rule

• Some complicated counting problems can be


solved using both the product rule and the
sum rule.
Example
• In a version of the computer language BASIC, the name of a
variable is a string of one character or two alphanumeric
characters, where uppercase and lowercase letters are not
distinguished. (An alphanumeric character is either one of
the 26 English letters or one of the 10 digits.) Moreover, a
variable name must begin with a letter. How many different
variable names are there in this version of BASIC?

• V1 (L): variable name with one character. (int a)


• V2 (LA): variable name with two alphanumeric
characters. (int aa; int a1;)
• 𝑉1 = 26, 𝑉2 = 26 ∗ 36 = 936
• 𝑉1 + 𝑉2 = 26 + 936 = 962
L D A= L+D
26 10 26 + 10 = 36
Example

• How many license plates can be made using


either three digits followed by three uppercase
English letters or three uppercase English letters
followed by three digits?
D1 D2 D3 L1 L2 L3
+
L1 L2 L3 D1 D2 D3

103 ∗ 263 + 263 ∗ 103


Example

• How many license plates can be made using


either two uppercase English letters followed by
four digits or two digits followed by four
uppercase English letters?
L1 L2 D1 D2 D3 D4
+
D1 D2 L1 L2 L3 L4

262 ∗ 104 + 102 ∗ 264


Example
How many three-digit integers are divisible by 5?
Solution:
Integers that are divisible by 5, end either in 5 or in 0.
CASE-I (Integers that end in 0)
There are nine choices for the left-most digit (the digits 1 through 9)
and ten choices for the middle digit.(the digits 0 through 9)
Hence, total number of 3 digit integers that end in 0 is

9 choices (1 to 9) 10 choices (0 to 9) 1 choice (digit 0)

9x10x1= 90
Example
How many three-digit integers are divisible by 5?
Solution:
Integers that are divisible by 5, end either in 5 or in 0.
CASE-II (Integers that end in 5)
There are nine choices for the left-most digit (the digits 1 through 9)
and ten choices for the middle digit.(the digits 0 through 9)
Hence, total number of 3 digit integers that end in 5 is
9 choices (1 to 9) 10 choices (0 to 9) 1 choice (digit 5)

9x10x1= 90
Finally, by sum rule, the number of 3 digit integers that are
divisible by 5 is
90 + 90 = 180
The Inclusion-Exclusion Principle
The Inclusion-Exclusion Principle

• Suppose a task can be done in 𝑛1 or in 𝑛2


ways.
• However, some of the set of 𝑛1 ways are the
same as some of the 𝑛2 other ways.
• To count the number of ways to the task, we
add 𝑛1 and 𝑛2 and subtract the number of
ways that is common in 𝑛1 ways and 𝑛2 ways.
A B = A + B − A B
Example

• How many bit strings of length eight either


start with a 1 bit or end with two bits 00?
Solution:
b7 b6 b5 b4 b3 b2 b1 b0
Possibilities for 2 2 2 2 2 2 2 1
Bits starting with 1
Possibilities for bits 1 1 2 2 2 2 2 2
ending with 0
Common in both 2 2 2 2 2
Example
• How many bit strings of length eight either start
with a 1 bit or end with two bits 00?
Solution:
• Task 1: bit strings of length eight starts with 1.
• Task 2: bit strings of length eight ends with 00.
– By the product rule, the number of task 1 is 27 .
– By the product rule, the number of task 2 is 26 .
– Common in task 1 and task 2 and the number of them
are 25 .
– By inclusion-exclusion principles, the number of such
strings is 27 + 26 − 25 = 160.

A B = A + B − A B
Example
• How many uppercase English letter strings of length three
either start with letter A or end with letter C?
Solution:
• Task 1: Strings start with letter A.
• Task 2: Strings end with letter C.
– By the product rule, the number of task 1 is 262 .
– By the product rule, the number of task 2 is 262 .
– Common in task 1 and task 2 and the number of them are
26.
– By inclusion-exclusion principles, the number of such
strings are:
262 + 262 − 26 = 1326.

A B = A + B − A B
Exercise Questions

Chapter # 6
Topic # 6.1
Q 1,2,3,4,5,6,7,8,9,10,11,28,29,30,31,32,33-a,b
Chapter Reading
Topic # 6.1(The Basics of Counting)
Lecture 24

Recursion

Chapter # 5
Topic 5.3
Lecture Outline

Recursion
– Recursive definition of function
– Recursive definition of sequence
– Recursive definition of sets

6/9/2025 CSC102 - Discrete Structures 2


Recursion

– Recursion is the process of repeating items in a self-similar


way.

– Sometimes it is difficult to define an object explicitly, but it is


easier to define it in terms of itself.
Recursion

• Definition for odd positive integers may be given as:


BASE:
1 is an odd positive integer.
RECURSION:
If k is an odd positive integer, then k + 2 is an
odd positive integer.
Now, 1 is an odd positive integer by the definition base.
With k = 1, 1 + 2 = 3, so 3 is an odd positive integer.
With k = 3, 3 + 2 = 5, so 5 is an odd positive integer
and so, 7, 9, 11, … are odd positive integers.
Factorial Recursive Function

int factorial(int n)
{
if(n == 0) Basis Step
return 1;
else Recursive Step
return n * factorial(n - 1);
}
Recursive Functions

• The process of defining an object in terms of


smaller versions of itself is called recursion.
• A recursive definition has two parts:
– Basic step: An initial simple definition which
cannot be expressed in terms of smaller versions
of itself. e.g. : f(0) = 1
– Recursive step: A rule for finding the value of the
function at an integer from its values at smaller
integers.e.g. : f(n+1) = 2 * f(n)
• Many common functions can be defined
recursively.
Example

• Can you write n! as a recursive function


– F(0) = 1
– F(n) = n * F(n-1)
– What is the value of F(5)?

• F(5) = 5 F(4)
= 5 . 4 F(3)
= 5 . 4 . 3 F(2)
= 5 . 4 . 3 . 2 F(1)
= 5 . 4 . 3 . 2 . 1 F(0)
= 5 . 4 . 3 . 2 . 1 . 1 = 120
Example

Suppose that f is defined recursively by


– f(0) = 3,
– f(n+1) = 2 f(n)+3. for n ≥ 1
Find f(3).
Solution:
f(3) = 2 f(2) + 3 = 2(21) + 3 = 45
f(2) = 2 f(1) + 3 = 2(9) + 3 = 21
f(1) = 2 f(0) + 3 = 2(3) + 3 = 9
Example

Suppose that f is defined recursively by


– f(0) = -1, f(1) = 2
– f(n+1) = f(n)+3f(n-1), for n ≥ 2
Find f(4).
Solution:
f(4) = f(3) + 3f(2) = 5 + 3(-1) = 2
f(3) = f(2) + 3f(1) = -1 + 3(2) = 5
f(2) = f(1) + 3f(0) = 2 + 3(-1) = -1
Example

– Fibonacci Numbers
• F(0) = 0, F(1) = 1
• F(n) = F(n-1) + F(n-2) for n = 2, 3, 4,……
– Find the Fibonacci number F(4).
Solution:
F(4) = F(3) + F(2) = 2 + 1 = 3
F(3) = F(2) + F(1) =1 + 1 = 2
F(2) = F(1) + F(0) = 1 + 0 = 1
Example

• Let a and b denote positive integers. Suppose


a function Q is defined recursively as follows:
• Find the value of Q(4,5) and Q(14,3).
• Find Q(55, 7).
0 if a  b
Q ( a, b) = 
 Q ( a − b, b ) + 1 if a  b

Q (4,5) = 0 if a  b
Example
0 if a  b
Q ( a, b) = 
 Q ( a − b, b ) + 1 if a  b
Q (14, 3) = Q (14 − 3, 3) + 1 = Q (11, 3) + 1
Q (11, 3) = Q (8, 3) + 1
Q (8, 3) = Q (5, 3) + 1
Q (5, 3) = Q (2, 3) + 1
Q (2, 3) = 0
Q (5, 3) = 0 + 1 = 1
Q (8, 3) = 1 + 1 = 2
Q (11, 3) = 2 + 1 = 3
Q (14, 3) = 3 + 1 = 4
Recursive Algorithms
– An algorithm is called recursive if it solves a problem by
reducing it to a smaller instance of the same problem.
– Computing n!
int factorial(int n)
{ If (n==0; return 1;
else return n*factorial(n-1); }
– Computing GCD
gcd(a,b)
/* assumption a < b */
If a=0, then return b
Else return gcd(b mod a, a)
Example

b if a = 0
gcd( a, b) = 
 gcd(b% a, a ) if a  b
Find gcd(30,108).

gcd(30,108) = gcd(108%30, 30)


= gcd(18, 30) = gcd(30%18,18)
= gcd(12,18) = gcd(18%12,12)
= gcd(6,12) = gcd(12%6, 6)
= gcd(0, 6) = 6
Sequence
Find the explicit formula and recursive formula of following sequence:
2,4,8,16,32,…
– An explicit formula or general formula for a sequence is a rule that
shows how the values of an depends on n (Term no)

Explicit Formula: Recursive Formula:


a=2 a2 = 2a1
Basis Step :
r=2 a3 = 2a2
a1 = 2
an = ar n −1
a4 = 2a3
n −1 Recursive Step :
an = 2(2)
an = 2n
an +1 = 2an an +1 = 2an

After giving the first term, each term of the sequence can be defined from
the previous term.
Sequence
Find the explicit formula and recursive formula of
following sequence:
5,10,15,20,25,…

Explicit Formula: Recursive Formula:

a=5 Basis Step : a2 = a1 + 5


d =5 a1 = 5 a3 = a2 + 5
an = a + (n − 1)d Recursive Step : a4 = a3 + 5
an = 5 + ( n − 1)5 an +1 = an + 5
an = 5n an +1 = an + 5

After giving the first term, each term of the sequence can
be defined from the previous term.
Recursively Defined Sets

• Assume S is a set.
• We use two steps to define the elements of S.
• Basis step:
– Specify an initial collection of elements.
• Recursive step:
– Give a rule for forming new elements from those already
known to be in S.
Recursively Defined Sets
• Consider S ⊆ Z defined by
• Basis step: (Specify initial elements.)
– 0S
• Recursive step: (Give a rule using existing elements)
– If x  S, then 2x + 2  S.

• No. of elements in set S after applying 3 time recursion


• 0
• 0, 2 (1st)
• 0, 2, 6 (2nd)
• 0, 2, 6, 14 (3rd)
Recursively Defined Sets

• Consider S ⊆ Z defined by
• Basis step: (Specify initial elements.)
– 3S
• Recursive step: (Give a rule using existing elements)
– If x  S and y  S, then x + y  S.
• No. of elements in set S after applying 3 time recursion
• 3
• 3, 6 (1st)
• 3, 6, 9, 12 (2nd)
• 3, 6, 9, 12, 15, 18, 21, 24 (3rd)
• This is the set of all positive multiples of 3.
Exercise Questions

Chapter # 5
Topic # 5.3
Q. 1, 2, 3, 4, 7, 28-a, Ackermann’s Function(50,
53)
Lecture 25
Lecture Outline
• Graphs
– Undirected Graph
– Directed Graph
– Graph Models
– Graph Terminologies
– Degree of a vertex

6/9/2025 CSC102 - Discrete Structures 2


Graphs

• What are graphs?


– A class of discrete structures useful for representing relations
among objects.
– Vertices (nodes) connected by edges.
– Theory about graphs can be used to solve a lot of important
problems
The First Graph Theory
– The first graph theory paper by Leonhard Euler in 1736
– Seven bridges of Königsberg, A town with 7 bridges and 4
pieces of land…
The Origin of Graph Theory
• Can we travel each bridge exactly once and
return to the starting point?
Graphs

• Graph
– Directed
– Undirected
Graphs

• Graph
• Directed Edge Un-directed
Edge

a b a b
terminal
Initial
vertex
vertex
Ordered pair Un-ordered pair
( a, b) {a, b}

7
Definition - Graphs
– A graph G = (V, E) is defined by a set of vertices V , and a set of
edges E consisting of ordered or unordered pairs of vertices
from V.
– Thus a graph G = (V, E)
• V = set of vertices
• E = set of edges = subset of V  V

• Each edge has either one or two vertices


associated with it, called its endpoints.
• An edge is said to connect its endpoints.
8
Graphs
Graphs
Simple Graphs

– A graph in which each edge connects two different vertices


and where no two edges connect the same pair of vertices.
Example
Multigraph
• A multigraph: multiple edges
connecting the same nodes

• E.g., nodes are cities, edges are


segments of major highways.
Pseudographs
– Pseudograph: Like a multigraph, but edges connecting a node
to itself are allowed.
Directed Graphs

– A directed graph (or digraph) (V,E) consists of a set of vertices


V and a set of directed edges E on V. Each directed edge is
associated with an ordered pair of vertices. The directed edge
associated with the ordered pair (u,v) is said to start at u and
end at v.
Simple Directed Graph

A directed graph that has no loops and has no multiple


directed edges is called a simple directed graph.
Directed Multigraphs
– A directed multigraph has directed parallel edges.

6/9/2025 CSC102 - Discrete Structures 17


Types of Graphs: Summary
– Summary of the book’s definitions.
– Keep in mind these terminology is not fully standardized
across different authors...

Type Edges Multiple Edges Loops


Allowed? Allowed?
Simple Graphs Undirected No No
Multigraph Undirected Yes No
Pseudograph Undirected Yes Yes
Simple directed Directed No No
graph
Directed Directed Yes Yes
multigraph
Graph Models: Acquaintanceship Graph
– Represent whether two people know each other, that is, whether
they are acquainted.
– Each person in a particular group of people is represented by a
vertex.
– Undirected edge is used to connect two people when these people
know each other.
– No multiple edges are used.
– Usually no loops are used. (If we want to include the notion of self-
knowledge, we would include loops.)
Example
Graph Models: An Influence Graph

– A directed edge (a, b) means a can influence b.


– E.g. (Fred, Brian) means Fred can influence Brian.
Example

• Construct an influence graph for the board members of a


company if the President can influence the Director of Research
and Development, the Director of Marketing and the Director of
Operations; the Director of Research and Development can
influence the Director of Operations; the Director of Marketing
can influence the Director of Operations; and no one can
influence, or be influenced by, the Chief Financial Officer.
Graph Models: Round Robin Tournaments

– A tournament where each team plays each other team exactly


once.

– Such tournaments can be modeled using directed graphs


where each team is represented by a vertex. Note that (a, b) is
an edge if team ‘a’ beats team ‘b’. This graph is a simple
directed graph, containing no loops or multiple directed
edges.
Example

Team 1 is undefeated in this tournament, and Team 3 is


winless.
Graph Models: Intersection Graph
– The intersection graph of a collections of sets
𝐴1 , 𝐴2 , 𝐴3 , … , 𝐴𝑛 is the graph that has a vertex for
each of these sets and has an edge connecting the
vertices representing two sets if these sets have a
non empty intersection.
– 𝐴1 = {0, 2, 4, 6, 8}
– 𝐴2 = {0, 1, 2, 3, 4}
– 𝐴3 = {1, 3, 5, 7, 11}
– 𝐴4 = {1, 4, 9, 16, 25}
Example

– 𝐴1 = {0, 2, 4, 6, 8}
– 𝐴2 = {0, 1, 2, 3, 4}
– 𝐴3 = {1, 3, 5, 7, 11}
– 𝐴4 = {1, 4, 9, 16, 25}
– Draw an edge if intersection is not empty.
– E.g.
A1 A2

𝐴1 ⋂A2 = {0, 2, 4}
𝐴1 ⋂ 𝐴3 = φ
𝐴1 ⋂A4 = 4
A3
A4
Graph Models: Precedence graph
• Each statement is represented by a vertex
• There is an edge from one statement to a second statement if
the second statement cannot be executed before the first
statement.
Graph Terminologies

– Adjacent:
Let G be an undirected graph with edge set E. Let e ∈ E be (or map
to) the pair {u,v}. Then we say:

– u, v are adjacent / neighbors / connected.

– Edge e is incident with vertices u and v.

– Edge e connects u and v.

– Vertices u and v are endpoints of edge e.


Degree of a Vertex

– Let G be an undirected graph, v ∈ V a vertex.


– The degree of v, deg(v), is its number of incident edges.
(Except that any self-loops are counted twice.)

deg(a) = 3
deg(b) = 5
deg(c) = 5
deg(d) = 5
deg(e) = 0 (isolated vertex)

Pendant vertex = with degree 1

G1
Example
• What is the degree of each vertex of the following graph?

A1 A2

A3
A4

deg(A1) = 2 deg(a) = 4
deg(A2) = 3 deg(b) = 6
deg(A3) = 2 deg(c) = 1
deg(A4) = 3 deg(d) = 5
deg(e) =6
Handshaking Theorem
– Let G be an undirected (simple, multi-, or pseudo-) graph with
vertex set V and edge set E. Then

 deg(v) = 2 E
vV

 deg(v) = deg(a) + deg(b) + deg(c) + deg(d ) + deg(e) = 18 = 2 | E |


v{a ,b ,c , d ,e}

• deg(a)=3, deg(b)=5, deg(c)=5, deg(d)=5,


deg(e)=0
Example

deg(a) = 3 deg(a) = 4
deg(b) = 5 deg(b) = 6
deg(c) = 5 deg(c) = 1
deg(d) = 5 deg(d) = 5
deg(e) =0 deg(e) =6

Total degree=18 Total degree=22


=2(9) =2(11)
Edges =9 Edges =11
Example
• How many edges are there in a graph with 10
vertices each of degree six?
Edges=10*6= 60=2(30)=2(E)

• If a graph has 5 vertices, can each vertex have


degree 3?
Edges=5*3= 15 cant be represented s multiple of 2,
Therefore Graph not possible
Handshaking Theorem
– Any undirected graph has an even number of vertices of odd
degree.
– Let 𝑉1 and 𝑉2 be the set of vertices of even and odd degrees
respectively, in an undirected graph, then

2e =  deg(v) =  deg(v) +  deg(v)


vV vV1 vV2

must be even because 2e is


must be even even and first Sum for v1 is
since deg(v) is already even, therefore this term
even for each v must also result in even number.
– |𝑉2 | has to be even. Because all the terms in
∈ V1
this sum are odd, there must be
an even number of such terms.
Thus, there are an even number
of vertices of odd degree.
Example

2 vertices with 4 vertices with 2 vertices with


odd degree odd degree odd degree

deg(A1) = 2 deg(a) = 3 deg(a) = 4


deg(A2) = 3 deg(b) = 5 deg(b) = 6
deg(A3) = 2 deg(c) = 5 deg(c) = 1
deg(A4) = 3 deg(d) = 5 deg(d) = 5
deg(e) =0 deg(e) =6
Directed Degree

– When (𝑢, 𝑣) is an edge of the graph G with directed edges, 𝑢


is said to be adjacent to 𝑣. The vertex 𝑢 is called the initial
vertex of 𝑢, 𝑣 , and 𝑣 is called the terminal or end vertex of
𝑢, 𝑣 .

– The initial vertex and terminal vertex of a loop are the same.
Directed Degree

– Let G be a directed graph, v a vertex of G.


– The in-degree of v, 𝑑𝑒𝑔− (𝑣), is the number of edges with 𝑣 as their
terminal vertex.
– The out-degree of v, 𝑑𝑒𝑔+ (𝑣), is the number of edges with 𝑣 as
their initial vertex.
– The degree of v, deg(𝑣): ≡ 𝑑𝑒𝑔− 𝑣 + 𝑑𝑒𝑔+ (𝑣)is the sum of v’s
in-degree and out-degree.
– Loop at a vertex contributes 1 to both the in-degree and the out-
degree of this vertex.
Example

– Determine in/out-degree of each vertex of Graph G.


Example

– Determine in/out-degree of each vertex of Graph G.


in- degree out - degree
deg − (a) = 2 deg + ( a ) = 4
deg − (b) = 2 deg + (b) = 1
deg − (c) = 3 deg + (c) = 2
deg − (d ) = 2 deg + ( d ) = 2
deg − (e) = 3 deg + (e) = 3
deg − ( f ) = 0 deg + ( f ) = 0
Total = 12 Total = 12
Theorem
• Let G = (𝑉, 𝐸) be a graph with directed edges
then
 deg
vV

(v ) =  deg
vV
+
(v ) = E

• The first sum counts the number of incoming


edges over all vertices and the second sum
counts the number of outgoing edges over all
vertices Both sums must be |E|.
Chapter Exercise
• Chapter # 10
Topic # 10.1
• Q – 1,3,4,5,6,7,8,9,13,16,19,21,22
Topic # 10.2
• Q -1,2,3,4,7,8,9,10,21,22,23,24,27
Lecture ----
Lecture Outline

• Graphs
– Special Graph Structures
– Sub Graph
– Adjacency List and Adjacency Matrix
– Incidence Matrix
– Path and Distance Matrix

6/20/2025 CSC102 - Discrete Structures 2


Special Graph Structures

– Special cases of undirected graph structures:


– Complete graphs 𝐾𝑛
– Cycles 𝐶𝑛
– Wheels 𝑊𝑛
– Bipartite graphs
Complete Graphs
• For any 𝑛 ∈ 𝑁, a complete graph on n vertices, denoted by
𝐾𝑛 , is a simple graph with n nodes in which every node is
adjacent to every other node.∀𝑢,𝑣∈𝑉 : 𝑢 ≠ 𝑣 {𝑢, 𝑣} ∈ 𝐸.
• A simple graph for which there is at least one pair of distinct
vertex not connect with edge is called non complete.
• Note: 𝐾𝑛 has 𝑛(𝑛 − 1)/2 edges.
Cycles

• A cycle 𝐶𝑛 , n ≥ 3, is a simple graph consisting of n


vertices such that
𝑉 = 𝑣1 , 𝑣2 , … , 𝑣𝑛 𝑎𝑛𝑑 𝑒𝑑𝑔𝑒𝑠
𝐸 = {{𝑣1 , 𝑣2 }, 𝑣2 , 𝑣3 , … , {𝑣𝑛−1 , 𝑣𝑛 }, {𝑣𝑛 , 𝑣1 }}

• How many edges are there in 𝐶𝑛 = 𝑛.


Wheels
• For any 𝑛 ≥ 3, a wheel 𝑊𝑛 , is a simple graph
obtained by taking the cycle 𝐶𝑛 and adding an
extra vertex 𝑉ℎ𝑢𝑏 and n extra edges
where {{𝑣ℎ𝑢𝑏 , 𝑣1 }, {𝑣ℎ𝑢𝑏 , 𝑣2 }, … , {𝑣ℎ𝑢𝑏 , 𝑣𝑛 }}.
• How many edges are there in 𝑊𝑛 = 2 𝑛
Note: Cycle with 4 edges is W3
• Cycle with 5 edges is W4, …
Bipartite Graph
• A graph G = {V, E} is bipartite graph (two parts)
if and only if 𝑉 = 𝑉1 𝑈 𝑉2 𝑤ℎ𝑒𝑟𝑒 𝑉1 ∩ 𝑉2 = ∅
and ∀𝑒∈𝐸 : ∃𝑣1 ∈ 𝑉1 , 𝑣2 ∈ 𝑉2 : 𝑒 = {𝑣1 , 𝑣2 }

Vertex set V can be partitioned into two


disjoint sets V1 and V2 such that every
edge in the graph connects a vertex in
V1 and a vertex in V2 (so that no edge in
G connects either two vertices in V1 or
two vertices in V2). When this condition
holds, we call the pair (V1, V2)
a bipartition of the vertex set V of G.
Example
Theorem

• A simple graph is bipartite if and only if it is


possible to assign one of two different colors
to each vertex of the graph so that no two
adjacent vertices are assigned the same color.
Example

• Is this bipartite?
a b

g
c

f
e d
Example

• Is this bipartite?
a b

g
c

f
e d
a b

Example g
c

f
• Is this bipartite? e d

a c

b
e

f
d
g
Example
Example
Not Bipartite,because adjacent nodes appear with same color.
Complete Bipartite Graphs

A complete bipartite graph Km,n is a graph that has its vertex


set partitioned into two subsets of m and n vertices, respectively
with an edge between two vertices iff one vertex is in the first
subset and the other vertex is in the second subset.
Sub-graphs

• A sub-graph of a graph G = (V ,E) is a graph H


= (W, F), where W ⊆ V and F ⊆ E.
• A sub-graph H of G is a proper sub-graph of G
if 𝐻 ≠ 𝐺.

G H
Graph Union
How to Represent a Graph?
• Mathematically, a graph G is represented by
two sets: vertex set V and edge Set E.
• G = (V, E), a tuple of two sets.
• How to represent a graph by computer?

• V = { a, b, c, d, e, f }

• E = {{a,b},{a,c},{b,c},
{b,e},{b,f},{c,f}}
Adjacency List

• A table with 1 row per vertex, listing its


adjacent vertices.
Adjacency Matrix

• Matrix 𝐴 = [𝑎𝑖𝑗 ], where 𝑎𝑖𝑗 is 1 if {𝑣𝑖 , 𝑣𝑗 } is


an edge of G, and is 0 otherwise.

6/20/2025
Adjacency List for Directed Graph
Adjacency Matrix for Directed Graph

Terminal Vertex

0 1 1 1 1
0 1 0 1 0
Initial
Vertex
1 0 1 0 1
0 0 0 0 0
0 1 1 1 0
Adjacency Matrix for Directed Graph

1 1 1 1
0 0 0 1
1 1 0 0
0 1 1 1
Example

Find the adjacency matrix of pseudograph?

a b c d
a 0 3 0 2
b 3 0 1 1
c 0 1 1 2
d 2 1 2 0
Incidence Matrix
• Let 𝐺 = (𝑉, 𝐸) be an undirected graph. Suppose
that 1,2, … , 𝑛 are the vertices and 𝑒1 , 𝑒2 , … , 𝑒𝑚 are
the edges of G. Then the incidence matrix with
respect to this ordering of V and E is 𝑛 × 𝑚 matrix
M = [𝑚𝑖𝑗 ], where
1 𝑤ℎ𝑒𝑛 𝑒𝑑𝑔𝑒 𝑒𝑗 𝑖𝑠 𝑖𝑛𝑐𝑖𝑑𝑒𝑛𝑡 𝑜𝑛 𝑖.
• 𝑚𝑖𝑗 = ቊ
0 𝑜𝑡ℎ𝑒𝑟𝑤𝑖𝑠𝑒
Example-Incidence Matrix
Example-Incidence Matrix
Path
• A path is a sequence of edges that begins at a
vertex of a graph and travels from vertex to
vertex along edges of the graph. (path does
not contain a repeated edge)
• Find a path between a and e.

a---e length=1
a---b---e length=2
a---b---f---e length=3
a---b---c---f---e length=4
Path
Find a path between a and e.
• a, d, c, f , e is a simple path of length 4, because {a, d},
{d, c}, {c, f }, and {f, e} are all edges.
• a, e is a simple path of length 1, because {a, e} is the
edge connecting both vertices.
• a, b, f , e is a simple path of length 3, because {a, b}, {b,
f}, and {f, e} are all edges.

a---e length=1
a---b---e length=2
a---b---f---e length=3
a---b---c---f---e length=4
Circuit

• The path is a circuit if it begins and ends at the


same vertex.

• Path a, b, c, d, a is a circuit.
Circuit

• The path is a circuit if it begins and ends at the


same vertex.

• Path a, b, c, d, a is a circuit.
Circuit
Walk – Path- circuit

Repeated Repeated Vertex Starts and Ends at Same Point


Edge
walk allowed Allowed allowed

closed walk allowed Allowed yes(means, where it starts also ends


at that point)
circuit no Allowed yes

simple circuit no first and last only yes

path no Allowed allowed

simple path no no No
Connected Graph

• An undirected graph is called connected if


there is a path between every pair of distinct
vertices of the graph.
Connected Graph
• The graph G1 is connected.
• The graph G2 is not connected. (For instance,
there is no path in G2 between vertices a and
d.)
Graph Distance

• The graph distance between two vertices in


a graph is the number of edges in a shortest
path connecting them.
• Also known as the geodesic distance.
• There may be more than one shortest path
between two vertices.
• If we compute the distance between every
pair of vertices of graph G, we can construct a
distance matrix D.
Eccentricity

• The eccentricity 𝒆(𝒗) of a vertex 𝒗 in a connected graph


𝑮(𝑽, 𝑬) is max 𝒅(𝒖, 𝒗), for all 𝒖 ∈ 𝑽. In other words, a
vertex’s eccentricity is equal to the distance from itself to
the vertex farthest away.

• The minimum eccentricity of all vertices in a graph is


called the radius of the graph,

• The maximum eccentricity of all vertices in a graph is the


diameter of the graph.
Example

Draw a undirected graph with the adjacency


matrix
0 1 1 0
1 0 1 1
1 1 0 1
0 1 1 0

with respect to the ordering of vertices a, b, c, d.


Find distance matrix of graph, eccentricity of
each vertex, diameter and radius of graph.
Example (Solution)
0 1 1 0
1 0 1 1 a b
1 1 0 1
0 1 1 0
Given Matrix
d c

We have four vertices; so


eccentricity of each vertex is
E(a)=2 0 1 1 2
E(b)=1 1 0 1 1
E(c)=1 1 1 0 1
E(d)=2 2 1 1 0
Distance Matrix
Radius =1
Diameter=2
Chapter Exercise
• Chapter # 10
Topic # 10.2
• Q -1,2,3,4,7,8,9,10,21,22,23,24,27
Topic # 10.3
• Q-1,2,3,4,5,6,7,8,10,11,12,13,14,
15,16,17,18,19,20,21,22,23,24,26,27
Lecture -----
Lecture Outline

• Graphs
– Path and Distance Matrix
• Trees
– Rooted Tree
– Tree Terminologies
– Ordered Rooted Tree
– Tree Traversal
– Infix, Prefix and Postfix Notation

6/20/2025 CSC102 - Discrete Structures 2


Walk – Path- circuit

Repeated Repeated Vertex Starts and Ends at Same Point


Edge
walk allowed Allowed allowed

closed walk allowed Allowed yes(means, where it starts also ends


at that point)
circuit no Allowed yes

simple circuit no first and last only yes

path no Allowed allowed

simple path no no No
Path
• A path is a sequence of edges that begins at a
vertex of a graph and travels from vertex to
vertex along edges of the graph. (path does
not contain a repeated edge)
• Find a path between a and e.

a---e length=1
a---b---e length=2
a---b---f---e length=3
a---b---c---f---e length=4
Path
Find a path between a and e.
• a, d, c, f , e is a simple path of length 4, because {a, d},
{d, c}, {c, f }, and {f, e} are all edges.
• a, e is a simple path of length 1, because {a, e} is the
edge connecting both vertices.
• a, b, f , e is a simple path of length 3, because {a, b}, {b,
f}, and {f, e} are all edges.

a---e length=1
a---b---e length=2
a---b---f---e length=3
a---b---c---f---e length=4
Circuit

• The path is a circuit if it begins and ends at the


same vertex.

• Path a, b, c, d, a is a circuit.
Circuit

• The path is a circuit if it begins and ends at the


same vertex.

• Path a, b, c, d, a is a circuit.
Circuit
Connected Graph

• An undirected graph is called connected if


there is a path between every pair of distinct
vertices of the graph.
Connected Graph
• The graph G1 is connected.
• The graph G2 is not connected. (For instance,
there is no path in G2 between vertices a and
d.)
Graph Distance

• The graph distance between two vertices in


a graph is the number of edges in a shortest
path connecting them.
• Also known as the geodesic distance.
• There may be more than one shortest path
between two vertices.
• If we compute the distance between every
pair of vertices of graph G, we can construct a
distance matrix D.
Eccentricity

• The eccentricity 𝒆(𝒗) of a vertex 𝒗 in a connected graph


𝑮(𝑽, 𝑬) is max 𝒅(𝒖, 𝒗), for all 𝒖 ∈ 𝑽. In other words, a
vertex’s eccentricity is equal to the distance from itself to
the vertex farthest away.

• The minimum eccentricity of all vertices in a graph is


called the radius of the graph,

• The maximum eccentricity of all vertices in a graph is the


diameter of the graph.
Example

Draw a undirected graph with the adjacency


matrix
0 1 1 0
1 0 1 1
1 1 0 1
0 1 1 0

with respect to the ordering of vertices a, b, c, d.


Find distance matrix of graph, eccentricity of
each vertex, diameter and radius of graph.
Example (Solution)
0 1 1 0
1 0 1 1 a b
1 1 0 1
0 1 1 0
Given Matrix
d c

We have four vertices; so


eccentricity of each vertex is
E(a)=2 0 1 1 2
E(b)=1 1 0 1 1
E(c)=1 1 1 0 1
E(d)=2 2 1 1 0
Distance Matrix
Radius =1
Diameter=2
Tree
Tree
• Trees are particularly useful in computer
science, where they are employed in a wide
range of algorithms.

Tree

• A tree is an undirected graph T such that


– T is connected
– T has no cycles (circuits)
• A tree cannot contain multiple edges or loops.
Therefore any tree must be a simple graph.
Applications of Tree
Trees are used to solve problems in a wide variety of
disciplines. In computer science trees are employed
to
1) construct efficient algorithms for locating items in a list.
2) construct networks with the least expensive set of
telephone lines linking distributed computers.
3) construct efficient codes for storing and transmitting
data.
4) model procedures that are carried out using a sequence
of decisions, which are valuable in the study of sorting
algorithms.
Example

Which of the graphs are trees?


Example

• G1 and G2 are trees, because both are


connected graphs with no simple circuits.
• G3 is not a tree because e, b, a, d, e is a simple
circuit in this graph.
• G4 is not a tree because it is not connected.
Forest

A forest is an undirected graph such that


• It has no simple circuits
• It is not necessarily connected
The connected components of a forest are trees
Rooted Tree
• A rooted tree is a tree in which one vertex has
been designated as the root and every edge is
directed away from the root.
• Root, parent, child, siblings relations between
vertices
Terminologies

• Suppose that T is a rooted


tree.
• If v is a vertex in T other than
the root, the parent of v is
the unique vertex u such that
there is a directed edge from
u to v. When u is the parent
of v, v is called a child of u.
• Vertices with the same
parent are called siblings.
Terminologies
• The ancestors of a vertex
other than the root are the
vertices in the path from the
root to this vertex, excluding
the vertex itself and
including the root (that is,
its parent, its parent’s
parent, and so on, until the
root is reached).
• The descendants of a vertex
v are those vertices that
have v as an ancestor.
Terminologies
• A vertex of a rooted tree is called
a leaf if it has no children.
• Vertices that have children are
called internal vertices. The root
is an internal vertex unless it is
the only vertex in the graph, in
which case it is a leaf.
• If v is a vertex in a tree, the
subtree with v as its root is the
subgraph of the tree consisting of
v and its descendants and all
edges incident to these
descendants.
Example
• In the rooted tree T (with root a), find the
parent of c, the children of g, the siblings of h,
all ancestors of e, all descendants of b, all
internal vertices, and all leaves.

• Parent of 𝐜: 𝑏
• Children of g: ℎ, 𝑖, 𝑗
• Siblings of 𝐡: 𝑖, 𝑗
• All ancestors of 𝐞: 𝑐, 𝑏, 𝑎
• All descendants of 𝐛: 𝑐, 𝑑, 𝑒
• All internal vertices: 𝑎, 𝑏, 𝑔, 𝑐, ℎ, 𝑗
• All leaves: 𝑓, 𝑑, 𝑒, 𝑖, 𝑘, 𝑙, 𝑚
A Rooted Tree T
Example
• In the rooted tree T (with root a), What is the
subtree rooted at g?

A Rooted Tree T Subtree Rooted at g


Rooted Tree

• A rooted tree is called an m-ary tree if every


internal vertex has no more than m children.
The tree is called a full m-ary tree if every
internal vertex has exactly m children. An m-ary
tree with m = 2 is called a binary tree.
Definitions
• The level of a vertex v in a rooted tree is the
length of the unique path from the root to this
vertex.

• The level of the root is defined to be zero.

• The height of a rooted tree is the maximum of


the levels of vertices. In other words, the
height of a rooted tree is the length of the
longest path from the root to any vertex.
Example
• Find the level of each vertex in the rooted tree
T. What is the height of this tree?
Balanced Trees

• A rooted m-ary tree of height h is balanced if


all leaves are at levels h or h − 1.
Ordered rooted Tree

• An ordered rooted tree is a rooted tree where


the children of each internal vertex are
ordered.

• In a drawing of an ordered rooted tree, with


the root shown at the top, the children of a
vertex are shown from left to right.
Ordered rooted Tree

• An ordered rooted tree is a rooted tree where


the children of each internal vertex are
ordered.
Tree Traversal and Traversal Algorithms

• Ordered rooted trees are often used to store


information. Tree traversal is the procedure of
visiting different vertices of the tree to read
information stored in that vertex. There are three
different orders of the tree traversal.
• Most commonly used algorithms:
– Preorder traversal
– In-order traversal
– Post-order traversal
• All recursively defined.
Preorder Traversal
• Let T be an ordered rooted tree with root r and 𝑇1, 𝑇2, … 𝑇𝑛 are
the subtrees at r from left to right. The preorder traversal
begins by visiting r . It continues by traversing 𝑇1 in preorder,
then 𝑇2 in preorder, then 𝑇3 in preorder, . . . , and finally 𝑇𝑛 in
preorder.
Preorder Traversal

Step
1
Step
1
Step
Step 1
3

Step
3
Step Step
Step Step 2 3
2 2
𝑐, 𝑎, 𝑏, 𝑓, 𝑔, 𝑑, 𝑒
Preorder Traversal

• Root, left, right


• Example:
F

B H

A D K

• F, B, A, D, H, K
Preorder Traversal
Postorder Traversal
• Let T be an ordered rooted tree with root r and
𝑇1, 𝑇2, … 𝑇𝑛 are the subtrees at r from left to right. The
postorder traversal begins by traversing 𝑇1 in
postorder, then 𝑇2 in postorder, then 𝑇3 in postorder, .
. . , and finally 𝑇𝑛 in postorder and ends by visiting r.
Post-order Traversal

Step
3
Step
3
Step
Step 3
2

Step
2
Step Step
Step Step 1 2
1 1
𝑓, 𝑔, 𝑏, 𝑑, 𝑎, 𝑒, 𝑐
Postorder Traversal

• Left, right, root


• Example:
F

B H

A D K

• A, D, B, K, H, F
Postorder Traversal
In order Traversal
• Let 𝑇 be an ordered rooted tree with root r and
𝑇1, 𝑇2, … 𝑇𝑛 are the subtrees at r from left to right.
The in order traversal begins by traversing 𝑇1 in
inorder, then visiting r. It continues by traversing 𝑇2
in inorder, then 𝑇3 in inorder, . .. , and finally 𝑇𝑛 in
inorder.
In-order Traversal

Step
2
Step
2
Step
Step 2
3

Step
3
Step Step
Step Step 1 3
1 1
𝑓, 𝑏, 𝑔, 𝑎, 𝑑, 𝑐, 𝑒
In-order Tree Walk

• Left, root, right


• Example:
F

B H

A D K

• A, B, D, F, H, K
Example
Binary Search Trees

• A Binary search tree is a binary tree in


symmetric order.
• Symmetric order means that:
– every node has a key
– every node’s key is
• larger than all keys in its left subtree
• smaller than all keys in its right subtree
Infix, Prefix and Postfix Notation

• We can represent complicated expressions using ordered


rooted tree.
• The representation of an arithmetic expression involving
operators + (addition), − (subtraction), ∗ (multiplication),
/ (division), and ↑ (exponentiation).
• An ordered rooted tree can be used to represent such
expressions, where the internal vertices represent
operations, and the leaves represent the variables or
numbers.
• Use parentheses to indicate the order of the operations.
• Each operation operates on its left and right sub trees (in
that order).
Example
• What is the ordered rooted tree that represents the expression
((𝑥 + 𝑦) ↑ 2) + ((𝑥 − 4)/3).
Example

preorder : +  + xy 2 / − x 43
postorder : xy + 2  x 4 − 3 / +
inorder : x + y  2 + x − 4 / 3
Infix, Prefix and Postfix form
• Infix Form
– It is the common arithmetic and logical formula notation,
in which operators are written between the operands

• Prefix Form
– Also known as Polish notation.
– A form of notation for logic, arithmetic, and algebra.
– It places operators to the left of their operands.

• Postfix Form
– Also known as Reverse Polish Notation.
– We obtain the postfix form of an expression by traversing
its tree in postorder.
Example

• What is the value of prefix expression + −  2 3 5/  2 3 4.


Example

• What is the value of postfix expression 7 2 3  − 4  9 3 / +.


Chapter Exercise

• Chapter # 11
• Topic # 11.1
• Question # 1, 2, 3, 4, 5, 6, 7, 8, 9,10
• Topic # 11.3
• Question # 7 – 18, 23 ,24

You might also like