You are on page 1of 57

Discrete Structure

(BT 12405)

S.Y. B. Tech. Semester IV (CSE)


by
Dr Anagha U. Khiste
Department of Applied Mathematics and Data Science
Indian Institute of Information Technology, Pune
Email: anaghakhiste@iiitp.ac.in

2022-2023
Discrete Structure
_____________________________
Relations
• Relationships between elements of sets occur in many
contexts.
• Every day we deal with relationships such as those between a
business and its telephone number, an employee and his or her
salary, a person and a relative, and so on.
• In mathematics we study relationships such as those between a
positive integer and one that it divides, a real number and one
that is larger than it, a real number x and the value f (x) where f
is a function, and so on.
• Relationships such as that between a program and a variable it
uses, and that between a computer language and a valid
statement in this language often arise in computer science.

anaghakhiste@iiitp.ac.in
Discrete Structure
_____________________________
Relations
Definition:
Let 𝐴 and 𝐵 be sets. A binary relation from 𝐴 to 𝐵 is a subset of
𝐴 × 𝐵 = 𝑎, 𝑏 : 𝑎 ∈ 𝐴 , 𝑏 ∈ 𝐵 .

For a binary relation 𝑅, we have R ⊆ 𝐴 × 𝐵.


Notations:
𝑎𝑅𝑏 denotes 𝑎, 𝑏 ∈ 𝑅 (𝑎 is said to be related to 𝑏 by 𝑅) and
denotes 𝑎, 𝑏 ∉ 𝑅 (𝑎 is said to be not related to 𝑏 by 𝑅)

anaghakhiste@iiitp.ac.in
Discrete Structure
_____________________________
Relations
For example,
• Let 𝐴 be the set of students in CSE branch
𝐴 = *Ajay, Vijay, Ganesh, Seema, Avanti+.
• Let 𝐵 be the courses the department offers
𝐵 = *BT201, BT202, BT203+.
We specify the relation R ⊆ 𝐴 × 𝐵 as the set of all students
𝑎 ∈ 𝐴, enrolled for the courses 𝑏 ∈ 𝐵.
𝑅 = * Ajay, BT201 , Ganesh, BT201 , Ganesh, BT202 ,
Seema, BT203 , (Seema, BT203)+.

anaghakhiste@iiitp.ac.in
Discrete Structure
_____________________________
Representation of Relations
Relations can be represented graphically as well as in a table.
For example,
• Let 𝐴 = 0, 1, 2 and 𝐵 = *a, b+. Then
𝑅 = * 0, a , 0, b , 1, a , 2, b + is a relation from 𝐴 to 𝐵.

anaghakhiste@iiitp.ac.in
Discrete Structure
_____________________________
Relations on a Set
Definition:
A relation on the set A is a relation from A to A.
i. e. a relation on the set A is a subset of 𝐴 × A.

Example:
1. Let 𝐴 = 1, 2,3,4,5 . Let 𝑅 = * 𝑎, 𝑏 : 𝑎 < 𝑏} be the relation
on 𝐴. Represent the relation 𝑅 graphically and in a table.
2. Let 𝐴 = 1, 2,3,4,5 . Let 𝑅 = * 𝑎, 𝑏 : 𝑎|𝑏} be the relation on
𝐴. Represent the relation 𝑅 graphically and in a table.
3. How many relations are there on a set with n elements?
4. How many relations are there on the set 𝐴 = 1, 2,3,4,5 ?

anaghakhiste@iiitp.ac.in
Discrete Structure
_____________________________
Properties of Relations
• Reflexive
• Symmetric
• Antisymmetric
• Asymmetric
• Transitive

anaghakhiste@iiitp.ac.in
Discrete Structure
_____________________________
Properties of Relations
• A relation 𝑅 on a set 𝐴 is
• Reflexive: if (𝑎, 𝑎) ∈ 𝑅 for every element 𝑎 ∈ 𝐴.
• Symmetric: if (𝑏, 𝑎) ∈ 𝑅 whenever (𝑎, 𝑏) ∈ 𝑅, for all
𝑎, 𝑏 ∈ 𝐴.
• Antisymmetric: if (𝑎, 𝑏) ∈ 𝑅 and (𝑏, 𝑎) ∈ 𝑅 for all 𝑎, 𝑏 ∈ 𝐴,
then 𝑎 = 𝑏.
• Asymmetric: if 𝑏, 𝑎 ∉ 𝑅 whenever (𝑎, 𝑏) ∈ 𝑅, for all
𝑎, 𝑏 ∈ 𝐴.
• Transitive: if (𝑎, 𝑏) ∈ 𝑅 and (𝑏, 𝑐) ∈ 𝑅, then (𝑎, 𝑐) ∈ 𝑅, for
all 𝑎, 𝑏, 𝑐 ∈ 𝐴.

anaghakhiste@iiitp.ac.in
Discrete Structure
_____________________________
Properties of Relations
• Remark: Using quantifiers, the relation 𝑅 on the set 𝐴 is
i. reflexive if ∀𝑎 𝑎, 𝑎 ∈ 𝑅 .
ii. symmetric if ∀𝑎∀𝑏((𝑎, 𝑏) ∈ 𝑅 → (𝑏, 𝑎) ∈ 𝑅).
iii. antisymmetric if ∀𝑎∀𝑏(((𝑎, 𝑏) ∈ 𝑅 ∧ (𝑏, 𝑎) ∈ 𝑅) → (𝑎 = 𝑏)).
iv. asymmetric if ∀𝑎∀𝑏( 𝑎, 𝑏 ∈ 𝑅 → 𝑏, 𝑎 ∉ 𝑅).
v. transitive if ∀𝑎∀𝑏∀𝑐(((𝑎, 𝑏) ∈ 𝑅 ∧ (𝑏, 𝑐) ∈ 𝑅) → (𝑎, 𝑐) ∈ 𝑅).

where the universe of discourse is the set of all elements in 𝐴.

