Download as pdf or txt
Download as pdf or txt
You are on page 1of 706

Sets

• A Set is a well defined collection of


objects called the members/elements
of the set.
• Example 1 : The collection of three positive integers is not
a set as it is not well defined.
• Example 2 : The collection of three positive integers less
than 4 is a set as it is well defined. This set can be
represented as {1,2,3}.

• A = {1,2,3}
• A = {x:x is the collection of 3 positive integer less than 4}
Representation of a Set
• There are two ways to represent a set - Tabular form
representation { a, b, …} and Set builder form{x: x satisfies
some property.}
• Example 3 : The set of three positive integers less than 4
can be represented as {1,2,3} as well as in the form {𝒙 ∈
𝑵: 𝒙 < 𝟒}.
• {x:x is the positive integer less than 4} Set builder form
• Example 4 : The set of all real numbers between 1 and 2
can be represented {𝒙 ∈ 𝑹: 𝟏 < 𝒙 < 𝟐}.
Representation of a Set
• Membership of an element 𝑎 in a set 𝐴 is represented as
𝑎 ∈ 𝐴 if 𝑎 is an element of the set 𝐴 and 𝑎 ∉ 𝐴 if 𝑎 is not
an element of the set 𝐴.
• Example 5: Consider the set 𝐴 = 1,2,3,4 , then 3 ∈ 𝐴 but
5 ∉ 𝐴.
Subset: Let A and B be any two sets. A  B iff x A  x B
• Example 6: The set 𝐴 = 1,2,3,4 , is a subset of the set of all Natural
numbers N = 1,2,3,4,5,6, … .

A = 1,2,3,4,5,6 . B= 1,2,3,4
B is subset of A
Properties of Set

• Equal set: Two sets A and B are said to be equal set iff (AB
& B A)A=B
• Example 7: Consider the sets A={1,2,3}, B={3,1,2}, C={1,3}
and D={3}. Then
• A  B, D  A, C  A, also B  A. Therefore A = B.
• Proper subset: A is said to be a proper subset of B iff A is
subset of B but A is not equal to B, denoted as A⊂B.
• Example 8: Consider the sets A={1,2,3}, C={1,3}. Then
• 𝐶 ⊆ 𝐴 , 𝐶 ≠ 𝐴. Therefore C is a proper subset of A denoted
as 𝐶 ⊂ 𝐴 .
Properties of Set
• Universal set: The set which contains all the objects under
investigation in any application of set theory is called the
Universal set represented as E,U or X
A ={1,2,3,4,5,6,7,8,9}
B = {2,3,4} C = {1,3,9} D = {3,4,6,7}
A is the universal Set
Empty or Null set: The set which contains no element is called the
empty set represented as ∅ 𝑜𝑟 { } A = {} or ∅
• Example 9: The set 𝑥: 𝑥 ∈ 𝑁, 𝑥 2 = −1 has no elements.
• Power set: Consider a set 𝐴, then the set of all the subsets of A is
known as the power set of A, represented as P(A).
Examples

• Example 10: Consider the sets A={1,2,3}. Then


• The subsets of the set Aare ∅, {1},{2}, {3}, {1,2}, {1,3}, {2,3}, and {1,2,3}. Hence
• 𝑃 𝐴 = ∅, {1}, {2}, {3}, {1,2}, {1,3}, {2,3}, {1,2,3} .
• If the set 𝐴 is finite and contains n elements, the 𝑃 𝐴 contains 2𝑛 elements.

• A 3 elements =8
Index set or Index

• Sometimes the elements of a set are used to label the elements of another set
such sets are called the index set.
• Let 𝐴𝑖 be a non-empty set for each 𝑖 ∈ 𝐼. Here the sets 𝐴1 , 𝐴2 ,…,𝐴𝑛 are called
indexed set and the set 𝐼 is called the index set and 𝑖 ∈ 𝐼 of 𝐴𝑖 is called an index.
Also the family of sets 𝐴𝑖 𝑖∈𝐼 is called the indexed family of sets.
• 𝐼 = 1,2,3,4 , A = 𝐴1 , 𝐴2 , 𝐴3 , 𝐴4
Operations on sets
• Intersection of sets: The intersection of two sets A and B is
the set of all the elements which are common in both the
sets. Mathematically, 𝐴 ∩ 𝐵 = 𝑥: 𝑥 ∈ 𝐴 𝑎𝑛𝑑 𝑥 ∈ 𝐵 .
• Union of sets: The union of two sets A and B is the set of all
the elements which are either in A or in B. Mathematically,
𝐴 ∪ 𝐵 = 𝑥: 𝑥 ∈ 𝐴 𝑜𝑟 𝑥 ∈ 𝐵 .
• Example 11:Consider the sets A={1,2,3,4}, B={3,4,5,6}. Then
𝐴 ∩ 𝐵 = 3,4 , and 𝐴 ∪ 𝐵 = 1,2,3,4,5,6 .
Operations on sets
• Disjoint sets: Two sets A and B are said to be disjoint iff
they have no elements in common, i.e., 𝐴 ∩ 𝐵 = ∅.

Example 12: Consider the sets A={1,2}, B={3,4,5,6}. Then

𝐴 ∩ 𝐵 = ∅. Hence A and B are disjoint sets.


Operations on sets
• Relative complement of B in A(difference): The relative
complement of a set B in set A denoted as 𝐴 − 𝐵, is defined as
the set of all those elements of A which are not in B, i.e., 𝐴 −
𝐵 = 𝑥: 𝑥 ∈ 𝐴 𝑎𝑛𝑑 𝑥 ∉ 𝐵 .
A = { 1,2,3,4,5,6} B = {5,4,7,8,9}
A-B = {1,2,3,6} , B-A = {7,8,9}
Absolute complement:The absolute complement of a set A denoted as 𝐴′, is
defined as the set of all those elements of U which are not in the set A, i.e.,
𝐴′ = 𝑥: 𝑥 ∈ 𝑈 𝑎𝑛𝑑 𝑥 ∉ 𝐴 .
• Example 13: Consider the set of all non-negative integers A={0,1,2,3,…}, and
the universal set as U={…,-3,-2,-1,0,1,2,3,…} the set of all integers . Then
𝐴′={…,-3,-2,-1} the set of all negative integers.
Consider the set of all non-negative integers
A={0,1,2,3,…}, and the universal set as U={…,-
3,-2,-1,0,1,2,3,…} the set of all integers . Then
𝐴′={…,-3,-2,-1} the set of all negative integers.
U = {1,2,3,4,5,6,7,8,9,0,10}
A = { 1,2,3,4,5,6}
𝐴′ = { 7,8,9,0,10}
Operations on sets

• Symmetric difference:The symmetric difference of two sets A and B denoted as


A⨁𝐵 or 𝐴∆𝐵, is defined as the union of their relative complements, i.e.,
A⨁𝐵 = (𝐴 − 𝐵) ∪ (𝐵 − 𝐴)

• Example 14: Consider the sets A={1,2,3,5}, B={3,4,5,6}. Then 𝐴 − 𝐵 = 1,2 and
𝐵 − 𝐴 = 4,6 .
Hence A⨁𝐵 = 𝐴 − 𝐵 ∪ 𝐵 − 𝐴 = {1,2,4,6}.
Venn Diagram
A Venn diagram is a pictorial representation of sets in which sets
are represented by enclosed areas in the plane. The universal set
U is represented by the interior of a rectangle, and the other sets
are represented by disks lying within the rectangle.

A U U
B A B

