SlideShare a Scribd company logo
7
Most read
17
Most read
18
Most read
Welcome
to
My presentation
Find Transitive Closure Using Warshall’s Algorithm
Md. Safayet Hossain
M.Sc student of CSE department , KUET.
1. It is transitive
2. It contains R
3. Minimal relation satisfies (1) & (2)
RT = R ∪ { (a, c) | (a, b) ∈ R ,(b, c) ∈ R }
Example:
A = { 1, 2, 3}
R ={ (1, 2), (2, 3) }
RT = { (1, 2), (2, 3) , (1, 3)}
Transitive closure
1 2
3
1 2
3
Input: Input the given graph as adjacency matrix
Output: Transitive Closure matrix.
Begin
copy the adjacency matrix into another matrix named T
for any vertex k in the graph, do
for each vertex i in the graph, do
for each vertex j in the graph, do
T [ i, j] = T [i, j] OR (T [ i, k]) AND T [ k, j])
done
done
done
Display the T
End
Algorithm to find transitive closure using Warshall’s algorithm
0 1
23
0 1 1 0
0 0 1 0
0 0 0 1
0 0 0 0
T =
MAdj =
0 1 1 0
0 0 1 0
0 0 0 1
0 0 0 0
0 1 2 3
0
1
2
3
copy
0 1 1 0
0 0 1 0
0 0 0 1
0 0 0 0
T =
for (k = 0; k < V; k++) {
for (i = 0; i < V; i++) {
for (j = 0; j < V; j++) {
//T[i][j] = T[i][j] || ( T[i][k] && T[k][j] );
T[0][0] = T[0][0] || ( T[0][0] && T[0][0] );
}
}
}
0
k =0
i =0
j = 0
T =
Transitive matrix when k = 0
0 1 1 0
0 0 1 0
0 0 0 1
0 0 0 0
T =
for (k = 0; k < V; k++) {
for (i = 0; i < V; i++) {
for (j = 0; j < V; j++) {
//T[i][j] = T[i][j] || (T[i][k] && T[k][j]);
T[0][1] = T[0][1] || (T[0][0] && T[0][1]);
}
}
}
0 1
k =0
i =0
j = 1
T =
Transitive matrix when k = 0
0 1 1 0
0 0 1 0
0 0 0 1
0 0 0 0
T =
for (k = 0; k < V; k++) {
for (i = 0; i < V; i++) {
for (j = 0; j < V; j++) {
//T[i][j] = T[i][j] || (T[i][k] && T[k][j]);
T[0][2] = T[0][2] || (T[0][0] && T[0][2]);
}
}
}
0 1 1
k =0
i =0
j = 2
T =
Transitive matrix when k = 0
0 1 1 0
0 0 1 0
0 0 0 1
0 0 0 0
T =
for (k = 0; k < V; k++) {
for (i = 0; i < V; i++) {
for (j = 0; j < V; j++) {
//T[i][j] = T[i][j] || (T[i][k] && T[k][j]);
T[0][3] = T[0][3] || (T[0][0] && T[0][3]);
}
}
}
0 1 1 0
k =0
i =0
j = 3
T =
Transitive matrix when k = 0
0 1 1 0
0 0 1 0
0 0 0 1
0 0 0 0
T =
for (k = 0; k < V; k++) {
for (i = 0; i < V; i++) {
for (j = 0; j < V; j++) {
//T[i][j] = T[i][j] || (T[i][k] && T[k][j]);
T[3][3] = T[3][3] || (T[3][0] && T[0][3]);
}
}
}
0 1 1 0
0 0 1 0
0 0 0 1
0 0 0 0
k =0
i =3
j = 3
T =
Transitive matrix when k = 0
0 1 1 0
0 0 1 0
0 0 0 1
0 0 0 0
T =
for (k = 0; k < V; k++) {
for (i = 0; i < V; i++) {
for (j = 0; j < V; j++) {
//T[i][j] = T[i][j] || (T[i][k] && T[k][j]);
T[3][3] = T[3][3] || (T[3][0] && T[0][3]);
}
}
}
0 1 1 0
0 0 1 0
0 0 0 1
0 0 0 0
k =1
i =3
j = 3
T =
Transitive matrix when k = 1
0 1 1 0
0 0 1 0
0 0 0 1
0 0 0 0
T =
for (k = 0; k < V; k++) {
for (i = 0; i < V; i++) {
for (j = 0; j < V; j++) {
//T[i][j] = T[i][j] || (T[i][k] && T[k][j]);
T[0][3] = T[0][3] || (T[0][2] && T[2][3]);
}
}
}
0 1 1 1
0 0 1 0
0 0 0 1
0 0 0 0
k =2
i =0
j = 3
T =
Transitive matrix when k = 2
0 1 1 0
0 0 1 0
0 0 0 1
0 0 0 0
T =
for (k = 0; k < V; k++) {
for (i = 0; i < V; i++) {
for (j = 0; j < V; j++) {
//T[i][j] = T[i][j] || (T[i][k] && T[k][j]);
T[1][3] = T[1][3] || (T[1][2] && T[2][3]);
}
}
}
0 1 1 1
0 0 1 1
0 0 0 1
0 0 0 0
k =2
i =1
j = 3
T =
Transitive matrix when k = 2
0 1 1 0
0 0 1 0
0 0 0 1
0 0 0 0
T =
for (k = 0; k < V; k++) {
for (i = 0; i < V; i++) {
for (j = 0; j < V; j++) {
//T[i][j] = T[i][j] || (T[i][k] && T[k][j]);
T[3][3] = T[3][3] || (T[3][2] && T[2][3]);
}
}
}
0 1 1 1
0 0 1 1
0 0 0 1
0 0 0 0
k =2
i =3
j = 3
T =
Transitive matrix when k = 2
0 1 1 0
0 0 1 0
0 0 0 1
0 0 0 0
T =
for (k = 0; k < V; k++) {
for (i = 0; i < V; i++) {
for (j = 0; j < V; j++) {
//T[i][j] = T[i][j] || (T[i][k] && T[k][j]);
T[3][3] = T[3][3] || (T[3][3] && T[3][3]);
}
}
}
0 1 1 1
0 0 1 1
0 0 0 1
0 0 0 0
k =3
i =3
j = 3
T =
Transitive matrix when k = 3
0 1 1 1
0 0 1 1
0 0 0 1
0 0 0 0
T(3) =
0 1
23
Final Transitive closure of the given graph
0 1 1 1
0 0 1 1
0 0 0 1
0 0 0 0
Transitive closure matrix for k = 3
0 1 1 0
0 0 1 0
0 0 0 1
0 0 0 0
MAdj =
0 1 1 0
0 0 1 0
0 0 0 1
0 0 0 0
T =
0 1 1 0
0 0 1 0
0 0 0 1
0 0 0 0
0 1 1 0
0 0 1 0
0 0 0 1
0 0 0 0
Transitive closure matrix for k=0
Transitive closure matrix for k=1
0 1 1 1
0 0 1 1
0 0 0 1
0 0 0 0
Transitive closure matrix for k=2
0 1 1 1
0 0 1 1
0 0 0 1
0 0 0 0
Transitive closure matrix for k=3
O(n2)
O(n2)
O(n2)
O(n2)
Time complexity = n * O(n2)
= O(n3)
Space complexity = n * O(n2)
= O(n3)
T =
T =
T =
T =
Time & space Complexity
Thank You