Note that, the relations symmetric and antisymmetric are not


opposites while symmetric and asymmetric are opposites.

anaghakhiste@iiitp.ac.in
Discrete Structure
_____________________________
Examples
Ex 1. Consider the following relations on {1, 2, 3, 4}:
𝑅1 = *(1, 1), (1, 2), (2, 1), (2, 2), (3, 4), (4, 1), (4, 4)+,
𝑅2 = *(1, 1), (1, 2), (2, 1)+,
𝑅3 = *(1, 1), (1, 2), (1, 4), (2, 1), (2, 2), (3, 3), (4, 1), (4, 4)+,
𝑅4 = *(2, 1), (3, 1), (3, 2), (4, 1), (4, 2), (4, 3)+,
𝑅5 = *(1, 1), (1, 2), (1, 3), (1, 4), (2, 2), (2, 3), (2, 4), (3, 3), (3, 4), (4, 4)+,
𝑅6 = *(3, 4)+.
Which of these relations are reflexive, symmetric, antisymmetric,
asymmetric and transitive?
Solution:
Reflexive relations: R3 and R5 only.
Symmetric relations: R2 and R3 only.
Antisymmetric relations: R4, R5, and R6 only.
Asymmetric relations: R4 and R6 only.
Transitive relations: R4, R5, and R6 only.
anaghakhiste@iiitp.ac.in
Discrete Structure
_____________________________
Examples
Ex 2. Consider these relations on the set of integers:
R1 = {(a, b) | a ≤ b},
R2 = {(a, b) | a > b},
R3 = {(a, b) | a = b or a = −b},
R4 = {(a, b) | a = b},
R5 = {(a, b) | a = b + 1},
R6 = {(a, b) | a + b ≤ 3}.
Which of these relations are reflexive, symmetric, antisymmetric,
asymmetric and transitive?
Solution:
Reflexive relations: R1 , R3 and R4 only.
Symmetric relations: R3 , R4 and R6 only.
Antisymmetric relations: R1 , R2 , R4, and R5 only.
Asymmetric relations: R2 only.
Transitive relations: R1 , R2 , R3 and R4 only. anaghakhiste@iiitp.ac.in
Discrete Structure
_____________________________
Examples

Ex 3. Is the “divides” relation on the set of positive integers reflexive,


symmetric, antisymmetric, asymmetric and transitive?
Solution: It is reflexive, antisymmetric and transitive only.

Q. What you can say if we replace the set of positive integers with the set of
all integers?

anaghakhiste@iiitp.ac.in
Discrete Structure
_____________________________
Combining Relations
• As relations are sets, so we can apply the usual set operations to them.

• If we have two relations from a set 𝐴 to a set 𝐵, say 𝑅1 and 𝑅2 , then we


can combine them to 𝑅1 ∪ 𝑅2 , 𝑅1 ∩ 𝑅2 , 𝑅1 − 𝑅2 , 𝑅2 − 𝑅1 and soon. Thus
the resultant set is also a relation from 𝐴 to 𝐵.

For Example;
Let 𝐴 = *1, 2, 3+ and 𝐵 = *1, 2, 3, 4+. The relations
𝑅1 = *(1, 1), (2, 2), (3, 3)+ and
𝑅2 = *(1, 1), (1, 2), (1, 3), (1, 4)+ can be combined to obtain
𝑅1 ∪ 𝑅2 = *(1, 1), (1, 2), (1, 3), (1, 4), (2, 2), (3, 3)+,
𝑅1 ∩ 𝑅2 = *(1, 1)+,
𝑅1 − 𝑅2 = *(2, 2), (3, 3)+,
𝑅2 − 𝑅1 = *(1, 2), (1, 3), (1, 4)+.
anaghakhiste@iiitp.ac.in
Discrete Structure
_____________________________
Composite of the Relations
• Definition: Let 𝑅 be a relation from a set 𝐴 to a set 𝐵 and 𝑆 a relation
from 𝐵 to a set 𝐶. The composite of 𝑅 and 𝑆 is the relation consisting
of ordered pairs (𝑎, 𝑐), where 𝑎 ∈ 𝐴, 𝑐 ∈ 𝐶, and for which there
exists an element 𝑏 ∈ 𝐵 such that (𝑎, 𝑏) ∈ 𝑅 and (𝑏, 𝑐) ∈ 𝑆. We
denote the composite of 𝑅 and 𝑆 by 𝑆◦𝑅 .

• For Example;
What is the composite of the relations 𝑅 and 𝑆, where 𝑅 is the relation
from *1, 2, 3+ to *1, 2, 3, 4+ with 𝑅 = *(1, 1), (1, 4), (2, 3), (3, 1), (3, 4)+
and 𝑆 is the relation from *1, 2, 3, 4+ to *0, 1, 2+ with
𝑆 = *(1, 0), (2, 0), (3, 1), (3, 2), (4, 1)+?

Solution:
𝑆◦𝑅 = *(1, 0), (1, 1), (2, 1), (2, 2), (3, 0), (3, 1)+.

anaghakhiste@iiitp.ac.in
Discrete Structure
_____________________________
Powers of the Relation

For Example:

Let 𝑅 = *(1, 1), (2, 1), (3, 2), (4, 3)+. Find the powers 𝑅𝑛 , 𝑛 = 2, 3, 4, . . . .