U
B
B U
A A
Properties
Let A, B and C are subsets of the universal set U, then
1. 𝐴 ∪ 𝐵 = 𝐵 ∪ 𝐴 and 𝐴 ∩ 𝐵 = 𝐵 ∩ 𝐴
2. 𝐴 ∪ 𝐵 ∪ 𝐶 = 𝐴 ∪ 𝐵 ∪ 𝐶 &
(𝐴 ∩ 𝐵) ∩ 𝐶 = 𝐴 ∩ (𝐵 ∩ 𝐶(Associative)

𝐴 ∪ ∅ = 𝐴 and 𝐴 ∩ 𝑈 = 𝐴 (Identity laws)

4. A ∩ 𝐴′ = ∅ and 𝐴 ∪ 𝐴′ = 𝑈 (Complement
laws)
𝐴 ∪ 𝐴 = 𝐴 & 𝐴 ∩ 𝐴 = 𝐴 (law of tautology)
𝐴 ∪ 𝑈 = 𝑈 & 𝐴 ∩ ∅ = ∅(law of absorption)
U = { 1,2,3,4,5}
A = {1,2} 𝐴′ = 3,4,5

A u U = {1,2,3,4,5}
A ∩ 𝐴′ = {}
𝐴 ∪ 𝐴′ = {1,2,3,4,5}
𝐴 ∩ 𝑈 = {1,2} = A
Properties
𝐴 ∪ 𝐵 ∩ 𝐶 = 𝐴 ∪ 𝐵 ∩ (𝐴 ∪ 𝐶)&

𝐴 ∩ (𝐵 ∪ 𝐶) = (𝐴 ∩ 𝐵) ∪ (𝐴 ∩ 𝐶)(Distributive)

𝐼𝑓 𝐴 ∪ 𝐵 =U and 𝐴 ∩ 𝐵 = ∅, then B = A′

𝐴′ ′ = 𝐴 (law of involution)

(𝐴 ∪ 𝐵)′ = 𝐴′ ∩ 𝐵′&
(𝐴 ∩ 𝐵)′ = 𝐴′ ∪ 𝐵′ (De Morgan’s laws)
𝐴 ∪ 𝑈 = 𝑈&𝐴 ∩ ∅ = ∅(law of absorption)
𝐼𝑓 𝐴 ∪ 𝐵 =U and 𝐴 ∩ 𝐵 = ∅, then B = A′

U = {1,2,3,4,5,6}
A={1,2,3} B = {4,5,6}
𝐴′ = 4,5,6

(𝐴 ∪ 𝐵)′ = 𝐴′ ∩ 𝐵′& (𝐴 ∩ 𝐵)′ = 𝐴′ ∪ 𝐵′


Prove it
A = {1,2,3}
B= {3,4,5}
Au B = {1,2,3,4,5}

C = {1,2,3,4,2,3,5,6}
C = {1,2,3,4,5,6}
U = {1,2,3,4,5,6,7,8,9,10}
A={1,2,3}

B={3,4,5}
Prove that (𝐀 ∪ 𝐁)′ = 𝐀′ ∩ 𝐁′
Proof: To prove this we are to prove that (A ∪ B)′ ⊆ A′ ∩
B′&A′ ∩ B′ ⊆ (A ∪ B)′.

Let x ∈ A ∪ B ′ ⇒ x ∉ A ∪ B
⇒ x ∉ A and x ∉ B
⇒ x ∈ A′ and x ∈ B′
⇒ x ∈ A′ ∩ B′
⇒ (A ∪ B)′ ⊆ A′ ∩ B′

Now, let x ∈ A′ ∩ 𝐵′ ⇒ x ∈ A′ and x ∈ B′


⇒ x ∉ A and x ∉ B
⇒x∉A∪B
⇒x∈ A∪B ′
⇒ A′ ∩ B′ ⊆ (A ∪ B)′
⇒ A ∪ B ′ = A′ ∩ B′
Prove that (𝐀 ∩ 𝐁)′ = 𝐀′ ∪ 𝐁′
Proof: To prove this we are to prove that (A ∩ B)′ ⊆ A′ ∪
B′&A′ ∪ B′ ⊆ (A ∩ B)′.

Let x ∈ A ∩ B ′ ⇒ x ∉ A ∩ B
⇒ x ∉ Aor x ∉ B
⇒ x ∈ A′or x ∈ B′
⇒ x ∈ A′ ∪ B′
⇒ (A ∩ B)′ ⊆ A′ ∪ B′
Now, let x ∈ A′ ∪ 𝐵′ ⇒ x ∈ A′or x ∈ B′
⇒ x ∉ Aor x ∉ B
⇒x∉A∩B
⇒x∈ A∩B ′
⇒ A′ ∪ B′ ⊆ (A ∩ B)′
⇒ A ∩ B ′ = A′ ∪ B′
Cardinality of Set

• Finite set: A set is said to be finite set if it contains finite


number of elements
• Example 15: Consider the sets A={1,2,3,4,5,6,7,8} has 8
elements. Therefore A is a finite set.
• Cardinality of a set: Cardinality of a finite set A (in symbols
|A|) is the number of elements in A.
• Example 16: Cardinality of the set A={1,2,3,4,5,6,7,8} is 8.

A={4,5,6,7,1} |A|= 5
B=
Inclusion-Exclusion Principle
• Inclusion-Exclusion Principle: Given sets 𝐴1 , 𝐴2 , … 𝐴𝑛 , the
cardinality of the union is the sum of the individual
cardinalities, minus all the cardinalities of intersections of
two sets, plus the cardinalities of intersections of three
sets, minus the cardinalities of intersections of four sets,
etc. This alternating sum ends with plus or minus the
cardinality of the intersection of all 𝑛 sets.
• Mathematically for three sets A, B and C 𝐴 ∪ 𝐵 ∪ 𝐶 =
𝐴 + 𝐵 + 𝐶 − 𝐴∩𝐵 − 𝐴∩𝐶 − 𝐵∩𝐶 +
𝐴∩𝐵∩𝐶 .
Inclusion-Exclusion Principle
• Suppose we have two finite sets 𝐴 and 𝐵.Then what is the
cardinality of 𝐴∪𝐵?
• If we take the sum of the individual cardinalities, then we
count all the elements in the intersection twice. Therefore,
we have to subtract that cardinality to obtain the correct
answer as 𝐴 ∪ 𝐵 = 𝐴 + 𝐵 − 𝐴 ∩ 𝐵 .
• Example 18: Consider the sets A={2,4,6,7,8} and B={2,4,9}.
Then 𝐴 ∪ 𝐵 = 𝐴 + 𝐵 − 𝐴 ∩ 𝐵 =5+3-2=6. As 𝐴 ∪ 𝐵 =
2,4,6,7,8,9 .
• The generalization of this formula to an arbitrary number
of sets is called the inclusion-exclusion principle.
Principle of duality
• Let E be an equation of set algebra, then the dual of E
represented as E* is the equation obtained by replacing
each occurrence of ∪,∩, 𝑈, ∅ in E by ∩,∪, ∅, 𝑈 respectively.
• Example 19: Dual of (U ∩ 𝐴) ∪ (𝐵 ∩ 𝐴) = A is
• (∅ ∪ 𝐴) ∩ (𝐵 ∪ 𝐴) = 𝐴.
• Theorem (The Principle of Duality): Let E denote a theorem
or identity dealing with the equality of two set expressions.
Then E* is also a theorem/identity.
• Example 20: (𝐴 ∪ 𝐵)′ = 𝐴′ ∩ 𝐵′& (𝐴 ∩ 𝐵)′ = 𝐴′ ∪ 𝐵′ (De
Morgan’s laws)
Minset & Maxset
• Minset:Let {𝐵1 , 𝐵2 , … 𝐵𝑛 } be a set of subsets of a set A. Sets
of the form 𝐷1 ∩ 𝐷2 ∩ ⋯ ∩ 𝐷𝑛 , where each 𝐷𝑖 , may be
either 𝐵𝑖 or 𝐵𝑖 ′is called a minset generated by 𝐵1 , 𝐵2 , … 𝐵𝑛 .
• Maxset: Dualof minset is called maxset.
• Use the principle of duality and the definition of minset to
write the definition of maxset.
• Example 20:Let 𝑈 = −2, −1, 0, 1, 2 , 𝐵1 = 0, 1, 2 , and
𝐵2 = 0,2 . Then 𝐵1 ∩ 𝐵2 = 0,2 , 𝐵1 ′ ∩ 𝐵2 = ∅, 𝐵1 ∩
𝐵2 ′ = 1 and 𝐵1 ′ ∩ 𝐵2 ′ = −2, −1 .
Ordered Pairs & n-tuples
• Ordered pair:An ordered pair of elements is written in the form (a, b) (or <a, b>)
which is distinct from (b, a) unless a = b.
• Equality of ordered pairs:(a,b) = (c,d) iff a = c & b = d
• {1,2} = {2,1} = {1,1,2}
but (1,2)  (2,1)  (1,1,2)
• Ordered triple:ordered triple (a,b,c)
• n-tuple: 𝑥1 , 𝑥2 , 𝑥3 , … , 𝑥𝑛
Cartesian Products-
• Let A & B be any two sets. The set of all ordered pairs such that
the first member of the ordered pair is an element of A & second
member is an element of B is called the Cartesian product of A
and B denoted as 𝐴 × 𝐵 .
• i.e., 𝐴 × 𝐵 = {(𝑎, 𝑏): (𝑎𝐴) 𝑎𝑛𝑑 ( 𝑏𝐵)}.
• 𝐴  (𝐵  𝐶) = {(𝑎, (𝑏, 𝑐)): (𝑎 𝐴) 𝑎𝑛𝑑 (𝑏, 𝑐)  𝐵  𝐶}.
• 𝐴  𝐵  𝐵  𝐴.
• Example 21: Consider the sets 𝐴 = {𝑎, 𝑏} &𝐵 = {1,2,3} find
𝐴 × 𝐵, 𝐵 × 𝐴, and 𝐴 × 𝐴 .
• 𝐴 × 𝐵 = {(𝑎, 1), (𝑎, 2), (𝑎, 3), (𝑏, 1), (𝑏, 2), (𝑏, 3)}
• 𝐵 × 𝐴 = {(1, 𝑎), (1, 𝑏), (2, 𝑎), (2, 𝑏), (3, 𝑎), (3, 𝑏)}
• 𝐴 × 𝐴 = {(𝑎, 𝑎), (𝑎, 𝑏), (𝑏, 𝑎), (𝑏, 𝑏)}
Properties of Cartesian Product

For the four sets A,B,C and D


1.( A  B )  (C  D) = ( A  C)  ( B  D)
2.( A − B )  C = ( A  C) − ( B  C)
3.( A  B )  C = ( A  C)  ( B  C)
4. A  ( B  C ) = ( A  B )  ( A  C )
Cartesian Product & Ordered Pairs
• An ordered pair of elements is written in the form (a, b) which is
distinct from (b, a) unless a = b
Definition(Cartesian Product) :
For sets A, B  U , the Cartesian product, or
cross product, of A and B is denoted by A  B
and A  B = {( a, b) | a  A, b  B}.
Example:
Let A = {x, y} and B = {a, b, c} then
A  B = {(x, a), (x, b), (x, c), (y, a), (y, b), (y, c)}
& B  A = {(a, x), (a, y), (b, x), (b, y), (c, x), (c, y)}
A  A = {(x, x), (x, y), (y, x), (y, y)}
Certainly A  B  B  A ( in general)
A = {x,y} A = {x,y}

A x A = { (x,x),(x,y), (y,x),(y,y)}
Example
X = { 1, 2} |x| = 2
Y = { a, b} |y| = 2

X x Y = {(1,a),(1,b),(2,a), (2,b)} |X x Y| = 4
Y x X = { (a, 1), (a,2), (b,1), (b,2)}
Note:
• XxYYxX

• |

• | X x Y | = |X| .|Y|

Determine:
1 1
X xX = 1,1 , 1,2 , 2,1 , (2,2) , M =
1 1
YxY =?
𝐴 = 1,2,3,4,5,6

𝑅= 𝑎, 𝑏 ∈ 𝑅: 𝑎 𝑑𝑖𝑣𝑖𝑑𝑒𝑠 𝑏

1,1 , 1,2 , 1,3 , 1,4 , 1,5 , (1,6)


𝑅= 2,2 , 2,4 , 2,6 ,
3,3 , 3,6 , 4,4 , 5,5 , (6,6)
𝐴 = 1,2,3,4,5,6

𝑅= 𝑎, 𝑏 ∈ 𝐴: 𝑎 𝑑𝑖𝑣𝑖𝑑𝑒𝑠 𝑏

R={
(1,1),(1,2),(1,3),(1,4),(1,5),(1,6),(2,2),(2,4),(2,6),(3,3),(3,6),(4,4),(5,5),(6,
6)}
Relation : Definition
Definition(Relation): For sets A,B  U , any subset of A  B is called
a relation from A to B. Any subset of A  A is called a binary
relation on A.

If R is a relation from a set A to another set B then R  A B


Remarks:
• In general, for finite sets A,B with |A| = m and |B| = n, there
are 2mn relations from A to B, including the empty relation
as well as the relation A B itself.
• The domain of a relation R is the set of all first elements of the
ordered pairs which belong to R, and the range of R is the set of
second elements.
Example:
• Let R = { (1,a),(2,b),(1,c)} then dom R = { 1,2 } and
range R = {a,b,c}
• Let A=Z+, a binary relation, R, on A, {(x,y) |x<y}
(1,2), (7,11) is in R, but (2,2), (3,2) is not in R
or 1R2, 7R11 (infix notation)
• Let X = {2, 3, 4} and Y = { 3, 4, 5,6, 7}
If we define a relation R from X to Y by
(x,y) R if x divides y ( with zero remainder)
We obtain:
R = { (2,4), (2,6), (3,3), (3,6), (4,4)}
Domain of R is {2, 3, 4};Range of R is {3, 4 6}
Let X = {2, 3, 4} and Y = { 3, 4, 5,6, 7}
If we define a relation R from X to Y

(x,y) R if x divides y ( with zero remainder)

{(2,4),(2,6),(3,3),(3,6),(4,4)}
Another Example:
• Let R be the relation on X = {1,2,3,4} defined by (x,y)  R

if x y,
x, y X.

• R = { (1,1), (1,2), (1,3), (1,4), (2,2), (2,3), (2,4), (3,3), (3,4),(4,4)}

• The domain and Range of R are both equal to X


Representing Relations using a Digraph
• Digraph – directed graph
• Components –
• Vertices or Nodes, drawn as dots
• Edges - Directed edges i.e. lines between vertices with arrows showing a
direction between the vertices)
• Vertices represent elements of X
• Directed Edge represent the members of the relation R
Example
Let R = {(1,1), (1,2), (1,3), (1,4), (2,2), (2,3), (2,4),
(3,3), (3,4),} be a relation on A={1,2,3,4}

1 2
A Loop

3
Exercise: 4
• The Relation R on X = {a, b, c, d} is
R = {(a,a), (b,c), (c,b), (d,d)}
What would the digraph to represent this relation look
like?
Let R = {(1,1), (1,2), (1,3), (1,4), (2,2), (2,3), (2,4),
(3,3), (3,4),} be a relation on A={1,2,3,4}
Let R = {(1,1), (1,2), (1,3), (1,4), (2,2), (2,3), (2,4),
(3,3), (3,4),} be a relation on A={1,2,3,4}
Representing Relations using a Matrix
Let A = { a1 , a 2 ,..., a m } and B={ b1 , b2 ,..., bn }
Let R be relation from A to B. Then R is represented by
a matrix M R = [ mij ]mn where

1 if ( ai , b j )  R
mij = 

0 if ( ai , b j )  R
The matrix M R is called the matrix of R.
Example : Let A = {1,2,3,4} and B = { x, y , z}
Let R = {(1, y ), ( 2, z ), (3, x ), (3, y ), ( 4, x ), ( 4, z )} be a relation from A to B.
Then M R is given by
0 1 0
 
x y z 0 0 1
1
MR = .
0 1 0 1 1 0
2 0 0 1  
1 1
3 1 1 0  0 
4 1 0 1
Types of Relations:
• Reflexive and Irreflexive

• Symmetric

• Antisymmetric

• Transitive
Reflexive and Irreflexive
• A relation R on a set A is called reflexive
if (a, a) R for every a  A
e.g.
R = { (1,1), (1,2), (1,3), (1,4), (2,2), (2,3), (2,4), (3,3), (3,4),(4,4)}
is Reflexive. [ A = {1,2,3,4} ] while
R*={(1,1),(1,2),(1,3),(1,4),(2,3),(2,4),(3,3),(3,4)}
is not a reflexive relation on A.
• A relation R on a set A is called irreflexive if
(a,a) does not belong to R for any a A.
R’={(1,2),(1,3),(1,4),(2,3),(2,4),(3,4)} is irreflexive relation on A.
Symmetric and Anti-symmetric
• A relation R on a set A, is called symmetric if whenever (a,b) R,
then (b,a)  R
Example:
R2 = {(a,a), (b,c), (c,b), (d,d)} is symmetric.
Is R2 also Reflexive?
• A relation R on a set A is called anitsymmetric if
whenever (a, b) and (b, a)  R then a=b.
Antisymmetric (continued)
• Is R2 = {(a, a), (b, c), (c, b), (d, d)} is antisymmetric?
No. Both (b,c) and (c,b) are in R.
• If a relation R on X has no members of the form (x, y) with xy, then R
is antisymmetric. WHY?
• Let R = {(a,a), (b,b), (c,c)}
then R is antisymmetric
Is R also Symmetric? Yes.

NB. “Antisymmetric” is not the same as “NOT


symmetric”
Transitivity
• A relation R on set A is called transitive if whenever
(a, b)  R and (b, c)  R, then
(a, c)  R
Example:
Let R = { (1,1), (1,2), (1,3), (1,4), (2,2), (2,3), (2,4), (3,3),
(3,4),(4,4)} is transitive but
R = {(a, a), (b, c), (c, b), (d, d)} is not transitive. WHY?
Inverse of a relation
• Let R be a relation from A to B. The inverse of R, denoted R-1, is the
relation from B to A defined by
R-1 ={(y, x )|(x, y)  R}
• X = {2,3,4} and Y ={3,4,5,6,7}, a relation R is defined by
(x, y)  R if x divides y (with zero remainder)
R = {(2,4), (2,6), (3,3),(3,6), (4,4)}
Then R-1 = {(4,2), (6,2), (3,3), (6,3), (4,4)}
The composition of two relations
Let R be a relation from A to B and S be a relation
from B to C. The composition of R and S, denoted by
So R , is the relation from A to C defined by
So R = {(a, c) | (a, b)  R
and (b, c)  S for some b  B}
Example: Let R is the relation from {1,2,3} to {
1,2,3,4} with R ={(1,1),(1,4),(2,3),(3,1),(3,4)}
and S is the relation from {1,2,3,4} to {0,1,2}
with S={(1,0),(2,0),(3,1),(3,2),(4,1)}.Find So R.

Solution: S o R = {(1,0),(1,1),(2,1),(2,2),(3,0),(3,1)}.
EXAMPLE