More Related Content

PPTX
Find Transitive Closure Using Floyd-Warshall Algorithm
PDF
Linear transformations and matrices
PPT
SINGLE-SOURCE SHORTEST PATHS
PPTX
Prims and kruskal algorithms
PPTX
Differential calculus maxima minima
PPT
how to calclute time complexity of algortihm
PPT
systems of linear equations & matrices
PPTX
Introduction to Graph Theory
Find Transitive Closure Using Floyd-Warshall Algorithm
Linear transformations and matrices
SINGLE-SOURCE SHORTEST PATHS
Prims and kruskal algorithms
Differential calculus maxima minima
how to calclute time complexity of algortihm
systems of linear equations & matrices
Introduction to Graph Theory

What's hot (20)

PDF
Formal Languages and Automata Theory Unit 1
PPTX
GRAPH APPLICATION - MINIMUM SPANNING TREE (MST)
PDF
Newton's Forward/Backward Difference Interpolation
PPT
graph ASS (1).ppt
PDF
Functions in discrete mathematics
PPTX
Cohen-Sutherland Line Clipping Algorithm
PPTX
Quick sort
PPTX
Numerical solution of system of linear equations
PPTX
Separation of variables
PPTX
Backtracking
PPTX
Automata theory -Conversion of ε nfa to nfa
PPTX
All pair shortest path
PDF
Production System in AI
PPT
Divide and Conquer
PDF
Chapter 2: Relations
PPSX
Methods of solving ODE
PPTX
Multistage graph unit 4 of algorithm.ppt
PPTX
Vertex cover Problem
PPTX
NFA Non Deterministic Finite Automata by Mudasir khushik
Formal Languages and Automata Theory Unit 1
GRAPH APPLICATION - MINIMUM SPANNING TREE (MST)
Newton's Forward/Backward Difference Interpolation
graph ASS (1).ppt
Functions in discrete mathematics
Cohen-Sutherland Line Clipping Algorithm
Quick sort
Numerical solution of system of linear equations
Separation of variables
Backtracking
Automata theory -Conversion of ε nfa to nfa
All pair shortest path
Production System in AI
Divide and Conquer
Chapter 2: Relations
Methods of solving ODE
Multistage graph unit 4 of algorithm.ppt
Vertex cover Problem
NFA Non Deterministic Finite Automata by Mudasir khushik
Ad