Solution: Let 𝑅 = *(1, 1), (2, 1), (3, 2), (4, 3)+.
• 𝑅2 = 𝑅◦𝑅 = 𝑅2 = *(1, 1), (2, 1), (3, 1), (4, 2)+.
• 𝑅3 = 𝑅2 ◦𝑅 = *(1, 1), (2, 1), (3, 1), (4, 1)+.
• 𝑅4 = 1, 1 , 2, 1 , 3, 1 , 4, 1 = 𝑅3 .
It also follows that 𝑅𝑛 = 𝑅3 for 𝑛 = 5, 6, 7, . . . . (verify this).
anaghakhiste@iiitp.ac.in
Discrete Structure
_____________________________
Powers of the Relation
Theorem: The relation 𝑅 on a set 𝐴 is transitive if and only
if 𝑅𝑛 ⊆ 𝑅 for 𝑛 = 1, 2, 3, . . . .
Proof: Let the relation 𝑅 on a set 𝐴 is transitive.
claim: 𝑅𝑛 ⊆ 𝑅 for 𝑛 = 1, 2, 3, . . .
This proof follows by applying mathematical induction on n.
Now, for the converse part, we assume that 𝑅𝑛 ⊆ 𝑅 for 𝑛 = 1, 2, 3, . . .
and we claimed that 𝑅 is transitive.
Clearly, the proof follows by using the definition of composite of the
relation and the fact that R2 ⊆ 𝑅 .

anaghakhiste@iiitp.ac.in
Discrete Structure
_____________________________
Representing Relations Using Matrices

Let 𝑅 be any relation from a set 𝐴 = 𝑎1 , 𝑎2 , … , 𝑎𝑚 to a set


B = 𝑏1 , 𝑏2 , … , 𝑏𝑛 . Then the relation 𝑅 can be represented
by the matrix M𝑅 = mij where
m×n
𝑚𝑖𝑗 = 1, if 𝑎𝑖 , 𝑏𝑗 ∈ 𝑅
= 0, if 𝑎𝑖 , 𝑏𝑗 ∉ 𝑅

In other words, the zero–one matrix representing 𝑅 has a 1 as its


(𝑖, 𝑗 ) entry when 𝑎𝑖 is related to 𝑏𝑗 , and a 0 in this position if 𝑎𝑖 is not
related to 𝑏𝑗 .

anaghakhiste@iiitp.ac.in
Discrete Structure
_____________________________
Representing Relations Using Matrices
For Example:
1. Suppose that A = {1, 2, 3} and B = {1, 2}. Let 𝑅 =
* 𝑎, 𝑏 : 𝑎 > 𝑏+ be the relation from a set 𝐴 to a set 𝐵.
What is the matrix representation of R?

anaghakhiste@iiitp.ac.in
Discrete Structure
_____________________________
Representing Relations Using Matrices
For Example:
2.

Solution: Because all the diagonal elements of this matrix are


equal to 1, 𝑅 is reflexive. Moreover, because 𝑀𝑅 is symmetric, it
follows that 𝑅 is symmetric. It is also easy to see that 𝑅 is not
antisymmetric.

anaghakhiste@iiitp.ac.in
Discrete Structure
_____________________________
Representing Relations Using Matrices
• Boolean Matrix: A matrix having entries are either 0 or 1.
• Boolean Matrix Operations:
1. Let 𝐴 = aij and B= bij be two Boolean matrices.
m×n m×n
We denote join of 𝐴 and B by 𝐴 ∨ 𝐵 and it is defined as a
Boolean matrix 𝐶 = cij where
m×n
𝑐𝑖𝑗 = 1, if 𝑎𝑖𝑗 = 1 or 𝑏𝑖𝑗 = 1
= 0, if 𝑎𝑖𝑗 = 0 and 𝑏𝑖𝑗 = 0
In other words,
𝑐𝑖𝑗 = 𝑎𝑖𝑗 ∨ 𝑏 𝑖𝑗 , ∀𝑖 and ∀𝑗

anaghakhiste@iiitp.ac.in
Discrete Structure
_____________________________
Representing Relations Using Matrices
2. Let 𝐴 = aij and B= bij be two Boolean matrices.
m×n m×n
We denote meet of 𝐴 and B by 𝐴 ∧ 𝐵 and it is defined as a
Boolean matrix 𝐶 = cij where
m×n
𝑐𝑖𝑗 = 1, if 𝑎𝑖𝑗 = 1 and 𝑏𝑖𝑗 = 1
= 0, if 𝑎𝑖𝑗 = 0 or 𝑏𝑖𝑗 = 0
In other words,
𝑐𝑖𝑗 = 𝑎𝑖𝑗 ∧ 𝑏 𝑖𝑗 , ∀𝑖 and ∀𝑗

anaghakhiste@iiitp.ac.in
Discrete Structure
_____________________________
Representing Relations Using Matrices
3. Let 𝐴 = aij and B= bij be two Boolean matrices.
m×p p×n
We denote product of 𝐴 and B by 𝐴 𝐵 and it is defined as a
Boolean matrix 𝐶 = cij where
m×n
𝑐𝑖𝑗 = 1, if 𝑎𝑖𝑘 = 1 and 𝑏𝑘𝑗 = 1 for some k, 1 ≤ 𝑘 ≤ 𝑝,
= 0, otherwise
In other words,
𝑝
𝑐𝑖𝑗 =∨ 𝑘=1 (𝑎𝑖𝑘 ∧ 𝑏 𝑘𝑗 )

anaghakhiste@iiitp.ac.in
Discrete Structure
_____________________________
Representing Relations Using Matrices
Remarks:
1. Let 𝑅1 and 𝑅2 be two relations on a set 𝐴 . Then

2. Let 𝑅 be a relation from 𝐴 to 𝐵 and 𝑆 be a relation


from 𝐵 to 𝐶. Then

3. Let 𝑅 be a relation on a set 𝐴. Then

anaghakhiste@iiitp.ac.in
Discrete Structure
_____________________________
Examples
1.

2.

3.

anaghakhiste@iiitp.ac.in
Discrete Structure
_____________________________
Representing Relations Using Digraphs
Directed graph, or Digraph:
• Graphical representation of a relation R on a finite set A.

1. Let 𝐴 = *𝑎, 𝑏, 𝑐, 𝑑+ and


𝑅 = *(𝑎, 𝑏), (𝑎, 𝑑), (𝑏, 𝑏), (𝑏, 𝑑), (𝑐, 𝑎), (𝑐, 𝑏), (𝑑, 𝑏)+. Then
digraph of R is represented as