Find R  R, R  S  R
Equivalence relations
• A relation on a set A is called an equivalence relation if it is
reflexive, symmetric, and transitive
Example 1:
• Consider relation R = { (a,b) | len(a) = len(b) }
on set of strings of English letters
• Where len(a) means the length of string a
• It is reflexive: len(a) = len(a)
• It is symmetric: if len(a) = len(b), then len(b) = len(a)
• It is transitive: if len(a) = len(b) and len(b) = len(c), then len(a) = len(c)
• Thus, R is a equivalence relation
Example 2: Let R be the relation on the set of real numbers such
that a R b iff a-b is an integer. Is R an equivalence relation?
(Ex!)
Examples:
• Which of these relations on {0, 1, 2, 3} are equivalence relations?
Determine the properties of an equivalence relation that the others lack
a) { (0,0), (1,1), (2,2), (3,3) }
Has all the properties, thus, is an equivalence relation
b) { (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)
c) { (0,0), (1,1), (1,2), (2,1), (2,2), (3,3) }
Has all the properties, thus, is an equivalence relation
d) { (0,0), (1,1), (1,3), (2,2), (2,3), (3,1), (3,2) (3,3) }
Not transitive: (1,3) and (3,2) are in the relation, but not (1,2)
e) { (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)
Partial Order relation: Introduction
• An equivalence relation is a relation that is reflexive, symmetric, and transitive

• A partial ordering (or partial order) is a relation that is reflexive, antisymmetric,


and transitive
• Recall that antisymmetric means that if (a,b) and (b,a)  R, then b = a
• Thus, (a,a) is allowed to be in R
• But since it’s reflexive, all possible (a,a) must be in R

• A set S with a partial ordering R is called a partially ordered set, or poset


• Denoted by (S,R)
Partial ordering examples
• Show that ≥ is a partial order on the set of integers
– It is reflexive: a ≥ a for all a  Z
– It is antisymmetric: if a ≥ b and b ≥ a then
b=a
– It is transitive: if a ≥ b and b ≥ c, then a ≥ c
• Note that ≥ is the partial ordering on the set of integers
• (Z, ≥) is the partially ordered set, or poset.
• Show that the inclusion relation is a partial
ordering relation on the power set of a set S.
(Exercise!) i.e. (P(S), ) is a poset. 


Comparability
• The elements a and b of a poset (S, ) are called
comparable if either a b or b a.
– Meaning if (a,b)  R or (b,a)  R
– It can’t be both because is antisymmetric
• Unless a = b, of course
– If neither a b nor b a, then a and b are incomparable
• Meaning they are not related to each other
• If all elements in S are comparable, the relation is a total
ordering
Comparability examples
• Let be the less than or equals operator ≤
• In the poset (Z+,≤), are the integers 3 and 9
comparable?
– Yes, as 3 ≤ 9
• Are 7 and 5 comparable?
– Yes, as 5 ≤ 7
• As all pairs of elements in Z+ are comparable, the
poset (Z+,≤) is a total order
– Also called as totally ordered poset, linearly ordered set,
chain, etc.
Equalities between Relations
.
Definition: Function
• Definition: A function f from a set A to a set B is an assignment of exactly one
element of B to each element of A.
• We write f(a)=b if b is the unique element of B assigned by the function f to the
element a  A.
• If f is a function from A to B, we write
f: A → B
This can be read as ‘f maps A to B’
• Note the subtlety
• Each and every element of A has a single mapping
• Each element of B may be mapped to by several elements in A or not at all
Terminology
• Let f: A → B and f(a)=b. Then we use the following terminology:
• A is the domain of f, denoted dom(f)
• B is the co-domain of f
• b is the image of a
• a is the preimage (antecedent) of b
• The range of f is the set of all images of elements of A, denoted rng(f)
Function: Visualization
Range
Preimage Image, f(a)=b
f
a b

A B
Domain Co-Domain
A function, f: A → B
More Definitions (1)
• Definition: Let f1 and f2 be two functions from a set A to R. Then f1+f2
and f1f2 are also function from A to R defined by:
• (f1+f2)(x) = f1(x) + f2(x)
• f1f2(x)= f1(x)f2(x)
• Example: Let f1(x)=x4+2x2+1 and f2(x)=2-x2
• (f1+f2)(x) = x4+2x2+1+2-x2 = x4+x2+3
• f1f2(x) = (x4+2x2+1)(2-x2)= -x6+3x2+2
Image of a set: Example
• Let:
• A = {a1,a2,a3,a4,a5}
• B = {b1,b2,b3,b4,b5}
• f={(a1,b2), (a2,b3), (a3,b3), (a4,b1), (a5,b4)}
• S={a1,a3}
• Draw a diagram for f
• What is the:
• Domain, co-domain, range of f?
• Image of S, f(S)?
More Definitions (3)
• Definition: A function f whose domain and co-domain are subsets of
the set of real numbers (R) is called
• strictly increasing if f(x)<f(y) whenever x<y and x and y are in the domain of f.
• strictly decreasing if f(x)>f(y) whenever x>y and x and y are in the domain of f.
• A function that is increasing or decreasing is said to be monotonic
Outline
• Definitions & terminology
• Properties
– One-to-one (injective)
– Onto (surjective)
– One-to-one correspondence (bijective)
– Exercices (5)
• Inverse functions (examples)
• Operators
• Important functions
Definition: Injection
• Definition: A function f is said to be one-to-one or injective (or an
injection) if
 x and y in in the domain of f, f(x)=f(y)  x=y
• Intuitively, an injection simply means that each element in the range
has at most one preimage (antecedent)
• It is useful to think of the contrapositive of this definition
x  y  f(x)  f(y)
Definition: Surjection
• Definition: A function f: A→B is called onto or surjective (or an
surjection) if
bB,  aA with f(a)=b
• Intuitively, a surjection means that every element in the codomain is
mapped into (i.e., it is an image, has an antecedent)
• Thus, the range is the same as the codomain
Definition: Bijection
• Definition: A function f is a one-to-one correspondence (or a
bijection), if is both one-to-one (injective) and onto (surjective)
• One-to-one correspondences are important because they endow a
function with an inverse.
• They also allow us to have a concept cardinality for infinite sets
• Let’s look at a few examples to develop a feel for these definitions…
Functions: Example 1

A B
a1 b1
a2 b2
a3 b3
a4 b4

• Is this a function? Why?


• No, because each of a1, a2 has two images
Functions: Example 2

A B
a1 b1
a2 b2
a3 b3
a4 b4

• Is this a function
• One-to-one (injective)? Why?
No, b1 has 2 preimages
• Onto (surjective)? Why?
No, b4 has no preimage
Functions: Example 3

A B
a1 b1
a2 b2
a3 b3
b4

• Is this a function
• One-to-one (injective)? Why?
Yes, no bi has 2 preimages
• Onto (surjective)? Why?
No, b4 has no preimage
Functions: Example 4

A B
a1 b1
a2 b2
a3 b3
a4 b4

• Is this a function
• One-to-one (injective)?
Thus, it is a bijection or a
• Onto (surjective)?
one-to-one correspondence
Exercice 1
• Let f:Z→Z be defined by
f(x)=2x-3
• What is the domain, codomain, range of f?
• Is f one-to-one (injective)?
• Is f onto (surjective)?
• Clearly, dom(f)=Z. To see what the range is, note that:
b rng(f)  b=2a-3, with aZ
 b=2(a-2)+1
Exercise 1 (cont’d)
• Thus, the range is the set of all odd integers
• Since the range and the codomain are different (i.e., rng(f)  Z), we
can conclude that f is not onto (surjective)
• However, f is one-to-one injective. Using simple algebra, we have:
f(x1) = f(x2)  2x1-3 = 2x2-3  x1= x2 QED
Exercise 2
• Let f be as before
f(x)=2x-3
but now we define f:N →N
• What is the domain and range of f?
• Is f onto (surjective)?
• Is f one-to-one (injective)?
• By changing the domain and codomain of f, f is not
even a function anymore. Indeed, f(1)=21-3=-1N
Exercice 3
• Let f:Z→Z be defined by
f(x) = x2 - 5x + 5
• Is this function
• One-to-one?
• Onto?
Exercice 3: Answer
• It is not one-to-one (injective)
f(x1)=f(x2)  x12-5x1+5=x22 - 5x2+5  x12 - 5x1 = x22 - 5x2
 x12 - x22 = 5x1 - 5x2  (x1 - x2)(x1 + x2) = 5(x1 - x2)
 (x1 + x2) = 5
Many x1,x2 Z satisfy this equality. There are thus an infinite number of solutions. In
particular, f(2)=f(3)=-1
• It is also not onto (surjective).
The function is a parabola with a global minimum at (5/2,-5/4). Therefore, the function fails to map to any
integer less than -1
• What would happen if we changed the domain/codomain?
Exercise 4
• Let f:Z→Z be defined by
f(x) = 3x3 – x
• Is this function
• One-to-one (injective)?
• Onto (surjective)?
f is one-to-one
• To check if f is one-to-one, again we suppose that for x1,x2 Z we
have f(x1)=f(x2)
f(x1)=f(x2)  3x13-x1=3x23-x2
 3x13 - 3x23 = x1 - x2
 3 (x1 - x2)(x12 +x1x2+x22)= (x1 - x2)
 (x12 +x1x2+x22)= 1/3
which is impossible because x1,x2 Z
thus, f is one-to-one
f is not onto
• Consider the counter example f(a)=1
• If this were true, we would have
3a3 – a=1  a(3a2 – 1)=1 where a and (3a2 – 1) Z
• The only time we can have the product of two integers equal to 1 is
when they are both equal to 1 or -1
• Neither 1 nor -1 satisfy the above equality
• Thus, we have identified 1Z that does not have an antecedent and f is not
onto (surjective)
Outline
• Definitions & terminology
– function, domain, co-domain, image, preimage (antecedent), range,
image of a set, strictly increasing, strictly decreasing, monotonic
• Properties
– One-to-one (injective), onto (surjective), one-to-one correspondence
(bijective)
– Exercices (5)
• Inverse functions (examples)
• Operators
– Composition, Equality
• Important functions
– identity, absolute value, floor, ceiling, factorial
Inverse Functions (1)
• Definition: Let f: A→B be a bijection. The inverse function of f is the
function that assigns to an element bB the unique element aA
such that f(a)=b
• The inverse function is denote f-1.
• When f is a bijection, its inverse exists and
f(a)=b  f-1(b)=a
Inverse Functions (2)
• Note that by definition, a function can have an inverse if and only if it
is a bijection. Thus, we say that a bijection is invertible
• Why must a function be bijective to have an inverse?
• Consider the case where f is not one-to-one (not injective). This means that
some element bB has more than one antecedent in A, say a1 and a2. How
can we define an inverse? Does f-1(b)=a1 or a2?
• Consider the case where f is not onto (not surjective). This means that there
is some element bB that does not have any preimage aA. What is then f-
1(b)?
Inverse Functions: Representation

f(a)
a b
f -1(b)
A B
Domain Co-Domain
A function and its inverse
Inverse Functions: Example 1
• Let f:R→R be defined by
f(x) = 2x – 3
• What is f-1?
1. We must verify that f is invertible, that is, is a bijection. We prove that is
one-to-one (injective) and onto (surjective). It is.
2. To find the inverse, we use the substitution
• Let f-1(y)=x
• And y=2x-3, which we solve for x. Clearly, x= (y+3)/2
• So, f-1(y)= (y+3)/2
Inverse Functions: Example 2
• Let f(x)=2x
• What should the domain/codomain be for this function to be a bijection?
• What is the inverse?
• The function should be f:R→R+
• Let f-1(y)=x and y=2x, solving for x we get x=log2(y). Thus, f-1(y)=log2(y)
• What happens when we include 0 in the codomain?
• What happens when restrict either sets to Z?
• If f x = 3x − 5, then f −1 x is
Function Composition (1)
• The value of functions can be used as the input to other functions
• Definition: Let g:A→B and f:B →C. The composition of the functions
f and g is
(f  g) (x)=f(g(x))
• fg is read as ‘f circle g’, or ‘f composed with g’, ‘f following g’, or just ‘f
of g
Function Composition (2)
• Because (f  g)(x)=f(g(x)), the composition f  g cannot be defined
unless the range of g is a subset of the domain of f
f  g is defined  rng(g)  dom(f)
• The order in which you apply a function matters: you go from the
inner most to the outer most
• It follows that f  g is in general not the same as g  f
Composition: Graphical Representation
(f  g)(a)

g(a) f(g(a))
a g(a) f(g(a))

A B C

The composition of two functions


Composition: Example 1
• Let f, g be two functions on R→R defined by
f(x) = 2x – 3
g(x) = x2 + 1
• What are f  g and g  f?
• We note that
• f is bijective, thus dom(f)=rng(f)= codomain(f)= R
• For g, dom(g)= R but rng(g)={xR | x1}  R+
• Since rng(g)={xR | x1} R+  dom(f) =R, f  g is defined
• Since rng(f)= R  dom(g) =R , g  f is defined
Composition: Example 1 (cont’)
• Given f(x) = 2x – 3 and g(x) = x2 + 1
• (f  g)(x) = f(g(x)) = f(x2+1) = 2(x2+1)-3
= 2x2 - 1
• (g  f)(x) = g(f(x)) = g(2x-3) = (2x-3)2 +1
= 4x2 - 12x + 10
Associativity
• The composition of function is not commutative (f  g  g  f), it is
associative
• Lemma: The composition of functions is an associative operation,
that is
(f  g)  h = f  (g  h)
Permutations
Example 1
Example 2
Example 3
Example 1
Example 2
Example 3
Example 4
Circular Permutation
Example 1
Example 2
Permutation of n with alike objects
Example 1
Example
Practice Questions

Answer: b)362880

Answer: d)180
Answer: c) 720
Review

A combination is a grouping of outcomes in which


the order does not matter.

A permutation is an arrangement of outcomes in


which the order does matter.
Combination
Relation between Permutation and Combination
Combination or Permutation ??
Combination or Permutation ??
The order of outcomes is not important, so this
situation involves combinations.

5C =10
2
The order of outcomes is important, so this situation
involves permutations.

26 x 6 x 10 x 10 =15600
The order of outcomes is important, so this situation
involves permutations.

ABC BAC CAB


ACB BCA CBA

3x2x1=6
The order of outcomes is important, so this situation
involves permutations.

3x2x1=6
The order of outcomes is not important, so this
situation involves combinations.

4C =6
2
The order of outcomes is important, so this situation
involves permutations.

8 x 7 x 6 = 336
The order of outcomes is not important, so this
situation involves combinations.

15𝐶4 = 1365
The order of outcomes is not important, so this
situation involves combinations.

13𝐶4 = 715
The order of outcomes is not important, so this
situation involves combinations.

12C = 792
5
The order of outcomes is not important, so this
situation involves combinations.

11C = 330
4
The order of outcomes is important, so this situation
involves permutations.

12𝑃4 = 11,880
Pigeon Hole Principle
Example
Pigeonhole Principle

• If k+1 objects are assigned to k places, then at least 1 place


must be assigned ≥2 objects.

• Proof: (by contradiction)


• Suppose none of the k places contains more than one object. Then the total
number of objects would be at most k. This is a contradiction, since there
are k + 1 objects.
In terms of the assignment function:
If f: A→B and |A|≥|B|+1, then some element of B
has ≥2 pre-images under f. I.e., f is not one-to-one.
Example