Similar to Find Transitive closure of a Graph Using Warshall's Algorithm (20)

PPTX
Arc Length, Curvature and Torsion
PPT
Linear transformation.ppt
PPT
12.5. vector valued functions
PPT
Curvature final
PDF
Discretization
PPTX
AI .pptx
PDF
Applied III Chapter 4(1).pdf
PPT
Curvature (2)
PPT
digital control Chapter 2 slide
PDF
8 Continuous-Time Fourier Transform Solutions To Recommended Problems
PDF
research paper publication
PPTX
Proyecto parcial iii_ proyecciones lineales
PPT
1601 parametric equations-03
PDF
Wide sense stationary process in digital communication
PDF
linear transformation and rank nullity theorem
PPTX
Get Accurate and Reliable Statistics Assignment Help - Boost Your Grades!
PDF
Semi markov process
PPTX
Dynamic Programming in design and analysis .pptx
PPTX
Linear transforamtion and it,s applications.(VCLA)
PPT
Series representation of solistics lectr19.ppt
Arc Length, Curvature and Torsion
Linear transformation.ppt
12.5. vector valued functions
Curvature final
Discretization
AI .pptx
Applied III Chapter 4(1).pdf
Curvature (2)
digital control Chapter 2 slide
8 Continuous-Time Fourier Transform Solutions To Recommended Problems
research paper publication
Proyecto parcial iii_ proyecciones lineales
1601 parametric equations-03
Wide sense stationary process in digital communication
linear transformation and rank nullity theorem
Get Accurate and Reliable Statistics Assignment Help - Boost Your Grades!
Semi markov process
Dynamic Programming in design and analysis .pptx
Linear transforamtion and it,s applications.(VCLA)
Series representation of solistics lectr19.ppt
Ad

More from Safayet Hossain (13)

PPTX
Application-Aware Big Data Deduplication in Cloud Environment
PPTX
Epipolar geometry
PPTX
Color Guided Thermal image Super Resolution
PPTX
Different type of attack on computer
PPTX
Region based image segmentation
PPTX
Anti- aliasing computer graphics
PPTX
detect emotion from text
PPTX
Vector computing
PPTX
Grid computing
PPTX
Green computing
PPTX
E waste...
PPTX
Economic presentation
PPTX
Remittance Management System
Application-Aware Big Data Deduplication in Cloud Environment
Epipolar geometry
Color Guided Thermal image Super Resolution
Different type of attack on computer
Region based image segmentation
Anti- aliasing computer graphics
detect emotion from text
Vector computing
Grid computing
Green computing
E waste...
Economic presentation
Remittance Management System

Recently uploaded (20)