anaghakhiste@iiitp.ac.in
Discrete Structure
_____________________________
Representing Relations Using Digraphs
2. Determine whether the relations for the directed graphs shown
in following figures are reflexive, symmetric, antisymmetric,
and/or transitive.

anaghakhiste@iiitp.ac.in
Discrete Structure
_____________________________
Transitive Closures
• Let 𝑅 be a relation on a set 𝐴, then transitive closure of 𝑅 is
• denoted by 𝑅∗ or 𝑅∞
• defined as a smallest transitive relation containing 𝑅.
• In other words,

• 𝑅∗ is always a transitive relation.


• 𝑅 is transitive if and only if 𝑅∗ = 𝑅.
• Let 𝑅 be a relation on a finite set 𝐴 = *𝑎1 , 𝑎2 , … , 𝑎𝑛 +, then
𝑛 𝑘
MR = ∨𝑘=1 𝑀𝑅

1 2 𝑛
= 𝑀𝑅 ∨ 𝑀𝑅 ∨ ⋯ ∨ 𝑀𝑅
= 𝑀𝑅 ∨ 𝑀𝑅2 ∨ ⋯ ∨ 𝑀𝑅𝑛
anaghakhiste@iiitp.ac.in
Discrete Structure
_____________________________
Transitive Closures
• Let 𝑅 = * 1,1 , 1,2 , 2,3 , 1,3 , 3,1 , (3,2)+ be a relation
on a set 𝐴 = *1,2,3+, then find the matrix MR⋆ .

1 1 1
1
Solution: 𝑀𝑅 = M𝑅 = 0 0 1 .
1 1 0
1 1 1 1 1 1
2 3
𝑀𝑅 = 1 1 0 . 𝑀𝑅 = 1 1 1 .
1 1 1 1 1 1

1 1 1
1 2 3
Thus MR∗ = 𝑀𝑅 ∨ 𝑀𝑅 ∨ 𝑀𝑅 = 1 1 1
1 1 1

And hence R∗ = 𝐴 × 𝐴 . anaghakhiste@iiitp.ac.in


Discrete Structure
_____________________________
Warshall’s Algorithm
• It is used to find the transitive closure of a relation on a set
with 𝑛 elements.
• It is an efficient method for computing the transitive closure
𝑘
of a relation, since using the formula MR∗ = ∨𝑛𝑘=1 𝑀𝑅
requires 2𝑛3 (𝑛 − 1) bit operations, however by Warshall’s
algorithm it requires only 2𝑛3 bit operations.