• How many students must be in class to guarantee that at least two


students receive the same score on the final exam, if the exam is graded
on a scale from 0 to 100 points?

102

So, if a million students take a national test with say 100 questions,
many must have the same score (in expectation 10,000). So, would need
at least a million questions to get a chance of a unique score for
everyone.
Generalized Pigeonhole Principle

• If N≥k+1 objects are assigned to k places, then at least one place


must be assigned at least N/k objects.
• E.g., there are N = 280 people in a party. There are k = 52 weeks in the year.
• Therefore, there must be at least 1 week during which at least 280/52 =
5.38 = 6 students in the party have a birthday.

36
G.P.P. Example

• Given: There are 280 people in the party. Without knowing anybody’s
birthday, what is the largest value of n for which we can prove that at
least n people must have been born in the same month?

• Answer:
280/12 = 23.3 = 24

38
Thank
you
Discrete Structure/AM103 Mr Pankaj 1
Discrete Structure/AM103 Mr Pankaj 2
Definition of Recurrence Relation

Let a1, a2, a3… an be a sequence, then relation that relates an to


one or more previous terms of sequence is called Recurrence
Relation. i.e., A recurrence relation is an equation that recursively
defines a sequence where the next term is a function of the
previous terms
To define sequence corresponding to recurrence relation, it is
important to know first few terms, which are called as initial
conditions of recurrence relation.
Example:
1) an = an-1 +5 with initial condition a0 = 10. It generates the
sequence a0 = 10, a1 = 15, a2 = 20 …
i.e., <10, 15, 20, 25, …>
2) Fibonacci sequence: fn = fn-1 + fn-2 with initial conditions f0 = 1, f1
=1. It generates f0 = 1, f1 =1, f2 =2, f3 = 3, f4 = 5, f5 = 8 …
i.e., <1, 1, 2, 3, 5, 8, 13, 21, … >
Discrete Structure/AM103 Mr Pankaj 3
1) an = an-1 +5 with initial condition a0 = 10.
It generates the sequence a0 = 10, a1 = 15,
a2 = 20 …
i.e., <10, 15, 20, 25, …>

Discrete Structure/AM103 Mr Pankaj 4


1) an = an-1 +5 with initial condition a0 = 10.
It generates the sequence a0 = 10, a1 = 15,
a2 = 20 …
i.e., <10, 15, 20, 25, …>

Discrete Structure/AM103 Mr Pankaj 5


2) Fibonacci sequence: fn = fn-1 + fn-2 with
initial conditions f0 = 1, f1 =1. It generates f0
= 1, f1 =1, f2 =2, f3 = 3, f4 = 5, f5 = 8 …
i.e., <1, 1, 2, 3, 5, 8, 13, 21, … >

Discrete Structure/AM103 Mr Pankaj 6


2) Fibonacci sequence: fn = fn-1 + fn-2 with
initial conditions f0 = 1, f1 =1. It generates f0
= 1, f1 =1, f2 =2, f3 = 3, f4 = 5, f5 = 8 …
i.e., <1, 1, 2, 3, 5, 8, 13, 21, … >

Discrete Structure/AM103 Mr Pankaj 7


Recurrence Relation

If we change initial conditions, then the corresponding


sequence also changes.
Example:
an = an-1 +2 with a0 =1
Corresponding sequence is,
<1, 3, 5, 7, 9, 11 ...> sequence of odd numbers.
Now if we take the same recurrence relation:
Ar = an-1 +2 with a0 = 2
Corresponding sequence is,
<2, 4, 6, 8 … >, sequence of even numbers.

Discrete Structure/AM103 Mr Pankaj 8


Linear Recurrence Relation with
Constant Coefficients

• Let a1, a2, a3 … an … be infinite sequence then


recurrence relation of the form c0 an + c1 an-1 + c2 an-2 +
c3 an-3 + … + ck an-k = f(n). Where ci’s are constants, such
function is called linear recurrence relation with constant
coefficient.
• Construction of Recurrence Relation
• Example 1: Sharma invests Rs.10,0000/- to purchase a
land. Land cost increases by 20% per year. From
recurrence relation, what will be the cost of land after ‘n’
years?
• Solution: Initially land cost = Rs.100000/- i.e., a0 =
100000, suppose an is the land cost after n years.

Discrete Structure/AM103 Mr Pankaj 9


Discrete Structure/AM103 Mr Pankaj 10
Degree of Recurrence Relation
• Number of previous terms required to find next term
of sequence in recurrence relation is called degree
of recurrence relation.
• i.e., Let, c0 an + c1 an-1 + c2 an-2 + c3 an-3 + … + ck
an-k = f(n) is recurrence relation. To find the value of
an, it is important to know the previous terms,
namely, an-1, an-2, an-3 … an-k . Hence, k is a degree
of above recurrence relation.
• Example: Find degree of recurrence relation
an=an-1+an-2,
• Solution: Here, we require two values of an-1, an-2,
to find value of an. Hence, degree of recurrence
relation is 2.
Discrete Structure/AM103 Mr Pankaj 11
Degree of Recurrence Relation

•an + an-1 = 3n2n, first degree

•an + 5 an-1-2an-2 = 3n, second degree

• c0an +c1an-1+c2an-2+…+cr an-r =f(n), rth-degree

•This is a linear recurrence relation with constant coeff. of


rth-degree.

Discrete Structure/AM103 Mr Pankaj 12


•an + 5 an-1-2an-2 = 3n, second degree

•an + an-1 = 3n2n, first degree

Discrete Structure/AM103 Mr Pankaj 13


• c0an +c1an-1+c2an-2+…+cr an-r =f(n), rth-degree

•This is a linear recurrence relation with constant coeff. of


rth-degree.

Discrete Structure/AM103 Mr Pankaj 14


•an + an-1 = 3n2n, first degree

Discrete Structure/AM103 Mr Pankaj 15


•an + 5 an-1-2an-2 = 3n, second degree

Discrete Structure/AM103 Mr Pankaj 16


Characteristic Equation of Recurrence
Relation

• If c0 an + c1 an-1 + c2 an-2 + c3 an-3 + … + ck an-k = f(n) Be


recurrence relation with constant coefficient of degree k
then equation of the type c0 αk + c1 αk-1 + c2 αk-2 + c3 αk-3
+ ... + ck α(k-k) = 0 where, α is constant is called
characteristic equation of recurrence relation.
• Characteristic Roots of Recurrence Relation
• Roots of characteristic equation of recurrence relation
are called as Characteristic roots of recurrence relation.
i.e., values of variable α which satisfy the characteristic
equation are called as characteristic roots. Say α1, α2, α3,
..., αk are k characteristic roots.
• Degree of recurrence relation = number of characteristic
roots
• All characteristic roots may not be distinct.
Discrete Structure/AM103 Mr Pankaj 17
Example

• Example: Find characteristic equation and characteristic roots


of recurrence relation an-7an-1 +12an-2 = 0.

Discrete Structure/AM103 Mr Pankaj 18


Homogeneous Recurrence Relation

• Recurrence relation of the type


c0 an + c1 an-1 + c2 an-2 + c3 an-3 + … + ck an-k = f(r)
is homogenous recurrence relation, if f(r)=0.
• i.e., c0 an + c1 an-1 + c2 an-2 + c3 an-3 + … + ck an-k = 0, is a
homogenous recurrence relation.

Discrete Structure/AM103 Mr Pankaj 19


Non-homogeneous Recurrence Relation

• Recurrence relation of the type


c0 an + c1 an-1 + c2 an-2 + c3 an-3 + … + ck an-k = f(n)
is non-homogenous recurrence relation, if f(n)≠0.
• i.e., f(n) may be constant or any function of variable ‘n’.

Discrete Structure/AM103 Mr Pankaj 20


Solution of Recurrence Relation

• A sequence is called a solution of a recurrence relation if its


terms satisfy the recurrence relation
• i.e., a numeric function described by recurrence relation
together with an appropriate set of initial conditions is called a
solution of recurrence relation.
• Homogenous Solution (arh):
• A solution that satisfies the recurrence relation when right
hand side of recurrence relation is zero, is called
homogeneous solution. And is denoted as arh .
• Particular Solution (arp)
• A solution which satisfies the recurrence relation with non
zero f(r) on right hand side is called particular solution. It is
denoted by arp.

Discrete Structure/AM103 Mr Pankaj 21


Solution of Recurrence Relation

• Consider the recurrence relation


an = 2an−1 − an−2 (n≥2).
• Which of the following are solutions?
an = 3n Yes -> 2 [3(n-1)] – 3(n-2)
= 3n => an
an = 2n No -> a0 = 1, a1 = 2, a2 = 4;
a2 = 2a1 – a0 = 2.2 – 1 = 3 ≠ a2
an = 5 Yes -> an = 2.5 – 5 = 5 = an

Discrete Structure/AM103 Mr Pankaj 22


Solving with const. Coefficients

• Basic idea: Look for solutions of the form an = rn,


where r is a constant.
• This requires the characteristic equation:
rn = c1rn−1 + … + ckrn−k, i.e.,
rk − c1rk−1 − … − ck = 0 (Dividing both sides
by rn-k and subtracting right hand side from left).
• The solutions (characteristic roots) can yield
an explicit formula for the sequence.

Discrete Structure/AM103 Mr Pankaj 23


Solving ……

• Theorem1: Let c1 and c2 be real numbers.


Suppose that r2 − c1r − c2 = 0 has two distinct roots r1and r2. Then
the sequence {an} is a solution of the recurrence relation an = c1an−1
+ c2an−2 if and only if an = α1r1n + α2r2n for n≥0, where α1, α2 are
constants.

Discrete Structure/AM103 Mr Pankaj 24


Steps for finding homogeneous solution

Step1: Find the characteristic equation


Step 2: Find characteristic roots
Step 3: Depending on the type of characteristic root find the solution by
rules in slide 18.

Discrete Structure/AM103 Mr Pankaj 25


Rules for finding solution of
Recurrence Relation

Discrete Structure/AM103 Mr Pankaj 26


Discrete Structure/AM103 Mr Pankaj 27
Example(when roots are distinct)

Solve the recurrence an = an−1 + 2an−2 given the initial


conditions a0 = 2, a1 = 7.

Solution:
Step 1: Characteristic equation: an = rn → rn = rn-1 + 2rn-2

r2 = r +2
Characteristic equation:
r2 − r − 2 = 0
Step 2: Roots are: r = 2 or r = −1.

Step 3: So from previous slide


an = α1 2n + α2 (−1)n.

Discrete Structure/AM103 Mr Pankaj 28


Example Continued(for initial
conditions )…

• To find α1 and α2, solve the equations for the initial


conditions a0 and a1:
a0 = 2 = α120 + α2 (−1)0
a1 = 7 = α121 + α2 (−1)1
Simplifying, we have the pair of equations:
2 = α1 + α2
7 = 2α1 − α2
which we can solve easily by substitution:
α2 = 2−α1; 7 = 2α1 − (2−α1) = 3α1 − 2;
9 = 3α1; α1 = 3; α2 = -1.
• Final answer: an = 3·2n − (−1)n

Discrete Structure/AM103 Mr Pankaj 29


Example(when roots are equal)

• E.g., Roots of C.E. are 2, 2, 2, 5, 5, & 9.


• Solution:
(α1,0 + α1,1n + α1,2n2).2n + (α2,0 + α2,1n).5n + α3,09n

Discrete Structure/AM103 Mr Pankaj 30


Practice Example

Solve an = 6an-1 – 11an-2 +6an-3;


a0=2,a1=5, & a2=15.
C.E.: r3 – 6r2 + 11r – 6; Roots = 1,2, & 3.
Solution: an = α1.1n + α2.2n + α3.3n
a0 = 2 = α 1 + α 2 + α 3
a1 = 5 = α1 + α2.2 + α3.3
a2 = 15 = α1 + α2.4 + α3.9
α1 = 1; α2 = -1; α3 = 2.
an = 1 – 2n + 2.3n

Discrete Structure/AM103 Mr Pankaj 31


When roots are equal

Discrete Structure/AM103 Mr Pankaj 32


When roots are complex

Discrete Structure/AM103 Mr Pankaj 33


Recurrence Relation

Discrete Structure/AM103 Mr Pankaj 1


Discrete Structure/AM103 Mr Pankaj 2
Discrete Structure/AM103 Mr Pankaj 3
Definition of Recurrence Relation

Let a1, a2, a3… an be a sequence, then relation that relates an to


one or more previous terms of sequence is called Recurrence
Relation. i.e., A recurrence relation is an equation that recursively
defines a sequence where the next term is a function of the
previous terms
To define sequence corresponding to recurrence relation, it is
important to know first few terms, which are called as initial
conditions of recurrence relation.
Example:
1) an = an-1 +5 with initial condition a0 = 10. It generates the
sequence a0 = 10, a1 = 15, a2 = 20 …
i.e., <10, 15, 20, 25, …>
2) Fibonacci sequence: fn = fn-1 + fn-2 with initial conditions f0 = 1, f1
=1. It generates f0 = 1, f1 =1, f2 =2, f3 = 3, f4 = 5, f5 = 8 …
i.e., <1, 1, 2, 3, 5, 8, 13, 21, … >
Discrete Structure/AM103 Mr Pankaj 4
1) an = an-1 +5 with initial condition a0 = 10.
It generates the sequence a0 = 10, a1 = 15,
a2 = 20 …
i.e., <10, 15, 20, 25, …>

Discrete Structure/AM103 Mr Pankaj 5


1) an = an-1 +5 with initial condition a0 = 10.
It generates the sequence a0 = 10, a1 = 15,
a2 = 20 …
i.e., <10, 15, 20, 25, …>

Discrete Structure/AM103 Mr Pankaj 6


2) Fibonacci sequence: fn = fn-1 + fn-2 with
initial conditions f0 = 1, f1 =1. It generates f0
= 1, f1 =1, f2 =2, f3 = 3, f4 = 5, f5 = 8 …
i.e., <1, 1, 2, 3, 5, 8, 13, 21, … >