PPTX
Introduction and Scope of Bichemistry.pptx
PDF
Mark Klimek Lecture Notes_240423 revision books _173037.pdf
PDF
Business Ethics Teaching Materials for college
PPTX
Cell Structure & Organelles in detailed.
PDF
STATICS OF THE RIGID BODIES Hibbelers.pdf
PDF
Anesthesia in Laparoscopic Surgery in India
PDF
grade 11-chemistry_fetena_net_5883.pdf teacher guide for all student
PPTX
UNDER FIVE CLINICS OR WELL BABY CLINICS.pptx
PPTX
COMPUTERS AS DATA ANALYSIS IN PRECLINICAL DEVELOPMENT.pptx
PPTX
school management -TNTEU- B.Ed., Semester II Unit 1.pptx
PDF
Pre independence Education in Inndia.pdf
PPTX
Open Quiz Monsoon Mind Game Prelims.pptx
PPTX
Onica Farming 24rsclub profitable farm business
PPTX
human mycosis Human fungal infections are called human mycosis..pptx
PDF
Open folder Downloads.pdf yes yes ges yes
PPTX
IMMUNITY IMMUNITY refers to protection against infection, and the immune syst...
PPTX
Nursing Management of Patients with Disorders of Ear, Nose, and Throat (ENT) ...
PDF
From loneliness to social connection charting
PDF
Abdominal Access Techniques with Prof. Dr. R K Mishra
PDF
ANTIBIOTICS.pptx.pdf………………… xxxxxxxxxxxxx
Introduction and Scope of Bichemistry.pptx
Mark Klimek Lecture Notes_240423 revision books _173037.pdf
Business Ethics Teaching Materials for college
Cell Structure & Organelles in detailed.
STATICS OF THE RIGID BODIES Hibbelers.pdf
Anesthesia in Laparoscopic Surgery in India
grade 11-chemistry_fetena_net_5883.pdf teacher guide for all student
UNDER FIVE CLINICS OR WELL BABY CLINICS.pptx
COMPUTERS AS DATA ANALYSIS IN PRECLINICAL DEVELOPMENT.pptx
school management -TNTEU- B.Ed., Semester II Unit 1.pptx
Pre independence Education in Inndia.pdf
Open Quiz Monsoon Mind Game Prelims.pptx
Onica Farming 24rsclub profitable farm business
human mycosis Human fungal infections are called human mycosis..pptx
Open folder Downloads.pdf yes yes ges yes
IMMUNITY IMMUNITY refers to protection against infection, and the immune syst...
Nursing Management of Patients with Disorders of Ear, Nose, and Throat (ENT) ...
From loneliness to social connection charting
Abdominal Access Techniques with Prof. Dr. R K Mishra
ANTIBIOTICS.pptx.pdf………………… xxxxxxxxxxxxx