anaghakhiste@iiitp.ac.in
Discrete Structure
_____________________________
Warshall’s Algorithm
• Suppose that 𝑅 is a relation on a set with 𝑛 elements. Let
𝑣1 , 𝑣2 , . . . , 𝑣𝑛 be an arbitrary listing of these 𝑛 elements.
• It is based on the construction of a sequence of Boolean
matrices 𝑊0 , 𝑊1 , . . . , 𝑊𝑛 , where 𝑊0 = 𝑀𝑅 and 𝑊𝑘 =
(𝑘) (𝑘)
,𝑤𝑖𝑗 -, where 𝑤𝑖𝑗 = 1 if there is a path from 𝑣𝑖 to 𝑣𝑗 such that
all the interior vertices of this path are in the set {𝑣1 , 𝑣2 , . . . ,
𝑣𝑘 } (the first 𝑘 vertices in the list) and is 0 otherwise. (The first
and last vertices in the path may be outside the set of the first 𝑘
vertices in the list.)
• Note that 𝑊𝑛 = 𝑀𝑅 ∗ , because the 𝑖, 𝑗 𝑡ℎ entry of 𝑀𝑅 ∗ is 1 if
and only if there is a path from 𝑣𝑖 to 𝑣𝑗 , with all interior vertices
in the set {𝑣1 , 𝑣2 , . . . , 𝑣𝑛 + (but these are the only vertices in the
directed graph).
anaghakhiste@iiitp.ac.in
Discrete Structure
_____________________________
1. Let 𝐴 = *𝑎, 𝑏, 𝑐, 𝑑+ and let 𝑅 be the relation on 𝐴 shown in the
following digraph. Then find transitive closure 𝑅∗ using
Warshall’s algorithm.

Solution: Let 𝑣1 = 𝑎, 𝑣2 = 𝑏, 𝑣3 = 𝑐, and 𝑣4 = 𝑑. W0 is the matrix


of the relation. Hence,

anaghakhiste@iiitp.ac.in
Discrete Structure
_____________________________
• 𝑊1 has 1 as its 𝑖, 𝑗 𝑡ℎ entry if there is a path from 𝑣𝑖 to 𝑣𝑗 that
has only 𝑣1 = 𝑎 as an interior vertex. Note that all paths of
length one can still be used because they have no interior
vertices. Also, there is now an allowable path from 𝑏 to 𝑑,
namely, 𝑏, 𝑎, 𝑑. Hence,

• 𝑊2 has 1 as its 𝑖, 𝑗 𝑡ℎ entry if there is a path from 𝑣𝑖 to 𝑣𝑗 that


has only 𝑣1 = 𝑎 and/or 𝑣2 = 𝑏 as its interior vertices, if any.
Because there are no edges that have 𝑏 as a terminal vertex, no
new paths are obtained when we permit 𝑏 to be an interior
vertex. Hence, 𝑊2 = 𝑊1 . anaghakhiste@iiitp.ac.in
Discrete Structure
_____________________________
• 𝑊3 has 1 as its 𝑖, 𝑗 𝑡ℎ entry if there is a
path from 𝑣𝑖 to 𝑣𝑗 that has only
𝑣1 = 𝑎, 𝑣2 = 𝑏, and/or 𝑣3 = 𝑐 as its
interior vertices, if any. We now have
paths from 𝑑 to 𝑎, namely, 𝑑, 𝑐, 𝑎, and
from 𝑑 to 𝑑, namely, 𝑑, 𝑐, 𝑑. Hence,

• Finally,𝑊4 has 1 as its 𝑖, 𝑗 𝑡ℎ entry if


there is a path from 𝑣𝑖 to 𝑣𝑗 that
has 𝑣1 = 𝑎, 𝑣2 = 𝑏, 𝑣3 = 𝑐,and/or 𝑣4 =
𝑑 as interior vertices, if any. Because
these are all the vertices of the graph, this
entry is 1 if and only if there is a path
from 𝑣𝑖 to 𝑣𝑗 . Hence,
• Thus, 𝑅∗ = (𝐴 × 𝐴) − *(𝑎, 𝑏), (𝑏, 𝑏), (𝑐, 𝑏), (𝑑, 𝑏)+.
anaghakhiste@iiitp.ac.in
Discrete Structure
_____________________________
Warshall’s Algorithm
Alternatively, we can compute 𝑊𝑘 directly from 𝑊𝑘−1 :
Suppose 𝑊𝑘 = ,𝑡𝑖𝑗 - and 𝑊𝑘−1 = ,𝑠𝑖𝑗 -.
Then 𝑡𝑖𝑗 = 1 iff either
i. sij = 1 or
ii. si𝑘 = 1 and skj = 1
For example:
1. Let 𝐴 = *1, 2, 3+ and let
𝑅 = * 1,1 , 1,2 , 1,3 , 2,3 , 3,1 , (3,2)+ be the relation on
𝐴. Then find transitive closure 𝑅∗ using Warshall’s algorithm.
1 1 1
Solution: Since 𝑊0 = M𝑅 = 0 0 1 .
1 1 0

anaghakhiste@iiitp.ac.in
Discrete Structure
_____________________________
Warshall’s Algorithm
1 1 1
𝑘 = 1: 𝑊1 = 0 0 1
1 1 1
(here 𝑡33 = 1, since 𝑠31 = 1 and 𝑠13 = 1)
1 1 1
𝑘 = 2: 𝑊2 = 0 0 1
1 1 1
1 1 1
𝑘 = 3: 𝑊3 = 𝑊𝑛 = 1 1 1
1 1 1
(here 𝑡21 = 1, since 𝑠23 = 1 and 𝑠31 = 1. Also 𝑡22 = 1, since
𝑠23 = 1 and 𝑠32 = 1)
Hence 𝑅∗ = 𝐴 × 𝐴.

anaghakhiste@iiitp.ac.in
Discrete Structure
_____________________________
2. Let 𝐴 = 1, 2, 3, 4 and let 𝑅 = * 1,2 , 2, 1 , 2,3 , 3,4 + be
the relation on 𝐴. Then find transitive closure 𝑅∗ using Warshall’s
algorithm.
0 1 0 0
Solution: 𝑊0 = 1 0 1 0
0 0 0 1
0 0 0 0

0 1 0 0
𝑘 = 1: 𝑊1 = 1 1 1 0
0 0 0 1
0 0 0 0
(here 𝑡22 = 1, since 𝑠21 = 1 and 𝑠12 = 1)

anaghakhiste@iiitp.ac.in
Discrete Structure
_____________________________
1 1 1 0
𝑘 = 2: 𝑊2 = 1 1 1 0
0 0 0 1
0 0 0 0

1 1 1 1
𝑘 = 3: 𝑊3 = 1 1 1 1
0 0 0 1
0 0 0 0
Hence
1 1 1 1 𝑅∗ = * 1,1 , 1,2 , 1,3 ,
𝑘 = 4: 𝑊4 = 1 1 1 1 1,4 , 2,1 , 2,2 , 2,3 ,
0 0 0 1
2,4 , (3,4)}
0 0 0 0

anaghakhiste@iiitp.ac.in
Discrete Structure
_____________________________
Recurrence Relations
• Sequence: List of objects arranged in a definite order.
• Recursive formula: Every term is defined using previous
term (it always include a starting place)
• Explicite formula: It exactly gives the value of any
particular term.
• Numeric function: Any function 𝑎: 𝑁 → 𝑅.
• Generating function: Infinite series representation of a
numeric function 𝑎 = *𝑎0 , 𝑎1 , … , 𝑎𝑟 , … +

𝐴 𝑧 = 𝑎0 + 𝑎1 𝑧 + 𝑎2 𝑧 2 + ⋯ + 𝑎𝑟 𝑧 𝑟 + ⋯ = 𝑎𝑟 𝑧 𝑟
𝑟=0

anaghakhiste@iiitp.ac.in
Discrete Structure
_____________________________
• Recurrence Relations (or Difference equation): It is the
recursive formula which is used to define a sequence (or
numeric function)
• Linear Recurrence Relations with constant coefficients:
A linear recurrence relation of order k with constant
coefficients is a recurrence relation of the form
𝑐0 𝑎𝑟 + 𝑐1 𝑎𝑟−1 + ⋯ + 𝑐𝑘 𝑎𝑟−𝑘 = f r ,
where 𝑟 ≥ 𝑘 are non-negative integers and 𝑐0 , 𝑐1 , …, 𝑐𝑘 are
constants such that 𝑐0 & 𝑐𝑘 are non-zero.
• For example:
1. 𝑎𝑟 − 2𝑎𝑟−1 = 2𝑟 (1st order linear rec. rel. with const. coeff. )
2. 𝑎𝑟2 + 𝑎𝑟−1 = 5 ( not a linear rec. rel.)
3. 𝑎𝑟 + 4𝑎𝑟−3 = 𝑟 2 (3rd order linear rec. rel. with const. coeff. )

anaghakhiste@iiitp.ac.in
Discrete Structure
_____________________________
Classification of a Linear Recurrence Relations

• Homogenenous linear recurrence relation: f r = 0


• Non-Homogenenous linear recurrence relation: f r ≠ 0

• Methods for solving homogenenous linear recurrence


relation: (f r = 0)
1. Substitution method
2. Method of generating functions
3. Method of characteristic roots

anaghakhiste@iiitp.ac.in
Discrete Structure
_____________________________