Discrete Structure/AM103 Mr Pankaj 7


2) Fibonacci sequence: fn = fn-1 + fn-2 with
initial conditions f0 = 1, f1 =1. It generates f0
= 1, f1 =1, f2 =2, f3 = 3, f4 = 5, f5 = 8 …
i.e., <1, 1, 2, 3, 5, 8, 13, 21, … >

Discrete Structure/AM103 Mr Pankaj 8


Recurrence Relation

If we change initial conditions, then the corresponding


sequence also changes.
Example:
an = an-1 +2 with a0 =1
Corresponding sequence is,
<1, 3, 5, 7, 9, 11 ...> sequence of odd numbers.
Now if we take the same recurrence relation:
Ar = an-1 +2 with a0 = 2
Corresponding sequence is,
<2, 4, 6, 8 … >, sequence of even numbers.

Discrete Structure/AM103 Mr Pankaj 9


Linear Recurrence Relation with
Constant Coefficients

• Let a1, a2, a3 … an … be infinite sequence then


recurrence relation of the form c0 an + c1 an-1 + c2 an-2 +
c3 an-3 + … + ck an-k = f(n). Where ci’s are constants, such
function is called linear recurrence relation with constant
coefficient.
• Construction of Recurrence Relation
• Example 1: Sharma invests Rs.10,0000/- to purchase a
land. Land cost increases by 20% per year. From
recurrence relation, what will be the cost of land after ‘n’
years?
• Solution: Initially land cost = Rs.100000/- i.e., a0 =
100000, suppose an is the land cost after n years.

Discrete Structure/AM103 Mr Pankaj 10


Discrete Structure/AM103 Mr Pankaj 11
Degree of Recurrence Relation
• Number of previous terms required to find next term
of sequence in recurrence relation is called degree
of recurrence relation.
• i.e., Let, c0 an + c1 an-1 + c2 an-2 + c3 an-3 + … + ck
an-k = f(n) is recurrence relation. To find the value of
an, it is important to know the previous terms,
namely, an-1, an-2, an-3 … an-k . Hence, k is a degree
of above recurrence relation.
• Example: Find degree of recurrence relation
an=an-1+an-2,
• Solution: Here, we require two values of an-1, an-2,
to find value of an. Hence, degree of recurrence
relation is 2.
Discrete Structure/AM103 Mr Pankaj 12
Degree of Recurrence Relation

•an + an-1 = 3n2n, first degree

•an + 5 an-1-2an-2 = 3n, second degree

• c0an +c1an-1+c2an-2+…+cr an-r =f(n), rth-degree

•This is a linear recurrence relation with constant coeff. of


rth-degree.

Discrete Structure/AM103 Mr Pankaj 13


•an + 5 an-1-2an-2 = 3n, second degree

•an + an-1 = 3n2n, first degree

Discrete Structure/AM103 Mr Pankaj 14


• c0an +c1an-1+c2an-2+…+cr an-r =f(n), rth-degree

•This is a linear recurrence relation with constant coeff. of


rth-degree.

Discrete Structure/AM103 Mr Pankaj 15


•an + an-1 = 3n2n, first degree

Discrete Structure/AM103 Mr Pankaj 16


•an + 5 an-1-2an-2 = 3n, second degree

Discrete Structure/AM103 Mr Pankaj 17


Characteristic Equation of Recurrence
Relation

• If c0 an + c1 an-1 + c2 an-2 + c3 an-3 + … + ck an-k = f(n) Be


recurrence relation with constant coefficient of degree k
then equation of the type c0 αk + c1 αk-1 + c2 αk-2 + c3 αk-3
+ ... + ck α(k-k) = 0 where, α is constant is called
characteristic equation of recurrence relation.
• Characteristic Roots of Recurrence Relation
• Roots of characteristic equation of recurrence relation
are called as Characteristic roots of recurrence relation.
i.e., values of variable α which satisfy the characteristic
equation are called as characteristic roots. Say α1, α2, α3,
..., αk are k characteristic roots.
• Degree of recurrence relation = number of characteristic
roots
• All characteristic roots may not be distinct.
Discrete Structure/AM103 Mr Pankaj 18
Example

• Example: Find characteristic equation and characteristic roots


of recurrence relation an-7an-1 +12an-2 = 0.

Discrete Structure/AM103 Mr Pankaj 19


Example: Find characteristic equation and
characteristic roots of recurrence relation
an-7an-1 +12an-2 = 0.

Discrete Structure/AM103 Mr Pankaj 20


Homogeneous Recurrence Relation

• Recurrence relation of the type


c0 an + c1 an-1 + c2 an-2 + c3 an-3 + … + ck an-k = f(r)
is homogenous recurrence relation, if f(r)=0.
• i.e., c0 an + c1 an-1 + c2 an-2 + c3 an-3 + … + ck an-k = 0, is a
homogenous recurrence relation.

Discrete Structure/AM103 Mr Pankaj 21


Non-homogeneous Recurrence Relation

• Recurrence relation of the type


c0 an + c1 an-1 + c2 an-2 + c3 an-3 + … + ck an-k = f(n)
is non-homogenous recurrence relation, if f(n)≠0.
• i.e., f(n) may be constant or any function of variable ‘n’.

Discrete Structure/AM103 Mr Pankaj 22


Solution of Recurrence Relation

• A sequence is called a solution of a recurrence relation if its


terms satisfy the recurrence relation
• i.e., a numeric function described by recurrence relation
together with an appropriate set of initial conditions is called a
solution of recurrence relation.
• Homogenous Solution (arh):
• A solution that satisfies the recurrence relation when right
hand side of recurrence relation is zero, is called
homogeneous solution. And is denoted as arh .
• Particular Solution (arp)
• A solution which satisfies the recurrence relation with non
zero f(r) on right hand side is called particular solution. It is
denoted by arp.

Discrete Structure/AM103 Mr Pankaj 23


Solution of Recurrence Relation

• Consider the recurrence relation


an = 2an−1 − an−2 (n≥2).
• Which of the following are solutions?
an = 3n Yes -> 2 [3(n-1)] – 3(n-2)
= 3n => an
an = 2n No -> a0 = 1, a1 = 2, a2 = 4;
a2 = 2a1 – a0 = 2.2 – 1 = 3 ≠ a2
an = 5 Yes -> an = 2.5 – 5 = 5 = an

Discrete Structure/AM103 Mr Pankaj 24


Solving with const. Coefficients

• Basic idea: Look for solutions of the form an = rn,


where r is a constant.
• This requires the characteristic equation:
rn = c1rn−1 + … + ckrn−k, i.e.,
rk − c1rk−1 − … − ck = 0 (Dividing both sides
by rn-k and subtracting right hand side from left).
• The solutions (characteristic roots) can yield
an explicit formula for the sequence.

Discrete Structure/AM103 Mr Pankaj 25


Solving ……

• Theorem1: Let c1 and c2 be real numbers.


Suppose that r2 − c1r − c2 = 0 has two distinct roots r1and r2. Then
the sequence {an} is a solution of the recurrence relation an = c1an−1
+ c2an−2 if and only if an = α1r1n + α2r2n for n≥0, where α1, α2 are
constants.

Discrete Structure/AM103 Mr Pankaj 26


Steps for finding homogeneous solution

Step1: Find the characteristic equation


Step 2: Find characteristic roots
Step 3: Depending on the type of characteristic root find the solution by
rules in slide 18.

Discrete Structure/AM103 Mr Pankaj 27


Rules for finding solution of
Recurrence Relation

Discrete Structure/AM103 Mr Pankaj 28


Discrete Structure/AM103 Mr Pankaj 29
Solve the recurrence an = an−1 + 2an−2
given the initial conditions a0 = 2, a1 = 7.

Discrete Structure/AM103 Mr Pankaj 30


Discrete Structure/AM103 Mr Pankaj 31
Discrete Structure/AM103 Mr Pankaj 32
Example(when roots are distinct)

Solve the recurrence an = an−1 + 2an−2 given the initial


conditions a0 = 2, a1 = 7.

Solution:
Step 1: Characteristic equation: an = rn → rn = rn-1 + 2rn-2

r2 = r +2
Characteristic equation:
r2 − r − 2 = 0
Step 2: Roots are: r = 2 or r = −1.

Step 3: So from previous slide


an = α1 2n + α2 (−1)n.

Discrete Structure/AM103 Mr Pankaj 33


an = an−1 + 2an−2

Discrete Structure/AM103 Mr Pankaj 34


Discrete Structure/AM103 Mr Pankaj 35
Example Continued(for initial
conditions )…

• To find α1 and α2, solve the equations for the initial


conditions a0 and a1:
a0 = 2 = α120 + α2 (−1)0
a1 = 7 = α121 + α2 (−1)1
Simplifying, we have the pair of equations:
2 = α1 + α2
7 = 2α1 − α2
which we can solve easily by substitution:
α2 = 2−α1; 7 = 2α1 − (2−α1) = 3α1 − 2;
9 = 3α1; α1 = 3; α2 = -1.
• Final answer: an = 3·2n − (−1)n

Discrete Structure/AM103 Mr Pankaj 36


Example(when roots are equal)

• E.g., Roots of C.E. are 2, 2, 2, 5, 5, & 9.


• Solution:
(α1,0 + α1,1n + α1,2n2).2n + (α2,0 + α2,1n).5n + α3,09n

Discrete Structure/AM103 Mr Pankaj 37


Discrete Structure/AM103 Mr Pankaj 38
E.g., Roots of C.E. are 2, 2, 2, 5, 5, & 9.
Solution:

Discrete Structure/AM103 Mr Pankaj 39


an = 6an-1 – 11an-2 +6an-3

Discrete Structure/AM103 Mr Pankaj 40


Practice Example

Solve an = 6an-1 – 11an-2 +6an-3;


a0=2,a1=5, & a2=15.
C.E.: r3 – 6r2 + 11r – 6; Roots = 1,2, & 3.
Solution: an = α1.1n + α2.2n + α3.3n
a0 = 2 = α 1 + α 2 + α 3
a1 = 5 = α1 + α2.2 + α3.3
a2 = 15 = α1 + α2.4 + α3.9
α1 = 1; α2 = -1; α3 = 2.
an = 1 – 2n + 2.3n

Discrete Structure/AM103 Mr Pankaj 41


When roots are equal

Discrete Structure/AM103 Mr Pankaj 42


Discrete Structure/AM103 Mr Pankaj 43
Discrete Structure/AM103 Mr Pankaj 44
Discrete Structure/AM103 Mr Pankaj 45
Discrete Structure/AM103 Mr Pankaj 46
Discrete Structure/AM103 Mr Pankaj 47
Discrete Structure/AM103 Mr Pankaj 48
Discrete Structure/AM103 Mr Pankaj 49
Discrete Structure/AM103 Mr Pankaj 50
Discrete Structure/AM103 Mr Pankaj 51
Discrete Structure/AM103 Mr Pankaj 52
Discrete Structure/AM103 Mr Pankaj 53
Discrete Structure/AM103 Mr Pankaj 54
Discrete Structure/AM103 Mr Pankaj 55
Discrete Structure/AM103 Mr Pankaj 56
Discrete Structure/AM103 Mr Pankaj 57
Discrete Structure/AM103 Mr Pankaj 58
Discrete Structure/AM103 Mr Pankaj 59
Discrete Structure/AM103 Mr Pankaj 60
Discrete Structure/AM103 Mr Pankaj 61
Discrete Structure/AM103 Mr Pankaj 62
Discrete Structure/AM103 Mr Pankaj 63
Discrete Structure/AM103 Mr Pankaj 64
Discrete Structure/AM103 Mr Pankaj 65
Discrete Structure/AM103 Mr Pankaj 66
Discrete Structure/AM103 Mr Pankaj 67
Discrete Structure/AM103 Mr Pankaj 68
Discrete Structure/AM103 Mr Pankaj 69
Generation Functions

Discrete Structure/AM103 Mr Pankaj 1


Definition
• Establish connection between two fields in order to apply
knowledge in one field to the other field.
• Given a numeric sequence a = a 0 , a1 , a 2 ,..........., a n ,.....
the series g(x) = a 0 + a1 x + a 2 x + ............ + a n x + ........
2 n

is called the generating function of the sequence.


m
• Example- g(x) = (1+x) generates the binomial coefficients
C(m,r)
• we can also write as
g(x) = 0a + a 1 x + a 2 x 2
+ ............ + a n x n
+ ........

xn
= 
n =0
an
n!
Discrete Structure/AM103 Mr Pankaj 2
Generating function of sequence

Discrete Structure/AM103 Mr Pankaj 3


Discrete Structure/AM103 Mr Pankaj 4
Example
Find the generating function for the sequence a = 1,1,1,1,....

The general term in this sequence is an


 

f(x) =  n =  = + + + + ..................
nn 2 3
a x 1 * x 1 x x x
n =0 n =0

1
= (binomial generating function)
1− x
 
xn xn
g ( x) =  a n = 1 *
n =0 n! n =0 n!
x2 x3
= 1+ x + + + ..........
2! 3!
= ex (exponential generating function)
Discrete Structure/AM103 Mr Pankaj 5
Discrete Structure/AM103 Mr Pankaj 6
Find the generating function for the sequence
1,0,1,0,1,...............

f ( x) = 1 + 0.x + 1.x 2 + 0.x 3 + ..........


= 1 + x 2 + x 4 + ........
1
=
(1 − x 2 )
Determine the sequence generated by f(x) = 1/(1+3x)

f ( x) = 1 /(1 + 3 x)
= (1 + 3 x) −1 = 1 − (3 x) + (3 x) 2 − (3 x) 3 + (3 x) 4 − ..........

Discrete Structure/AM103 Mr Pankaj 7


f ( x) = 1 /(1 + 3 x)
= (1 + 3 x) −1 = 1 − (3 x) + (3 x) 2 − (3 x) 3 + (3 x) 4 − ..........

Discrete Structure/AM103 Mr Pankaj 8


Discrete Structure/AM103 Mr Pankaj 9
Example

For the following two sequences a and b, whose general