Find Transitive closure of a Graph Using Warshall's Algorithm

  • 2. Find Transitive Closure Using Warshall’s Algorithm Md. Safayet Hossain M.Sc student of CSE department , KUET.
  • 3. 1. It is transitive 2. It contains R 3. Minimal relation satisfies (1) & (2) RT = R ∪ { (a, c) | (a, b) ∈ R ,(b, c) ∈ R } Example: A = { 1, 2, 3} R ={ (1, 2), (2, 3) } RT = { (1, 2), (2, 3) , (1, 3)} Transitive closure 1 2 3 1 2 3
  • 4. Input: Input the given graph as adjacency matrix Output: Transitive Closure matrix. Begin copy the adjacency matrix into another matrix named T for any vertex k in the graph, do for each vertex i in the graph, do for each vertex j in the graph, do T [ i, j] = T [i, j] OR (T [ i, k]) AND T [ k, j]) done done done Display the T End Algorithm to find transitive closure using Warshall’s algorithm
  • 5. 0 1 23 0 1 1 0 0 0 1 0 0 0 0 1 0 0 0 0 T = MAdj = 0 1 1 0 0 0 1 0 0 0 0 1 0 0 0 0 0 1 2 3 0 1 2 3 copy
  • 6. 0 1 1 0 0 0 1 0 0 0 0 1 0 0 0 0 T = for (k = 0; k < V; k++) { for (i = 0; i < V; i++) { for (j = 0; j < V; j++) { //T[i][j] = T[i][j] || ( T[i][k] && T[k][j] ); T[0][0] = T[0][0] || ( T[0][0] && T[0][0] ); } } } 0 k =0 i =0 j = 0 T = Transitive matrix when k = 0
  • 7. 0 1 1 0 0 0 1 0 0 0 0 1 0 0 0 0 T = for (k = 0; k < V; k++) { for (i = 0; i < V; i++) { for (j = 0; j < V; j++) { //T[i][j] = T[i][j] || (T[i][k] && T[k][j]); T[0][1] = T[0][1] || (T[0][0] && T[0][1]); } } } 0 1 k =0 i =0 j = 1 T = Transitive matrix when k = 0
  • 8. 0 1 1 0 0 0 1 0 0 0 0 1 0 0 0 0 T = for (k = 0; k < V; k++) { for (i = 0; i < V; i++) { for (j = 0; j < V; j++) { //T[i][j] = T[i][j] || (T[i][k] && T[k][j]); T[0][2] = T[0][2] || (T[0][0] && T[0][2]); } } } 0 1 1 k =0 i =0 j = 2 T = Transitive matrix when k = 0
  • 9. 0 1 1 0 0 0 1 0 0 0 0 1 0 0 0 0 T = for (k = 0; k < V; k++) { for (i = 0; i < V; i++) { for (j = 0; j < V; j++) { //T[i][j] = T[i][j] || (T[i][k] && T[k][j]); T[0][3] = T[0][3] || (T[0][0] && T[0][3]); } } } 0 1 1 0 k =0 i =0 j = 3 T = Transitive matrix when k = 0
  • 10. 0 1 1 0 0 0 1 0 0 0 0 1 0 0 0 0 T = for (k = 0; k < V; k++) { for (i = 0; i < V; i++) { for (j = 0; j < V; j++) { //T[i][j] = T[i][j] || (T[i][k] && T[k][j]); T[3][3] = T[3][3] || (T[3][0] && T[0][3]); } } } 0 1 1 0 0 0 1 0 0 0 0 1 0 0 0 0 k =0 i =3 j = 3 T = Transitive matrix when k = 0
  • 11. 0 1 1 0 0 0 1 0 0 0 0 1 0 0 0 0 T = for (k = 0; k < V; k++) { for (i = 0; i < V; i++) { for (j = 0; j < V; j++) { //T[i][j] = T[i][j] || (T[i][k] && T[k][j]); T[3][3] = T[3][3] || (T[3][0] && T[0][3]); } } } 0 1 1 0 0 0 1 0 0 0 0 1 0 0 0 0 k =1 i =3 j = 3 T = Transitive matrix when k = 1
  • 12. 0 1 1 0 0 0 1 0 0 0 0 1 0 0 0 0 T = for (k = 0; k < V; k++) { for (i = 0; i < V; i++) { for (j = 0; j < V; j++) { //T[i][j] = T[i][j] || (T[i][k] && T[k][j]); T[0][3] = T[0][3] || (T[0][2] && T[2][3]); } } } 0 1 1 1 0 0 1 0 0 0 0 1 0 0 0 0 k =2 i =0 j = 3 T = Transitive matrix when k = 2
  • 13. 0 1 1 0 0 0 1 0 0 0 0 1 0 0 0 0 T = for (k = 0; k < V; k++) { for (i = 0; i < V; i++) { for (j = 0; j < V; j++) { //T[i][j] = T[i][j] || (T[i][k] && T[k][j]); T[1][3] = T[1][3] || (T[1][2] && T[2][3]); } } } 0 1 1 1 0 0 1 1 0 0 0 1 0 0 0 0 k =2 i =1 j = 3 T = Transitive matrix when k = 2
  • 14. 0 1 1 0 0 0 1 0 0 0 0 1 0 0 0 0 T = for (k = 0; k < V; k++) { for (i = 0; i < V; i++) { for (j = 0; j < V; j++) { //T[i][j] = T[i][j] || (T[i][k] && T[k][j]); T[3][3] = T[3][3] || (T[3][2] && T[2][3]); } } } 0 1 1 1 0 0 1 1 0 0 0 1 0 0 0 0 k =2 i =3 j = 3 T = Transitive matrix when k = 2
  • 15. 0 1 1 0 0 0 1 0 0 0 0 1 0 0 0 0 T = for (k = 0; k < V; k++) { for (i = 0; i < V; i++) { for (j = 0; j < V; j++) { //T[i][j] = T[i][j] || (T[i][k] && T[k][j]); T[3][3] = T[3][3] || (T[3][3] && T[3][3]); } } } 0 1 1 1 0 0 1 1 0 0 0 1 0 0 0 0 k =3 i =3 j = 3 T = Transitive matrix when k = 3
  • 16. 0 1 1 1 0 0 1 1 0 0 0 1 0 0 0 0 T(3) = 0 1 23 Final Transitive closure of the given graph 0 1 1 1 0 0 1 1 0 0 0 1 0 0 0 0 Transitive closure matrix for k = 3 0 1 1 0 0 0 1 0 0 0 0 1 0 0 0 0 MAdj =
  • 17. 0 1 1 0 0 0 1 0 0 0 0 1 0 0 0 0 T = 0 1 1 0 0 0 1 0 0 0 0 1 0 0 0 0 0 1 1 0 0 0 1 0 0 0 0 1 0 0 0 0 Transitive closure matrix for k=0 Transitive closure matrix for k=1 0 1 1 1 0 0 1 1 0 0 0 1 0 0 0 0 Transitive closure matrix for k=2 0 1 1 1 0 0 1 1 0 0 0 1 0 0 0 0 Transitive closure matrix for k=3 O(n2) O(n2) O(n2) O(n2) Time complexity = n * O(n2) = O(n3) Space complexity = n * O(n2) = O(n3) T = T = T = T = Time & space Complexity