1. Substitution method:
For example:
Solve the recurrence relation
𝑎𝑟 = 2𝑎𝑟−1 + 1 with 𝑎1 = 7 for 𝑟 > 1
Solution:
Since 𝑎1 = 7, we have 𝑎2 = 2𝑎1 + 1 = 15 = 7 × 2 + 1
𝑎3 = 2𝑎2 + 1 = 31 = 7 × 22 + 21 + 1
𝑎4 = 2𝑎3 + 1 = 63 = 7 × 23 + 22 + 21 + 1 and so on…
Thus ∀ 𝑟 ≥ 1
𝑎𝑟 = 7 × 2𝑟−1 + 2𝑟−2 + 2𝑟−3 + ⋯ + 21 + 1
= 7 × 2𝑟−1 + 2𝑟−1 − 1 (since by binomial exp.)

anaghakhiste@iiitp.ac.in
Discrete Structure
_____________________________
2. Method of generating function:
For example: Solve the recurrence relation
𝑎𝑟 − 2𝑎𝑟−1 − 3ar−2 = 0 with 𝑟 ≥ 2 𝑎0 = 3, 𝑎1 =1
Solution: Consider
∞ ∞ ∞

𝑎𝑟 𝑧 𝑟 − 2 𝑎𝑟−1 𝑧 𝑟 − 3 𝑎𝑟−2 𝑧 𝑟 = 0
𝑟=2 𝑟=2 𝑟=2
,𝐴 𝑧 − 𝑎0 −𝑎1 𝑧- − 2*𝑧,𝐴 𝑧 − 𝑎0 -+ − 3𝑧 2 𝐴(𝑧) = 0
Since 𝑎0 = 3, 𝑎1 =1, we have
3 − 5𝑧 1 2
𝐴 𝑧 = 2 = +
1 − 2𝑧 − 3𝑧 1 − 3𝑧 1 + 𝑧
∞ ∞ ∞
𝑟
= 3𝑧 +2 −1 𝑟 𝑧 𝑟 = (3𝑟 + 2 −1 𝑟 )𝑧 𝑟
𝑟=0 𝑟=0 𝑟=0
𝑟 𝑟
Thus 𝑎𝑟 = 3 + 2 −1 , ∀ 𝑟 ≥ 0.
anaghakhiste@iiitp.ac.in
Discrete Structure
_____________________________
3. Method of Characteristic Roots:
Consider the homogenous linear recurrence relation of order k
𝑐0 𝑎𝑟 + 𝑐1 𝑎𝑟−1 + ⋯ + 𝑐𝑘 𝑎𝑟−𝑘 = 0 …….(1)
Let us consider the characteristic equation is the 𝑘 𝑡ℎ degree
polynomial in 𝑥 with coefficients are 𝑐0 , 𝑐1 , …, 𝑐𝑘 .
i.e. 𝑐0 𝑥 𝑘 + 𝑐1 𝑥 𝑘−1 + ⋯ + 𝑐𝑘−1 𝑥 + 𝑐𝑘 = 0 …….(2)
This gives 𝑘 roots of equation (2) say, 𝑥1 , 𝑥2 , …, 𝑥𝑘 .
Case (i): If all 𝑘 roots are distinct, then the general solution of
equation (1) is 𝑎𝑟 = 𝐴1 𝑥1𝑟 + 𝐴2 𝑥2𝑟 + ⋯ + 𝐴𝑘 𝑥𝑘𝑟
where 𝐴1 , 𝐴2 , … , 𝐴𝑟 are constants which are to be
determined using the given initial conditions
Case (ii): Roots are repeated: Suppose a root say 𝑥1 is repeated 𝑚
times, then the term 𝐴1 𝑥1𝑟 from the above expression is
replaced by (𝐴1′ 𝑟 𝑚−1 + 𝐴′2 𝑟 𝑚−2 + ⋯ + 𝐴′𝑚−1 𝑟 + 𝐴′𝑚 )𝑥1𝑟 .
anaghakhiste@iiitp.ac.in
Discrete Structure
_____________________________
3. Method of Characteristic Roots:
For example:
1. Solve 𝑎𝑟 − 10𝑎𝑟−1 + 9𝑎𝑟−2 = 0 with 𝑎0 = 3 & 𝑎1 = 11.
Solution: Given equation is
𝑎𝑟 − 10𝑎𝑟−1 + 9𝑎𝑟−2 = 0 …….(1)
Consider the characteristic equation as
𝑥 2 − 10𝑥 + 9 = 0 …….(2)
Since, the roots of equation (2) are 𝑥 = 1, 9 which are distinct.
Thus the general solution of equation (1) is
𝑎𝑟 = 𝐴1 1𝑟 + 𝐴2 9𝑟 = 𝐴1 + 𝐴2 9𝑟
where 𝐴1 & 𝐴2 are constants
Since 𝑎0 = 𝐴1 + 𝐴2 = 3 & 𝑎1 = 𝐴1 + 9𝐴2 = 11,
we have 𝐴1 = 2 & 𝐴2 = 1
and hence 𝑎𝑟 = 2 + 9𝑟 , ∀𝑟 ≥ 0.
anaghakhiste@iiitp.ac.in
Discrete Structure
_____________________________
3. Method of Characteristic Roots:
Ex 2. Solve 𝑎𝑟 = 6𝑎𝑟−1 − 9𝑎𝑟−2 with 𝑎0 = 1 & 𝑎1 = 6 .
Solution: Given equation is
𝑎𝑟 − 6𝑎𝑟−1 + 9𝑎𝑟−2 = 0 …….(1)
Consider the characteristic equation as
𝑥 2 − 6𝑥 + 9 = 0 …….(2)
Since, the root of equation (2) is 𝑥 = 3, which is repeated twice.
Thus the general solution of equation (1) is
𝑎𝑟 = (𝐴1 𝑟1 + 𝐴2 )3𝑟 = (𝐴1 𝑟 + 𝐴2 )3𝑟
where 𝐴1 & 𝐴2 are constants
Since 𝑎0 = 𝐴2 = 1 & 𝑎1 = (𝐴1 +𝐴2 )31 = 6,
we have 𝐴1 = 1 & 𝐴2 = 1
and hence 𝑎𝑟 = 𝑟 + 1 3𝑟 = 3𝑟 + 𝑟3𝑟 , ∀𝑟 ≥ 0.