terms are given find a + b and ab.

0 for 0  r  2 3 − 2 r for 0  r  1
ar =  − r and br = 
2 + 5 for r  3 r + 2 for r  2
3 − 2 r for 0  r  1

cr = ar + br = 4 for r = 2
2 − r + r + 7 for r  3

0 for 0  r  2
cr = ar * br =  − r
 r 2 + 2 − r +1
+ 5r + 10 for r  3

Discrete Structure/AM103 Mr Pankaj 10


Theorem- Let f(x) is the generating function for a
and g(x) is the generating function for b .
Then f(x)+g(x) is the generating function
for a + b
Theorem- Let f(x) and g(x) be generating function for finite
sequences a and b respectively. The convolution of two
sequences a and b is the sequence c defined as
n
c n =  a r bn − r
r =0

Show the f(x)g(x) is the generating function for convolution


of a and b
Discrete Structure/AM103 Mr Pankaj 11
Example 1

Discrete Structure/AM103 Mr Pankaj 12


Discrete Structure/AM103 Mr Pankaj 13
Discrete Structure/AM103 Mr Pankaj 14
Discrete Structure/AM103 Mr Pankaj 15
Discrete Structure/AM103 Mr Pankaj 16
Discrete Structure/AM103 Mr Pankaj 17
Discrete Structure/AM103 Mr Pankaj 18
Discrete Structure/AM103 Mr Pankaj 19
Discrete Structure/AM103 Mr Pankaj 20
Discrete Structure/AM103 Mr Pankaj 21
Solve: an + an-1 = 3n2n, a0 =0, using generating
function method
Let f(x) be the generating function for the sequence

f(x) =  n
a
n =0
x n

( )
 
=  a n x + a0 x =  3n 2n − an −1 x n
n
n =1 n =1
 
=  3n 2 x −  an −1 x n
n n
n =1 n =1

(
= 3 2 x + 2 ( 2 x ) + 3 ( 2 x ) + .. − xf
2 3
) ( x)
Discrete Structure/AM103 Mr Pankaj 22
Example2

Discrete Structure/AM103 Mr Pankaj 23


Discrete Structure/AM103 Mr Pankaj 24
Discrete Structure/AM103 Mr Pankaj 25
(
f ( x ) = 3.2 x 1 + 2 ( 2 x ) + 3 ( 2 x ) + . − xf ( x )
1 2
)
−2
= 6 x (1 − 2 x ) − xf ( x )

 (1 + x ) f ( x ) = 6 x (1 − 2 x )
2

 f ( x ) = 6 x (1 − 2 x ) (1 + x )
2

2 4 2
= − −
(1 − 2 x ) 2 3 (1 − 2 x ) 3 (1 + x )
Discrete Structure/AM103 Mr Pankaj 26
As f(x)=anxn, so an= coeff. of xn in f(x)

 2 4 2 
= coeff x  n
− − 

 (1 − 2 x )
2
3(1 − 2 x ) 3(1 + x ) 
 2n   2
= (n + 1)2 n +1
− 4  −  (− 1)n
 3   3

 1  n +1 2
=  n + 2 − (− 1)
n

 3 3
Discrete Structure/AM103 Mr Pankaj 27
Discrete Structure/AM103 Mr Pankaj 28
Discrete Structure/AM103 Mr Pankaj 29
Discrete Structure/AM103 Mr Pankaj 30
Logics

1
• A proposition(statement) is a declarative
sentence (a sentence that declares a fact) that is
either true or false, but not both.
• Are the following sentences propositions?
(Yes)
– Toronto is the capital of Canada.
– Read this carefully. (No)
– 1+2=3 (Yes)
(No)
– x+1=2
– What time is it? (No)

2
3
Propositional Logic
• Propositional Logic – the area of logic that
deals with propositions
• Propositional Variables – variables that
represent propositions: p, q, r, s
– E.g. Proposition p – “Today is Friday.”
• Truth values – T, F

4
Logical Operators
Logical operators are used to form new propositions
from two or more existing propositions. The logical
operators are also called connectives.
• Negation
• Conjunction
• Disjunction
• Exclusive OR
• Conditional statement
• Biconditional statement

5
Negation(¬)
Let p be a proposition. The negation of p, denoted by ¬p, is the statement
“It is not the case that p.”
The proposition ¬p is read “not p.” The truth value of the negation of p, ¬p
is the opposite of the truth value of p.

• Examples
– Find the negation of the proposition “Today is Friday.” and express this
in simple English.
Solution: The negation is “It is not the case that today is Friday.”
In simple English, “Today is not Friday.” or “It is not
Friday today.”
– Find the negation of the proposition “At least 10 inches of rain fell
today in Miami.” and express this in simple English.
Solution: The negation is “It is not the case that at least 10 inches
of rain fell today in Miami.”
In simple English, “Less than 10 inches of rain fell today 6
in Miami.”
Truth Table

The Truth Table for the


Negation of a Proposition.
p ¬p
T F
F T

Double Negation Law: ¬(¬ p)=p

7
Conjunction(Λ)
Let p and q be propositions. The conjunction of p and q, denoted by p
Λ q, is the proposition “p and q”. The conjunction p Λ q is true when
both p and q are true and is false otherwise.

• Examples
– Find the conjunction of the propositions p and q where p is the
proposition “Today is Friday.” and q is the proposition “It is raining
today.”, and the truth value of the conjunction.
Solution: The conjunction is the proposition “Today is Friday and it
is raining today.” The proposition is true on rainy Fridays.

8
Truth table of conjunction

9
Disjunction(ν)
Let p and q be propositions. The disjunction of p and q, denoted by p ν
q, is the proposition “p or q”. The conjunction p ν q is false when both
p and q are false and is true otherwise.

10
Truth Table

11
Exclusive or(  )
Let p and q be propositions. The exclusive or of p and q, denoted by p  q,
is the proposition that is true when exactly one of p and q is true and is
false otherwise.

The Truth Table for The Truth Table for The Truth Table for the
the Conjunction of the Disjunction of Exclusive Or (XOR) of
Two Propositions. Two Propositions. Two Propositions.
p q pΛq p q pνq p q p q
T T T T T T T T F
T F F T F T T F T
F T F F T T F T T
F F F F F F F F F
12
13
Conditional Statements
Let p and q be propositions. The conditional statement p → q, is the
proposition “if p, then q.” The conditional statement is false when p is
true and q is false, and true otherwise. In the conditional statement p
→ q, p is called the hypothesis (or antecedent or premise) and q is
called the conclusion (or consequence).

⚫ A conditional statement is also called an implication.


⚫ Example: “If I am elected, then I will lower taxes.” p→q
implication:
elected, lower taxes. T T |T
not elected, lower taxes. F T |T
not elected, not lower taxes. F F |T
elected, not lower taxes. T F |F

14
Example

15
Other conditional statements:
– Converse of p → q : q → p

– Contrapositive of p → q : ¬ q → ¬ p

– Inverse of p → q : ¬ p → ¬ q

16
Example

17
Biconditional Statement
Let p and q be propositions. The biconditional statement p ↔ q is the
proposition “p if and only if q.” The biconditional statement p ↔ q is
true when p and q have the same truth values, and is false otherwise.
Biconditional statements are also called bi-implications.

• p ↔ q has the same truth value as (p → q) Λ (q → p)


• “if and only if” can be expressed by “iff”
• Example:
– Let p be the statement “You can take the flight” and let q be the
statement “You buy a ticket.” Then p ↔ q is the statement
“You can take the flight if and only if you buy a ticket.”
Implication:
If you buy a ticket you can take the flight.
If you don’t buy a ticket you cannot take the flight.
18
Truth Table

The Truth Table for the


Biconditional p ↔ q.
p q p↔ q
T T T
T F F
F T F
F F T

19
Compound Statement
Compound statement is a statement built
out of simple statements using logical.

20
Truth Tables of Compound Propositions

• We can use connectives to build up complicated compound propositions


involving any number of propositional variables, then use truth tables to
determine the truth value of these compound propositions.
• Example: Construct the truth table of the compound proposition
(p ν ¬q) → (p Λ q).

The Truth Table of (p ν ¬q) → (p Λ q).


p q ¬q p ν ¬q pΛq (p ν ¬q) → (p Λ q)

T T F T T T
T F T T F F
F T F F F T
F F T T F F
21
Precedence of Logical Operators
• We can use parentheses to specify the order in which logical operators in
a compound proposition are to be applied.
• To reduce the number of parentheses, the precedence order is defined
for logical operators.

Precedence of Logical Operators.


E.g. ¬p Λ q = (¬p ) Λ q
Operator Precedence
p Λ q ν r = (p Λ q ) ν r
¬ 1 p ν q Λ r = p ν (q Λ r)
Λ 2
ν 3
→ 4
↔ 5

22
English and Logic

23
Translating English Sentences

• English (and every other human language) is often ambiguous. Translating


sentences into compound statements removes the ambiguity.
• Example: How can this English sentence be translated into a logical
expression?
“You cannot ride the roller coaster if you are under 4 feet
tall unless you are older than 16 years old.”

Solution: Let p, q, and r represent “You can ride the roller coaster,”
“You are under 4 feet tall,” and “You are older than
16 years old.” The sentence can be translated into:
(q Λ ¬ r) → ¬p.

24
• Example: How can this English sentence be translated into a logical
expression?
“You can access the Internet from campus only if you are a
computer science major or you are not a freshman.”
Solution: Let p, q, and r represent “You can access the Internet from
campus,” “You are a computer science major,” and “You are
a freshman.” The sentence can be translated into:
p → (q ν ¬r).

25
Logic and Bit Operations

• Computers represent information using bits.


• A bit is a symbol with two possible values, 0 and 1.
• By convention, 1 represents T (true) and 0 represents F (false).
• A variable is called a Boolean variable if its value is either true or false.
• Bit operation – replace true by 1 and false by 0 in logical operations.

Table for the Bit Operators OR, AND, and XOR.


x y xνy x Λy x  y
0 0 0 0 0
0 1 1 0 1
1 0 1 0 1
1 1 1 1 0 26
Absorption Law
Exercise
• A compound proposition that is always true, no matter what the truth
values of the propositions that occurs in it, is called a tautology.

• A compound proposition that is always false is called a contradiction

• A compound proposition that is neither a tautology or a contradiction


is called a contingency.

Examples of a Tautology and a Contradiction.


p ¬p p ν ¬p p Λ ¬p
T F T F
F T T F

38
Logical Equivalences
The compound propositions p and q are called logically equivalent if p ↔
q is a tautology. The notation p ≡ q denotes that p and q are logically
equivalent.

• Compound propositions that have the same truth values in all possible
cases are called logically equivalent.
• Logically equivalent can proved by truth table or by laws of logics
• Example: Show that ¬p ν q and p → q are logically equivalent.
Truth Tables for ¬p ν q and p → q .
p q ¬p ¬p ν q p→q
T T F T T
T F F F F
F T T T T
F F T T T 39
Exercise
Note
• In general, 2n rows are required if a compound proposition involves n
propositional variables in order to get the combination of all truth values.

41
Constructing New Logical Equivalences

• Example: Show that ¬(p → q ) and p Λ ¬q are logically equivalent.


Solution:
¬(p → q ) ≡ ¬(¬p ν q) (Already Proved)
≡ ¬(¬p) Λ ¬q by De Morgan law
≡ p Λ ¬q by the double negation law
• Example: Show that (p Λ q) → (p ν q) is a tautology.
Solution: To show that this statement is a tautology, we will use logical
equivalences to demonstrate that it is logically equivalent to T.
(p Λ q) → (p ν q) ≡ ¬(p Λ q) ν (p ν q)
≡ (¬ p ν ¬q) ν (p ν q) by the first De Morgan law
≡ (¬ p ν p) ν (¬ q ν q) by the associative and
communicative law for disjunction
≡TνT
≡T
• Note: The above examples can also be done using truth tables.
42
Quantifiers

43
Universal Quantifiers

44
Existential Quantifiers

45
Negation of Predicates

46
Argument

An Argument is a statement which asserts that given set of propositions p1,


p2,………pn taken together gives another proposition p.
These are expressed as p1, p2, ………pn /- p
“/- “is known as turnstile
The proposition ‘p1, p2,………pn’ are called premises and ‘p’ is called
conclusion. 47
Valid Argument

An Argument p1, p2, ………pn /- p is true when the assumptions p1,


p2, ………pn is true otherwise it is false.

A True Argument is called a Valid Argument(Tautology)

A False Argument is called a Fallacy or Invalid.

48
Example

If he works hard then he will be successful. If he is successful then


he will be happy, therefore hard work leads to happiness.

49
Example

50
51
52
Example: Test the validity of:
If my brother stands first in class, I will give him a watch . Either he
stood first or I was out of station .I did not give him a watch this time.
Therefore I was out of station .

53
Rewrite the following argument symbolically and determine the validity
of it.
If john graduates ,he gets the job. John does not get the job. Therefore
John doesn't graduate

Solution: Valid Argument

54
55
Lattice

Discrete Structure/AM103 1
Partial Orderings

• A partial ordering (or partial order) is a relation that is


reflexive, antisymmetric, and transitive
– Recall that antisymmetric means that if (a,b)  R, then (b,a)  R
unless b = a
– Thus, (a,a) is allowed to be in R
– But since it’s reflexive, all possible (a,a) must be in R

Discrete Structure/AM103 2
Partially Ordered Set (POSET)

• A relation R on a set S is called a partial ordering or partial order if


it is reflexive, antisymmetric, and transitive. A set S together with a
partial ordering R is called a partially ordered set, or poset, and is
denoted by (S, R)

Discrete Structure/AM103 3
Example (1)

• Let S = {1, 2, 3} and


• let R = {(1,1), (2,2), (3,3), (1, 2), (3,1), (3,2)}

2
3

Discrete Structure/AM103 4
Comparable / Incomparable

Discrete Structure/AM103 5
Example

• Consider the power set of {a, b, c} and the subset relation.


(P({a,b,c}), )

{a, c}  {a, b} and {a, b}  {a, c}