anaghakhiste@iiitp.ac.in
Discrete Structure
_____________________________
3. Method of Characteristic Roots:
Ex.3. Solve 𝑎𝑟 + 6𝑎𝑟−1 + 12𝑎𝑟−2 + 8𝑎𝑟−3 = 0
with 𝑎0 = 𝑎1 = 0 & 𝑎2 = 2 .
Solution: Given equation is
𝑎𝑟 + 6𝑎𝑟−1 + 12𝑎𝑟−2 + 8𝑎𝑟−3 = 0 …….(1)
Consider the characteristic equation as
𝑥 3 + 6𝑥 2 + 12𝑥 + 8 = 0 …….(2)
Since, the roots of equation (2) are 𝑥 = −2, −2, −2.
Thus the general solution of equation (1) is
𝑎𝑟 = (𝐴1 𝑟 2 + 𝐴2 𝑟 + 𝐴3 )(−2)𝑟
where 𝐴1 𝐴2 & 𝐴3 are constants
Since 0 = 𝑎0 = 𝐴3 & 0 = 𝑎1 = (𝐴1 +𝐴2 )(−2)1 ,
2 = 𝑎2 = (4𝐴1 +2𝐴2 )(−2)2
1 −1
we have 𝐴1 = , 𝐴2 = & 𝐴3 = 0
4 4
1 2 1 𝑟 −2 𝑟
hence 𝑎𝑟 = 𝑟 − 𝑟+0 (𝑟 2 − 𝑟),
(−2) = anaghakhiste@iiitp.ac.in ∀𝑟 ≥ 0.
Discrete Structure
_____________________________

3. Method of Characteristic Roots:


Ex.4. Suppose that the roots of the characteristic equation of a
linear homogeneous recurrence relation are 2, 2, 2, 5, 5,
and 9. What is the form of the general solution?
Solution: The general form of the solution is
𝐴1 𝑟 2 + 𝐴2 𝑟 + 𝐴3 2𝑟 + 𝐴4 𝑟 + 𝐴5 5𝑟 + 𝐴6 9𝑟

anaghakhiste@iiitp.ac.in
Discrete Structure
_____________________________
Non-Homogenous Linear recurrence relation:
Consider the non-homogenous linear recurrence relation
𝑐0 𝑎𝑟 + 𝑐1 𝑎𝑟−1 + ⋯ + 𝑐𝑘 𝑎𝑟−𝑘 = 𝑓(𝑟) …….(1)
where 𝑓 𝑟 ≠ 0.
Now, consider the associated homo. linear recurrence relation
𝑐0 𝑎𝑟 + 𝑐1 𝑎𝑟−1 + ⋯ + 𝑐𝑘 𝑎𝑟−𝑘 = 0 …….(2)
(ℎ)
with its general solution 𝑎𝑟 [i.e., the general solution of eqn (2)].
(𝑝)
Then find the particular solution 𝑎𝑟 of eqn (1), [i.e., a solution of
which satisfies the eqn (1)].
Thus the general solution of equation (1) is
(ℎ) (𝑝)
𝑎𝑟 = 𝑎𝑟 + 𝑎𝑟

anaghakhiste@iiitp.ac.in
Discrete Structure
_____________________________
There is no general procedure for determining particular solution
of equation (1). It depends upon the nature of 𝑓 𝑟 .
𝑓 𝑟 (𝑝)
𝑎𝑟

1 Constant no. = d0 Constant = 𝑃


2 d0 + 𝑑1 𝑟 + ⋯ + 𝑑𝑛 𝑟 𝑛 P0 + 𝑃1 𝑟 + ⋯ + 𝑃𝑛 𝑟 𝑛
3 d0 𝑏𝑟 , where b is not characteristic 𝑃𝑏𝑟
root of eqn (2)
4 (d0 +𝑑1 𝑟 + ⋯ + 𝑑𝑛 𝑟 𝑛 )𝑏𝑟 , where b P0 + 𝑃1 𝑟 + ⋯ + 𝑃𝑛 𝑟 𝑛 𝑏𝑟
is not characteristic root of eqn (2)
5 d0 𝑏𝑟 , where b a characteristic root 𝑃𝑟 𝑚 𝑏𝑟
of eqn (2) with multiplicity 𝑚
6 (d0 +𝑑1 𝑟 + ⋯ + 𝑑𝑛 𝑟 𝑛 )𝑏𝑟 , where b P0 + 𝑃1 𝑟 + ⋯ + 𝑃𝑛 𝑟 𝑛 𝑟 𝑚 𝑏𝑟
is a characteristic root of eqn (2)
with multiplicity 𝑚
anaghakhiste@iiitp.ac.in
Discrete Structure
_____________________________
For example:
1. Solve 𝑎𝑟 − 𝑎𝑟−1 − 6𝑎𝑟−2 = −30 with 𝑎0 = 20 & 𝑎1 =5 .
Solution: Given recurrence relation is
𝑎𝑟 − 𝑎𝑟−1 − 6𝑎𝑟−2 = −30 ……(1)
Consider associated homogeneous recurrence relation
𝑎𝑟 − 𝑎𝑟−1 − 6𝑎𝑟−2 = 0 …….(2)
having general solution is
(ℎ)
𝑎𝑟 = 𝐴1 −2 𝑟 + 𝐴2 3 𝑟
where 𝐴1 & 𝐴2 are constants.
Now, to find particular solution of equation (1):
(𝑝)
Since f r = −30, let 𝑎𝑟 = 𝑃 = constant, ∀𝑟
Thus equation (1) gives, P − 𝑃 − 6𝑃 = −30, hence 𝑃 = 5.
(𝑝)
∴ 𝑎𝑟 = 5, ∀𝑟

anaghakhiste@iiitp.ac.in
Discrete Structure
_____________________________
Hence general solution of equation (1) is
(ℎ) (𝑝)
𝑎𝑟 = 𝑎𝑟 + 𝑎 𝑟
= 𝐴1 −2 𝑟 + 𝐴2 3 𝑟 + 5
Since 20 = 𝑎0 = 𝐴1 + 𝐴2 + 5
& 5 = 𝑎1 = 𝐴1 −2 + 𝐴2 3 + 5,
we have 𝐴1 = 9 & 𝐴2 = 6
and hence 𝑎𝑟 = 9 −2 𝑟 + 6 3 𝑟 + 5, ∀𝑟 ≥ 0.

anaghakhiste@iiitp.ac.in
Discrete Structure
_____________________________
For example:
2. Solve 𝑎𝑟 − 7𝑎𝑟−1 + 10𝑎𝑟−2 = 6 + 8𝑟 with 𝑎0 = 1 & 𝑎1 = 2.
Solution: Given recurrence relation is
𝑎𝑟 − 7𝑎𝑟−1 + 10𝑎𝑟−2 = 6 + 8𝑟 ……(1)
Consider associated homogeneous recurrence relation
𝑎𝑟 − 7𝑎𝑟−1 + 10𝑎𝑟−2 = 0 …….(2)
having general solution is
(ℎ)
𝑎𝑟 = 𝐴1 2 𝑟 + 𝐴2 5 𝑟
where 𝐴1 & 𝐴2 are constants.
Now, to find particular solution of equation (1):
(𝑝)
Since f r = 6 + 8𝑟, let 𝑎𝑟 = 𝑃0 + 𝑃1 𝑟 , ∀𝑟
Thus equation (1) gives, P0 =8 and P1 = 2
(𝑝)
∴ 𝑎𝑟 = 8+2r, ∀𝑟

anaghakhiste@iiitp.ac.in
Discrete Structure
_____________________________
Hence general solution of equation (1) is
(ℎ) (𝑝)
𝑎𝑟 = 𝑎𝑟 + 𝑎 𝑟
= 𝐴1 2 𝑟 + 𝐴2 5 𝑟 + 8 + 2𝑟
Since 1 = 𝑎0 = 𝐴1 + 𝐴2 + 8
& 2 = 𝑎1 = 𝐴1 2 + 𝐴2 5 + 10,
we have 𝐴1 = −9 & 𝐴2 = 2
and hence 𝑎𝑟 = −9 2 𝑟 + 2 5 𝑟 + 8 + 2𝑟, ∀𝑟 ≥ 0.

anaghakhiste@iiitp.ac.in
Discrete Structure
_____________________________
3. Solve 𝑎𝑟 + 𝑎𝑟−1 = 3𝑟2𝑟 .
Solution: Given recurrence relation is
𝑎𝑟 + 𝑎𝑟−1 = 3𝑟2𝑟 ……(1)
Consider associated homogeneous recurrence relation
𝑎𝑟 + 𝑎𝑟−1 = 0 …….(2)
having general solution is
(ℎ)
𝑎𝑟 = 𝐴1 −1 𝑟
where 𝐴1 is a constant.
Now, to find particular solution of equation (1):
Since f r = 3𝑟2𝑟 , [where 𝑏 = 2 is not a root of characteristic
equation of equation (2) ],
(𝑝)
let 𝑎𝑟 = 𝑃0 + 𝑃1 𝑟 2𝑟 , ∀𝑟
2
Thus equation (1) gives, 𝑃0 = & 𝑃1 = 2 .
3
(𝑝) 2 𝑟 , ∀𝑟
∴ 𝑎𝑟 = + 2𝑟 2anaghakhiste@iiitp.ac.in
Discrete Structure
_____________________________
Hence general solution of equation (1) is
(ℎ) (𝑝)
𝑎𝑟 = 𝑎𝑟 + 𝑎 𝑟
𝑟 2
= 𝐴1 −1 + + 2𝑟 2𝑟 , ∀𝑟 ≥ 0.
3

anaghakhiste@iiitp.ac.in
Discrete Structure
_____________________________
4. Solve 𝑎𝑟 − 4𝑎𝑟−1 + 4𝑎𝑟−2 = (𝑟 + 1)2𝑟 .
Solution: Given recurrence relation is
𝑎𝑟 − 4𝑎𝑟−1 + 4𝑎𝑟−2 = (𝑟 + 1)2𝑟 .……(1)
Consider associated homogeneous recurrence relation
𝑎𝑟 − 4𝑎𝑟−1 + 4𝑎𝑟−2 = 0 …….(2)
having general solution is
(ℎ)
𝑎𝑟 = (𝐴1 +𝐴2 𝑟)2𝑟
where 𝐴1 and 𝐴1 are constants.
Now, to find particular solution of equation (1):
Since f r = (𝑟 + 1)2𝑟 , [where 𝑏 = 2 is a root of characteristic
equation of equation (2) with multiplicity 2],
(𝑝)
let 𝑎𝑟 = 𝑃0 + 𝑃1 𝑟 𝑟 2 2𝑟 , ∀𝑟
2
Thus equation (1) gives, 𝑃0 = & 𝑃1 = 2 . (verify this values.)
3
(𝑝) 2 𝑟 , ∀𝑟
∴ 𝑎𝑟 = + 2𝑟 2anaghakhiste@iiitp.ac.in
Discrete Structure
_____________________________
Hence general solution of equation (1) is
(ℎ) (𝑝)
𝑎𝑟 = 𝑎𝑟 + 𝑎 𝑟
𝑟 2
= 𝐴1 −1 + + 2𝑟 2𝑟 , ∀𝑟 ≥ 0.
3

anaghakhiste@iiitp.ac.in

You might also like