So, {a,c} and {a,b} are incomparable

Discrete Structure/AM103 6
• In the poset (Z+,≤), are the integers 3 and 9 comparable?
– Yes, as 3 ≤ 9
• Are 7 and 5 comparable?
– Yes, as 5 ≤ 7
• As all pairs of elements in Z+ are comparable, the poset (Z+,≤) is a total
order
– a.k.a. totally ordered poset, linear order, or chain

Discrete Structure/AM103 7
• In the poset (Z+,|) with “divides” operator |, are the integers 3 and 9
comparable?
– Yes, as 3 | 9
• Are 7 and 5 comparable?
– No, as 7 | 5 and 5 | 7

• Thus, as there are pairs of elements in Z+ that are not comparable,


the poset (Z+,|) is a partial order. It is not a chain.

Discrete Structure/AM103 8
Totally Ordered, Chains

If (S, ) is a poset and every two elements of


S are comparable, S is called totally ordered or
linearly ordered set, and is called a total
order or a linear order. A totally ordered set is
also called a chain.

Discrete Structure/AM103 9
Discrete Structure/AM103 10
Hasse Diagrams

Given any partial order relation defined on a finite set,


it is possible to draw the directed graph so that all
of these properties are satisfied.

This makes it possible to associate a somewhat simpler


graph, called a Hasse diagram, with a partial order
relation defined on a finite set.

Discrete Structure/AM103 11
Hasse Diagram

• For the poset ({1,2,3,4,6,8,12}, |)

Discrete Structure/AM103 12
For the poset ({1,2,3,4,6,8,12}, |)

Discrete Structure/AM103 13
Discrete Structure/AM103 14
Maximal and Minimal Elements

a is a maximal in the poset (S, ) if there is no b  S


such that a b. Similarly, an element of a poset is
called minimal if it is not greater than any element of
the poset. That is, a is minimal if there is no element
b  S such that b a.
It is possible to have
multiple minimals and maximals.

Discrete Structure/AM103 15
Discrete Structure/AM103 16
Discrete Structure/AM103 17
Discrete Structure/AM103 18
Discrete Structure/AM103 19
Greatest Element
Least Element

a is the greatest element in the poset (S, ) if b a


for all b  S . Similarly, an element of a poset is called
the least element if it is less or equal than all other
elements in the poset. That is, a is the least element if
a b for all b  S

Discrete Structure/AM103 20
Upper bound, Lower bound

Sometimes it is possible to find an element that is


greater than all the elements in a subset A of a poset
(S, ). If u is an element of S such that a u for all
elements a  A , then u is called an upper bound of A.
Likewise, there may be an element less than all the
elements in A. If l is an element of S such that l a
for all elements a  A , then l is called a lower bound of
A.

Discrete Structure/AM103 21
Upper Bound of:

ub{2,6}={6,12}
ub{4,8}={8}
ub{2,6}= {6,12}
Ub{3,4}={12}
Ub{8,12}= no upper bound
Ub{2,3,6}={6,12}
Ub{1,2,4}={4,8,12}

Lower Bounds:

lb{2,6}={1,2}
lb{4,8}={1,2,4}

lb{3,4}={1}
lb{8,12}= {4,2,1}
lb{2,3,6}={1}
lb{1,2,4}={1,2}

Discrete Structure/AM103 22
Least Upper Bound,
Greatest Lower Bound

The element x is called the least upper bound (lub) of


the subset A if x is an upper bound that is less than
every other upper bound of A.
The element y is called the greatest lower bound (glb)
of A if y is a lower bound of A and z y whenever z is
a lower bound of A.

Discrete Structure/AM103 23
Upper Bound and least upper bound of:

ub{2,6}={6,12} lub{2,6}={6}
ub{4,8}={8} lub{4,8}={8}
ub{2,6}= {6,12}
Ub{3,4}={12}
Ub{8,12}= no upper bound
Ub{2,3,6}={6,12} lub{2,3,6}={6}
Ub{1,2,4}={4,8,12} lub{1,2,4}={4}

Lower Bounds and greatest lower


bounds:

lb{2,6}={1,2} glb{2,6}={2}
lb{4,8}={1,2,4} glb{4,8}={4}

lb{3,4}={1} glb{3,4}={1}
lb{8,12}= {4,2,1} glb{8,12}={4}
lb{2,3,6}={1} glb{2,3,6}={1}
lb{1,2,4}={1,2}
Discrete Structure/AM103 24
Discrete Structure/AM103 25
Discrete Structure/AM103 26
Lattices

A partially ordered set in which every pair


of elements has both a least upper bound
and a greatest lower bound is called a
lattice.

Discrete Structure/AM103 27
Examples 21 and 22, p. 575 in Rosen.

Discrete Structure/AM103 28
Z+={1,2,3…………..}

Discrete Structure/AM103 29
Discrete Structure/AM103 30
Discrete Structure/AM103 31
Discrete Structure/AM103 32
Discrete Structure/AM103 33
Discrete Structure/AM103 34
Discrete Structure/AM103 35
Discrete Structure/AM103 36
Discrete Structure/AM103 37
Discrete Structure/AM103 38
Discrete Structure/AM103 39
Discrete Structure/AM103 40
Discrete Structure/AM103 41
Discrete Structure/AM103 42
D20=(D20,/)=divisors of 20={1,2,4,5,10,20}

Discrete Structure/AM103 43
Discrete Structure/AM103 44
Discrete Structure/AM103 45
Discrete Structure/AM103 46
Discrete Structure/AM103 47
D30={1,2,3,5,6,10,15,30}

Discrete Structure/AM103 48
Discrete Structure/AM103 49
Discrete Structure/AM103 50
Discrete Structure/AM103 51
Discrete Structure/AM103 52
Discrete Structure/AM103 53
Discrete Structure/AM103 54
Discrete Structure/AM103 55
Discrete Structure/AM103 56
Discrete Structure/AM103 57
Discrete Structure/AM103 58
Discrete Structure/AM103 59
Discrete Structure/AM103 60
Boolean Algebra
Boolean Algebra/Lattice

A lattice is a Boolean lattice iff it is a


complemented distributive lattice.
Another Definition
De-Morgan’s Law
Examples
Applications of Boolean Algebra
AND Operator
OR Operator
NOT Operator
Truth Table
Exercise
Implementation
Logic Gates
AND Gate
OR Gate
NOT Gate
Principle of Duality
Logic Circuits
Logic Circuits
56
Outline of Presentation

✓Introduction
✓Definition of Graphs
✓Types of Graphs
✓Order & Size of Graphs
✓Degree of Vertex
✓Source & Sink
Definition of Graphs

Graph consists of two sets: a set of vertices V and a set of edges E


obtained by joining certain vertices of V. It is denoted by G(V, E).

V = {A, B, C, D, E, F}

E = {(A, B), (A, C), (A, F), (B, C), (C, D),
(C, E), (D, E), (F, E)}
Adjacent Vertices

Two vertices are said to


be connected if they are
connected by an edge.
TYPES OF GRAPHS

Directed Graphs

A graph in which
every edge is
directed is called
directed graph or
digraph.

Every edge in a directed graph is directed.


TYPES OF GRAPHS (ctd…)

Undirected Graphs

A graph in which
every edge is
undirected is called
undirected graph.
TYPES OF GRAPHS (ctd…)

Mixed Graphs

A mixed graph
in which both
directed and
undirected
edges may exist.
TYPES OF GRAPHS (ctd…)

Self Loops

A self loop is an edge


that connects a
vertex to itself.
TYPES OF GRAPHS (ctd…)

Parallel/ Multiple Edge

Multiple edges (also


called parallel
edges or a multi-
edge), are two or
more edges that are
incident to the same
two vertices.
SIMPLE GRAPH

A graph without loops and parallel edges.


NULL GRAPH

A null graph is a graph in which there are no


edges between its vertices. A null graph is
also called empty graph.
TRIVIAL GRAPH

A trivial graph is the graph which has only one vertex.


ORDER & SIZE OF GRAPH

The number of vertices denoted by 𝑽 𝑮 is called order of G.

Order = 4 Size = 3

The number of edges denoted by 𝑬 𝑮 is called size of G.


DEGREE of VERTEX

It is the number of edges incident on a vertex.

The degree of vertex a is written as deg(a)

deg(a) = 2

deg(b) = 2

deg(c) = 3

deg(d) = 1

If the degree of vertex a is 0 then it is called isolated vertex.


If the degree of vertex a is 1 then it is called pendent vertex.
DEGREE of VERTEX in a UNDIRECTED GRAPH

An undirected graph has no directed edges.


DEGREE of VERTEX in a DIRECTED GRAPH
DEGREE of VERTEX in a DIRECTED GRAPH (ctd…)

Degree of vertex V = Indegree of vertex V + Outdegree of vertex V

Sum of outdegree of vertices = Sum of indegree of vertices = Number of edges


SOURCE & SINK

A vertex A vertex V
V with with zero
zero outdegree
indegree is called
is called sink
source
Some RESULTS

RESULT 1

The sum of the degrees of the vertices of a graph G is


equal to twice the number of edges in G.

෍ deg v = 2|E|

This is also known as Handshaking Lemma


Some RESULTS (ctd…)

RESULT 2

In any graph, the number of vertices of odd degree is even.

RESULT 3

The maximum degree of any vertex in a simple graph with n


vertices is n-1.
Some RESULTS (ctd…)

RESULT 4

The maximum number of edges in a graph with n


𝑛(𝑛−1)
vertices and no multiple edges are
2
DEGREE SEQUENCE

Degree sequence of a
graph is the list of degree
of all the vertices of the
graph. Usually we list the
degrees in non increasing
order, that is from largest
degree to smallest
degree.
Outline of Presentation

✓Walk
✓Trail
✓Path
✓Cycle
✓Distance
✓Eccentricity
✓Diameter
WALK

Walk is sequence of adjacent vertices (or edges)


in a graph.

1 – 2 – 4 – 5 – 3 is a walk from
1 to 3
1 – 2 – 3 -– 4 – 5 – 3 is a walk
from 1 to 3

1 – 2 – 3 – 1 – 2 – 4 – 5 – 3 is a walk
from 1 to 3

Note: A walk can contain vertices and edges


multiple times.
In any graph, the number of vertices of odd degree is even.
TRAIL

Trail is an open walk where vertices can


repeat, but not edges.

1 – 2 – 3 – 4 – 5 – 3 is a trail from
1 to 3.

1 – 2 – 3 – 4 – 5 – 3 – 1 is a closed
trail.
PATH

Path is an open walk with no repetition of


vertices and edges.

1 – 2 – 3 – 4 – 5 is a path
from 1 to 5.

1 – 2 – 4 – 5 – 3 is a path
from 1 to 3.
CIRCUIT

Circuit is a closed walk where vertices can


repeat, but not edges.

1 – 2 – 3 – 4 – 5 – 3 – 1 is a
circuit.
1 – 3 – 5 – 4 – 3 – 2 – 1 is a
circuit.
CYCLE

Cycle is a closed walk where neither vertices nor


edges can repeat. But since it is closed, the first
and the last vertices are the same (one
repetition).

1 – 2 – 4 – 5 – 3 – 1 is a
cycle.

1 – 3 – 5 – 4 – 2 – 1 is
a cycle.
DISTANCE

Distance
between two
vertices in a
graph is the
number of
edges in a
shortest path
connecting
them.
ECCENTRICITY

It is defined as the maximum distance of one vertex


from other vertex. It is denoted by e(V).
DIAMETER of graph

The diameter of graph is the maximum


distance between the pair of vertices.

Way to solve :
Find eccentricity of all vertices and then find
maximum of all.
Regular graph
• If each vertex of a graph G has the same degree as every
other vertex.

• A k- regular graph is a graph whose common degree is k.

Example: Consider k2 and k4. The degree of each vertex in k2


regular graph is 2 and k4 regular graph is 4. Hence k2, k4 are
regular graphs.

13
Complete graph
• A simple graph in which there is exactly one edge between
each pair of distinct vertices is called a complete graph. In a
complete graph, every pair of vertices are adjacent.

15
Planar Graphs
A graph is said to be planar if it can be drawn in a plane
such that no two edges cross each other.

Non-Planar Graphs
A graph is said to be non-planar if it can be drawn in a
plane such that two edges cross each other.

16
Maps
A particular planar representation of a finite planar
multigraph is called a Map.

Region
The map so drawn divides the plane into various areas
bounded by edges which cannot be further subdivided.

17
i) Infinite Region
If the area of the region is infinite, then that region is
called infinite region.

In the above figure, we have R4 to be the infinite


region.
ii) Finite Region
If the area of the region is finite, then that region is called
finite region.

In the above figure, R1, R2 & R3 are finite region and R4 is


infinite region.
iii) Degree of Region
If G is a planar graph and R be its region, then number of
edges in boundary of R is defined as degree of region R.

In the above figure, deg (R1) = 3, deg (R2) = 3, deg(R3) = 3


and deg(R4) = 5.
Note: Degree of a cut edge is counted twice.
20
Properties of Planar graphs

• If a connected planar graph G has E edges and R regions, then R ≤


2/3 E.

• If a connected planar graph G has E edges, V vertices and R


regions then V - E + R = 2 (Euler’s Formula)

• If a connected planar graph G has E edges and V vertices, then

3V – E ≥ 6.

• A complete graph Kn is planar, if and only if n < 5.

21
Question:
Is the complete graph K4 planar ?

Solution:

22
The complete graph K4
contains 4 vertices and 6
edges.

From the property, 3V – E ≥ 6,

hence 3 * 4 – 6 = 6, which
satisfies the property of
planar graphs.

Therefore, K4 is a planar
graph.
• V - E + R = 2 (Euler’s Formula)
Pseudo-graph
• The graphs in which loops and parallel edges are allowed.

26
Weighted graph
• The graph in which weights are assigned to each
edge.

27
Traversable graphs
• A graph is traversable if you can draw a path between all
the vertices without retracing the same path.

28
EULER’S FORMULA

A formula which is used to check the planarity of the given graph is called Euler’s formula.
The general formula is :
|V|-|E|+ |R| = 2
Where, V is the number of vertices in the graph.
E is the number of edges in the graph.
R is the regions in the graph.

In this graph, there are total 5 vertices,10 edges,7 region


i.e. V = 5, E=10, R=7
So, by Euler’s formula
|V|-|E|+ |R| =2
5 - 10 + 7 = 2
i.e. LHS = RHS
Graph Theory
Euler’s formula,
Traveling salesman problem,
Konigsberg Bridge problem,
Chromatic number &
Graph coloring by Welsh Powell Algorithm.
EULER’S FORMULA

A formula which is used to check the planarity of the given graph is called Euler’s formula.
The general formula is :
|V|-|E|+ |R| = 2
Where, V is the number of vertices in the graph.
E is the number of edges in the graph.
R is the regions in the graph.

In this graph, there are total 5 vertices,10 edges,7 region


i.e. V = 5, E=10, R=7
So, by Euler’s formula
|V|-|E|+ |R| =2
5 - 10 + 7 = 2
i.e. LHS = RHS
Travelling Salesman Problem

• Problem Statement
A traveler needs to visit all the cities from a list, where distances between all the cities are known
and each city should be citvisited just once. What is the shortest possible route that he visits each city
exactly once and returns to the origin y?

A salesman visits number of cities during his trips. We denote the cities by vertices and the roads between
the cities by edges. We obtained a connected graph, then assign a real number w(e1),with every edge
e1,called the weight of the edge(distance between the cities).Then we get a weighted graph. There are
numerous Hamiltonian circuits corresponding to this graph. For instance, if there are “n” cities, then there
1
will be (n − 1)! Hamiltonian circuits. However, the salesman problem is to determine that
2
Hamiltonian circuits that has least sum of distance(weight)
ALGORITHM:

1. We select any vertex u1 at the beginning.

2. Then select one vertex say u2 from the n − 1 vertices not selected so far, which is nearest to
u1 . Denote the walk (u1 u2 u1 ) by w2

3.Again select one vertex say u3 from among the n − 2 vertices not selected so far which is nearest to
walk w2 = (u1 u2 u1 ) . Denote the walk (u1 u2 u3 u1 ) by w3

Continuing the process in this manner until all the vertices are selected. Then
wn will give the Hamiltonian cicuit of G
EXAMPLE OF TRAVELLING SALESMAN PROBLEM

▪ Step 1: First we select vertex 𝑢1


• Step 2:Select vertex u2 , which is nearest to 𝑢1 .Let 𝑤2 𝑏𝑒 𝑡ℎ𝑒 𝑤𝑎𝑙𝑘 𝑢1 , 𝑢2 , 𝑢1 .
• Step3:Now,select
vertexu3 , which is nearest towalk w2 . It has distance 10 from u1 . Let 𝑤3 𝑏𝑒 𝑡ℎ𝑒 𝑤𝑎𝑙𝑘 𝑢1 , 𝑢2 , 𝑢3, 𝑢1
• Step 4: Now,select vertex
u4 , which is nearest towalk w3 . It has distance 15 from u1 . Now we detremine the length of cycles.
𝑢1 𝑢2 𝑢3 𝑢4 𝑢1 = 5+35+25+15 = 80
𝑢1 𝑢2 𝑢4 𝑢3 𝑢1 = 5+40+25+10 = 80
𝑢1 𝑢4 𝑢2 𝑢3 𝑢1 = 15+40+35+10 = 100
We denote shortest cycle by 𝑤 . Let 𝑤 = 𝑢 𝑢 𝑢 𝑢 𝑢
• Step 5: We select vertex
u5 , which is nearest towalk w4 . It has distance 20 from u1 . Now we detremine the length of cycles.
𝑢1 𝑢2 𝑢3 𝑢4 𝑢5 𝑢1 = 5+35+25+50+20 = 135
𝑢1 𝑢2 𝑢3 𝑢5 𝑢4 𝑢1 = 5+35+30+50+15 = 135
𝑢1 𝑢2 𝑢5 𝑢3 𝑢4 𝑢1 = 5+45+30+25+15 = 120
𝑢1 𝑢5 𝑢2 𝑢3 𝑢4 𝑢1 = 20+45+35+25+15 = 140

Clearly cycle with length 120 is shortest , so 𝑤5 = (𝑢1 𝑢2 𝑢5 𝑢3 𝑢4 𝑢1 ) is the shortest of these and hence the
solution is
𝑤𝑚𝑖𝑛. =120 as shown in fig.
Traversable Graph :A graph is traversable if you can draw a path between all the vertices
without retracing the same path.
or
Konigsberg Bridge problem

Figure (2)
Figure (1)

There are four Land masses A , B , C , D joined by seven bridges as shown in Figure ( 1).
The problem is to start from anyone of 4 land masses A , B , C , D walk across each bridge exactly once. No one could
design such a tour and Euler explained this problem.
EULER’S THEOREM (KONIGSBERG CASE)
No walking tour of KONIGSBERG can be designed so that each bridge is used exactly once.
KONIGSBERG bridge problem can be represented graphically as shown in figure:

An undirected graph is Eulerian iff it is connected has either 0 or 2


vertices of an odd degree and the rest are even degree.
Or
All the vertices are of even degree, the graph has Eulerian circuit.
CHROMATIC NUMBER OF G
• The chromatic number of a graph is the smallest number of colors needed to
color the vertices of G so that no two adjacent vertices share the same color. It
is most commonly denoted by χ G
How to find the Chromatic number of graph G
Step-01:
• Color first vertex with the first color.
Step-02:
• Now, consider the remaining (V-1) vertices one by one and do the following-
• Color the currently picked vertex with the lowest numbered color if it has not
been used to color any of its adjacent vertices.
• If it has been used, then choose the next least numbered color.
• If all the previously used colors have been used, then assign a new color to the
currently picked vertex.
Vertex a b c d e f
Color C1 C2 C1 C2 C1 C2
Problem-01:
Find chromatic number of the graph (1)
Applying Algorithm, we have :

Vertex a b c d e f
Color C1 C2 C1 C2 C1 C2

From here,
Minimum number of colors used to color the given graph are 2.
Graph 1 Therefore, Chromatic Number of the given graph = 2.
Therefore, The given graph may be properly colored using 2 colors as
shown below-

Graph 2
Graph coloring by Welsh Powell Algorithm
Algorithm
Step 1: Find the degree of all the vertices
Step 2: Order the vertices in G in decreasing order of degree.
Step 3: Use one color for the first vertex and color them in sequential order each vertex
on the list that is not adjacent to a vertex previously colored with this color.
Step 4: Start again from top of list and repeat third step using the second color.
Step 5: Repeat until all vertices are colored.
Vertex v111v2 v3 v4 v5 v6 v7
Degree 5 3 3 4 4 4 3

2. Arrange all the vertices in decreasing order


𝐯𝟏 𝐯𝟒 𝐯𝟓 𝐯𝟔 𝐯𝟐 𝐯𝟐 𝐯𝟑 𝐯𝟕
3. Color C1 to v1 and v7 is not adjacent to v1 color v7 with C1
4. Color v4 byC2 and v2 , v7 is not adjacent to v4 .But
v7 is already colored so color v2 by C2 .
5. Color v5 by C3 .Color v6 by C3 as it is not adjacent to v5 .
6. Now, color v3 by C4 .
So, all the vertices are colored by 4 colors.
Hence, χ G =4
So, at least 4 colors are required to color.
Problem 1:
Find χ G for the graph shown in figure using Welsh Powell Algorithm
Solution:
1. The degree of all the vertices
Vertex v111v2 v3 v4 v5 v6 v7
Degree 5 3 3 4 4 4 3

2. Arrange all the vertices in decreasing order


𝐯𝟏 𝐯𝟒 𝐯𝟓 𝐯𝟔 𝐯𝟐 𝐯𝟐 𝐯𝟑 𝐯𝟕
3. Color C1 to v1 and v7 is not adjacent to v1 color
v7 with C1
4. Color v4 byC2 and v2 , v7 is not adjacent to v4 .But
v7 is already colored so color v2 by C2 .
5. Color v5 by C3 .Color v6 by C3 as it is not adjacent
to v5 .
6. Now, color v3 by C4 .
So, all the vertices are colored by 4 colors.
Hence, χ G =4
So, at least 4 colors are required to color.
Thank
you
TREE
Tree,
Binary trees,
Rooted Tree,
Spanning tree
TREE
A cycle free graph is called acyclic graph. A tree can be defined as a finite connected acyclic graph.
All edges are called its branches. A forest is a collection of trees.
Example

These are the example with 1 vertex, 2,3 vertices respectively, for trees.
Trivial Tree is a tree with only one vertex.
Properties:
1. There is only one path between a pair of vertices of a tree.
2. In a tree with more than one vertex, there are at least two vertices of degree 1.
3. In a tree with n vertices, n≥ 1 ℎ𝑎𝑣𝑒 "𝑛 − 1“ edges.
BINARY TREES
Here, degree of root i.e ‘r’ and node ‘d’ are three while others have
‘0’ to ‘3’ .
Rooted Tree:

• It is a connected graph without any cycle, having a vertex ‘r’ called root of the tree, denoted by
T.

• There is a unique path from root r , to each vertex v in T ,which determines the direction to
each edge. Thus, we can say it is a graph.

• The length (number of edges) of the path from root to vertex is called the level or depth of that
vertex.

Maximum depth or level is the depth of tree.


Level of (f) =2
Level of (b) =1
Level of (j) =3
Depth of tree = 3
If a node has successors S1 , S1 , … … … than N is the parent of Si′ s and Si′ s are the children of N.
Further , Si′ s are siblings to each other.

Parent of (e) = a
Children of (g) = j , k
Siblings of (j) = k
Parent of (c) =
Children of (g) =
Siblings of (h) =
Leaves are
Q. Find parent of c, children of g, siblings of h, all leaves of the
given graph.

Parent of (c) = b
Children of (g) = h , i , j
Siblings of (h) = i , j
Leaves are d , e , f , k , i , l , m
Tree Terminology
Spanning Tree:
A sub-graph T of a connected graph G whose all the vertices are connected by using selected edges
to make a tree T
Example:
Q. Draw all spanning trees of the graph.

Solution:

(ii)
(i)

(iii) (iv)
Thank
you
TREE

Traversing Binary Trees


Binary Tree Traversals
These are of three types:
Preorder Traversal
Inorder Traversal
Postorder Traversal

• Preorder Traversal: The preorder traversal of a binary tree is a recursive process. The
preorder traversal of a tree is

• Visit the root of the tree.


• Traverse the left subtree in preorder.
• Traverse the right subtree in preorder.
Inorder Traversal: The inorder traversal of a binary tree is a recursive process. The
inorder traversal of a tree is

Traverse in inorder the left subtree.

Visit the root of the tree.

Traverse in inorder the right subtree.


Postorder Traversal: The postorder traversal of a binary tree is a recursive process.
The postorder traversal of a tree is

Traverse the left subtree in postorder.

Traverse the right subtree in postorder.

Visit the root of the tree.


Q. In preorder traversal of a binary tree the second step is ____________

(a) traverse the right subtree

(b) traverse the left subtree

(c) traverse right subtree and visit the root

(d) visit the root

Answer: b
Explanation: In a preorder traversal of a binary tree first is to visit the root, second
traverse the left subtree of the tree and third traverse the right subtree of the tree.
Q. Write preorder , inorder , postorder of following tree:
Solution:
Preorder: Root-Left subtree-Right subtree
Inorder

Solution:
Inorder: Left subtree-Root-Right subtree
Post Order:
.

Post Order: Left subtree-Right subtree-Root

Post Order:
.Q. Write preorder , inorder , postorder of following tree:

Preorder: Root-Left subtree-Right subtree


Inorder: Left subtree-Root-Right subtree
Post Order: Left subtree-Right subtree-Root
(i) Preodrer : a b d e c f g

(ii) In order : d b e a f c g

(iii) Post order : d e b f g c a


Q. From the following code identify the which traversal of a binary tree is this __________

//if node has left child


order(node.left)
//if node has right child
order(node.right)
visit(node)

(a) Inorder traversal

(b) preorder traversal

(c) postorder traversal

(d) Euler tour traversal


Answer: C
Explanation: In a postorder traversal of a binary tree first is to traverse the left subtree, second traverse the right
subtree of the tree and third is to visit the node.
TREE

Traversing Binary Trees


Q Determine the preorder and inorder traversal of the
binary tree as shown in fig

Preorder: Root-Left subtree-Right subtree

Solution:
AB

Preorder : A B C D E F G H J K I
Inorder: Left subtree-Root-Right subtree
Q. Construct the binary tree whose inorder and preorder traversal are:

Inorder: E A C I F H D B G
Preorder: F A E I C D H G B Preorder: Root-Left subtree-Right subtree
Solution: Inorder: Left subtree-Root-Right subtree
Q. Construct the binary tree whose inorder and preorder traversal are:

Inorder: E A C I F H D B G
Preorder: F A E I C D H G B
Solution:
Inorder: E A C I F H D B G Inorder: Left subtree-Root-Right subtree
Preorder: F A E I C D H G B Preorder: Root-Left subtree-Right subtree
Solution:

Inorder: E A C I (Left subtree) , F(Root) and H D B G (Right Subtree)


Inorder: E A C I F H D B G
Preorder: F A E I C D H G B
Q. Construct tree from following traversals:
Inorder: D C E B F A H G I Inorder: Left subtree-Root-Right subtree
Postorder: D E C F B H I G A Postorder:Left subtree-Right subtree-Root

.
Q. Construct tree from following traversals:
Inorder: DCEBFAHGI
Postorder: D E C F B H I G A
Inorder: Left subtree-Root-Right subtree
Inorder: D C E B F A H G I Postorder:Left subtree-Right subtree-Root
Postorder: D E C F B H I G A
Last letter of Postorder is A i.e root of the tree is ‘A’.

Inorder: DCEBF A HGI


Root
Left Subtree Right Subtree
Thank
you

You might also like