SlideShare a Scribd company logo
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
Ad

More Related Content

What's hot (20)

Minimum spanning tree
Minimum spanning treeMinimum spanning tree
Minimum spanning tree
Hinal Lunagariya
 
Stressen's matrix multiplication
Stressen's matrix multiplicationStressen's matrix multiplication
Stressen's matrix multiplication
Kumar
 
Presentation on dbms(relational calculus)
Presentation on dbms(relational calculus)Presentation on dbms(relational calculus)
Presentation on dbms(relational calculus)
yourbookworldanil
 
Multi dimensional arrays
Multi dimensional arraysMulti dimensional arrays
Multi dimensional arrays
Aseelhalees
 
SINGLE-SOURCE SHORTEST PATHS
SINGLE-SOURCE SHORTEST PATHS SINGLE-SOURCE SHORTEST PATHS
SINGLE-SOURCE SHORTEST PATHS
Md. Shafiuzzaman Hira
 
Disjoint sets
Disjoint setsDisjoint sets
Disjoint sets
Core Condor
 
All pairs shortest path algorithm
All pairs shortest path algorithmAll pairs shortest path algorithm
All pairs shortest path algorithm
Srikrishnan Suresh
 
Recursion tree method
Recursion tree methodRecursion tree method
Recursion tree method
Rajendran
 
Prim's algorithm
Prim's algorithmPrim's algorithm
Prim's algorithm
Pankaj Thakur
 
Graph in data structure
Graph in data structureGraph in data structure
Graph in data structure
Abrish06
 
A presentation on prim's and kruskal's algorithm
A presentation on prim's and kruskal's algorithmA presentation on prim's and kruskal's algorithm
A presentation on prim's and kruskal's algorithm
Gaurav Kolekar
 
Graphs In Data Structure
Graphs In Data StructureGraphs In Data Structure
Graphs In Data Structure
Anuj Modi
 
Algorithms Lecture 2: Analysis of Algorithms I
Algorithms Lecture 2: Analysis of Algorithms IAlgorithms Lecture 2: Analysis of Algorithms I
Algorithms Lecture 2: Analysis of Algorithms I
Mohamed Loey
 
5.1 greedy
5.1 greedy5.1 greedy
5.1 greedy
Krish_ver2
 
01 Knapsack using Dynamic Programming
01 Knapsack using Dynamic Programming01 Knapsack using Dynamic Programming
01 Knapsack using Dynamic Programming
Fenil Shah
 
Matrix chain multiplication
Matrix chain multiplicationMatrix chain multiplication
Matrix chain multiplication
Kiran K
 
Algorithm analysis
Algorithm analysisAlgorithm analysis
Algorithm analysis
sumitbardhan
 
Asymptotic notations
Asymptotic notationsAsymptotic notations
Asymptotic notations
Nikhil Sharma
 
Unit 3 daa
Unit 3 daaUnit 3 daa
Unit 3 daa
Nv Thejaswini
 
Knapsack problem
Knapsack problemKnapsack problem
Knapsack problem
Vikas Sharma
 
Stressen's matrix multiplication
Stressen's matrix multiplicationStressen's matrix multiplication
Stressen's matrix multiplication
Kumar
 
Presentation on dbms(relational calculus)
Presentation on dbms(relational calculus)Presentation on dbms(relational calculus)
Presentation on dbms(relational calculus)
yourbookworldanil
 
Multi dimensional arrays
Multi dimensional arraysMulti dimensional arrays
Multi dimensional arrays
Aseelhalees
 
All pairs shortest path algorithm
All pairs shortest path algorithmAll pairs shortest path algorithm
All pairs shortest path algorithm
Srikrishnan Suresh
 
Recursion tree method
Recursion tree methodRecursion tree method
Recursion tree method
Rajendran
 
Graph in data structure
Graph in data structureGraph in data structure
Graph in data structure
Abrish06
 
A presentation on prim's and kruskal's algorithm
A presentation on prim's and kruskal's algorithmA presentation on prim's and kruskal's algorithm
A presentation on prim's and kruskal's algorithm
Gaurav Kolekar
 
Graphs In Data Structure
Graphs In Data StructureGraphs In Data Structure
Graphs In Data Structure
Anuj Modi
 
Algorithms Lecture 2: Analysis of Algorithms I
Algorithms Lecture 2: Analysis of Algorithms IAlgorithms Lecture 2: Analysis of Algorithms I
Algorithms Lecture 2: Analysis of Algorithms I
Mohamed Loey
 
01 Knapsack using Dynamic Programming
01 Knapsack using Dynamic Programming01 Knapsack using Dynamic Programming
01 Knapsack using Dynamic Programming
Fenil Shah
 
Matrix chain multiplication
Matrix chain multiplicationMatrix chain multiplication
Matrix chain multiplication
Kiran K
 
Algorithm analysis
Algorithm analysisAlgorithm analysis
Algorithm analysis
sumitbardhan
 
Asymptotic notations
Asymptotic notationsAsymptotic notations
Asymptotic notations
Nikhil Sharma
 

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

Arc Length, Curvature and Torsion
Arc Length, Curvature and TorsionArc Length, Curvature and Torsion
Arc Length, Curvature and Torsion
vaani pathak
 
Linear transformation.ppt
Linear transformation.pptLinear transformation.ppt
Linear transformation.ppt
Raj Parekh
 
12.5. vector valued functions
12.5. vector valued functions12.5. vector valued functions
12.5. vector valued functions
math267
 
Curvature final
Curvature finalCurvature final
Curvature final
vicky123xyz
 
Discretization
DiscretizationDiscretization
Discretization
NARESH MEENA
 
AI .pptx
AI .pptxAI .pptx
AI .pptx
alex194654
 
Applied III Chapter 4(1).pdf
Applied III  Chapter 4(1).pdfApplied III  Chapter 4(1).pdf
Applied III Chapter 4(1).pdf
DawitThomas
 
Curvature (2)
Curvature (2)Curvature (2)
Curvature (2)
vicky123xyz
 
digital control Chapter 2 slide
digital control Chapter 2 slidedigital control Chapter 2 slide
digital control Chapter 2 slide
asyrafjpk
 
8 Continuous-Time Fourier Transform Solutions To Recommended Problems
8 Continuous-Time Fourier Transform Solutions To Recommended Problems8 Continuous-Time Fourier Transform Solutions To Recommended Problems
8 Continuous-Time Fourier Transform Solutions To Recommended Problems
Sara Alvarez
 
research paper publication
research paper publicationresearch paper publication
research paper publication
samuu45sam
 
Proyecto parcial iii_ proyecciones lineales
Proyecto parcial iii_ proyecciones linealesProyecto parcial iii_ proyecciones lineales
Proyecto parcial iii_ proyecciones lineales
JOSUESANTIAGOPILLAJO
 
1601 parametric equations-03
1601 parametric equations-031601 parametric equations-03
1601 parametric equations-03
Dr Fereidoun Dejahang
 
Wide sense stationary process in digital communication
Wide sense stationary process in digital communicationWide sense stationary process in digital communication
Wide sense stationary process in digital communication
VitthalGavhane1
 
linear transformation and rank nullity theorem
linear transformation and rank nullity theorem linear transformation and rank nullity theorem
linear transformation and rank nullity theorem
Manthan Chavda
 
Get Accurate and Reliable Statistics Assignment Help - Boost Your Grades!
Get Accurate and Reliable Statistics Assignment Help - Boost Your Grades!Get Accurate and Reliable Statistics Assignment Help - Boost Your Grades!
Get Accurate and Reliable Statistics Assignment Help - Boost Your Grades!
Statistics Assignment Help
 
Semi markov process
Semi markov processSemi markov process
Semi markov process
Angélica Alebrant Mendes
 
Dynamic Programming in design and analysis .pptx
Dynamic Programming in design and analysis .pptxDynamic Programming in design and analysis .pptx
Dynamic Programming in design and analysis .pptx
dimpuk1
 
Linear transforamtion and it,s applications.(VCLA)
Linear transforamtion and it,s applications.(VCLA)Linear transforamtion and it,s applications.(VCLA)
Linear transforamtion and it,s applications.(VCLA)
DeepRaval7
 
Series representation of solistics lectr19.ppt
Series representation of solistics lectr19.pptSeries representation of solistics lectr19.ppt
Series representation of solistics lectr19.ppt
sadafshahbaz7777
 
Arc Length, Curvature and Torsion
Arc Length, Curvature and TorsionArc Length, Curvature and Torsion
Arc Length, Curvature and Torsion
vaani pathak
 
Linear transformation.ppt
Linear transformation.pptLinear transformation.ppt
Linear transformation.ppt
Raj Parekh
 
12.5. vector valued functions
12.5. vector valued functions12.5. vector valued functions
12.5. vector valued functions
math267
 
Applied III Chapter 4(1).pdf
Applied III  Chapter 4(1).pdfApplied III  Chapter 4(1).pdf
Applied III Chapter 4(1).pdf
DawitThomas
 
digital control Chapter 2 slide
digital control Chapter 2 slidedigital control Chapter 2 slide
digital control Chapter 2 slide
asyrafjpk
 
8 Continuous-Time Fourier Transform Solutions To Recommended Problems
8 Continuous-Time Fourier Transform Solutions To Recommended Problems8 Continuous-Time Fourier Transform Solutions To Recommended Problems
8 Continuous-Time Fourier Transform Solutions To Recommended Problems
Sara Alvarez
 
research paper publication
research paper publicationresearch paper publication
research paper publication
samuu45sam
 
Proyecto parcial iii_ proyecciones lineales
Proyecto parcial iii_ proyecciones linealesProyecto parcial iii_ proyecciones lineales
Proyecto parcial iii_ proyecciones lineales
JOSUESANTIAGOPILLAJO
 
Wide sense stationary process in digital communication
Wide sense stationary process in digital communicationWide sense stationary process in digital communication
Wide sense stationary process in digital communication
VitthalGavhane1
 
linear transformation and rank nullity theorem
linear transformation and rank nullity theorem linear transformation and rank nullity theorem
linear transformation and rank nullity theorem
Manthan Chavda
 
Get Accurate and Reliable Statistics Assignment Help - Boost Your Grades!
Get Accurate and Reliable Statistics Assignment Help - Boost Your Grades!Get Accurate and Reliable Statistics Assignment Help - Boost Your Grades!
Get Accurate and Reliable Statistics Assignment Help - Boost Your Grades!
Statistics Assignment Help
 
Dynamic Programming in design and analysis .pptx
Dynamic Programming in design and analysis .pptxDynamic Programming in design and analysis .pptx
Dynamic Programming in design and analysis .pptx
dimpuk1
 
Linear transforamtion and it,s applications.(VCLA)
Linear transforamtion and it,s applications.(VCLA)Linear transforamtion and it,s applications.(VCLA)
Linear transforamtion and it,s applications.(VCLA)
DeepRaval7
 
Series representation of solistics lectr19.ppt
Series representation of solistics lectr19.pptSeries representation of solistics lectr19.ppt
Series representation of solistics lectr19.ppt
sadafshahbaz7777
 
Ad

More from Safayet Hossain (13)

Application-Aware Big Data Deduplication in Cloud Environment
Application-Aware Big Data Deduplication in Cloud EnvironmentApplication-Aware Big Data Deduplication in Cloud Environment
Application-Aware Big Data Deduplication in Cloud Environment
Safayet Hossain
 
Epipolar geometry
Epipolar geometryEpipolar geometry
Epipolar geometry
Safayet Hossain
 
Color Guided Thermal image Super Resolution
Color Guided Thermal image Super ResolutionColor Guided Thermal image Super Resolution
Color Guided Thermal image Super Resolution
Safayet Hossain
 
Different type of attack on computer
Different type of attack on computerDifferent type of attack on computer
Different type of attack on computer
Safayet Hossain
 
Region based image segmentation
Region based image segmentationRegion based image segmentation
Region based image segmentation
Safayet Hossain
 
Anti- aliasing computer graphics
Anti- aliasing computer graphicsAnti- aliasing computer graphics
Anti- aliasing computer graphics
Safayet Hossain
 
detect emotion from text
detect emotion from textdetect emotion from text
detect emotion from text
Safayet Hossain
 
Vector computing
Vector computingVector computing
Vector computing
Safayet Hossain
 
Grid computing
Grid computing Grid computing
Grid computing
Safayet Hossain
 
Green computing
Green computing Green computing
Green computing
Safayet Hossain
 
E waste...
E   waste...E   waste...
E waste...
Safayet Hossain
 
Economic presentation
Economic presentationEconomic presentation
Economic presentation
Safayet Hossain
 
Remittance Management System
Remittance Management System Remittance Management System
Remittance Management System
Safayet Hossain
 
Application-Aware Big Data Deduplication in Cloud Environment
Application-Aware Big Data Deduplication in Cloud EnvironmentApplication-Aware Big Data Deduplication in Cloud Environment
Application-Aware Big Data Deduplication in Cloud Environment
Safayet Hossain
 
Color Guided Thermal image Super Resolution
Color Guided Thermal image Super ResolutionColor Guided Thermal image Super Resolution
Color Guided Thermal image Super Resolution
Safayet Hossain
 
Different type of attack on computer
Different type of attack on computerDifferent type of attack on computer
Different type of attack on computer
Safayet Hossain
 
Region based image segmentation
Region based image segmentationRegion based image segmentation
Region based image segmentation
Safayet Hossain
 
Anti- aliasing computer graphics
Anti- aliasing computer graphicsAnti- aliasing computer graphics
Anti- aliasing computer graphics
Safayet Hossain
 
detect emotion from text
detect emotion from textdetect emotion from text
detect emotion from text
Safayet Hossain
 
Remittance Management System
Remittance Management System Remittance Management System
Remittance Management System
Safayet Hossain
 
Ad

Recently uploaded (20)

Mental Health Assessment in 5th semester bsc. nursing and also used in 2nd ye...
Mental Health Assessment in 5th semester bsc. nursing and also used in 2nd ye...Mental Health Assessment in 5th semester bsc. nursing and also used in 2nd ye...
Mental Health Assessment in 5th semester bsc. nursing and also used in 2nd ye...
parmarjuli1412
 
puzzle Irregular Verbs- Simple Past Tense
puzzle Irregular Verbs- Simple Past Tensepuzzle Irregular Verbs- Simple Past Tense
puzzle Irregular Verbs- Simple Past Tense
OlgaLeonorTorresSnch
 
Redesigning Education as a Cognitive Ecosystem: Practical Insights into Emerg...
Redesigning Education as a Cognitive Ecosystem: Practical Insights into Emerg...Redesigning Education as a Cognitive Ecosystem: Practical Insights into Emerg...
Redesigning Education as a Cognitive Ecosystem: Practical Insights into Emerg...
Leonel Morgado
 
spinal cord disorders (Myelopathies and radiculoapthies)
spinal cord disorders (Myelopathies and radiculoapthies)spinal cord disorders (Myelopathies and radiculoapthies)
spinal cord disorders (Myelopathies and radiculoapthies)
Mohamed Rizk Khodair
 
How To Maximize Sales Performance using Odoo 18 Diverse views in sales module
How To Maximize Sales Performance using Odoo 18 Diverse views in sales moduleHow To Maximize Sales Performance using Odoo 18 Diverse views in sales module
How To Maximize Sales Performance using Odoo 18 Diverse views in sales module
Celine George
 
LDMMIA Reiki Yoga S5 Daily Living Workshop
LDMMIA Reiki Yoga S5 Daily Living WorkshopLDMMIA Reiki Yoga S5 Daily Living Workshop
LDMMIA Reiki Yoga S5 Daily Living Workshop
LDM Mia eStudios
 
Drugs in Anaesthesia and Intensive Care,.pdf
Drugs in Anaesthesia and Intensive Care,.pdfDrugs in Anaesthesia and Intensive Care,.pdf
Drugs in Anaesthesia and Intensive Care,.pdf
crewot855
 
antiquity of writing in ancient India- literary & archaeological evidence
antiquity of writing in ancient India- literary & archaeological evidenceantiquity of writing in ancient India- literary & archaeological evidence
antiquity of writing in ancient India- literary & archaeological evidence
PrachiSontakke5
 
Classification of mental disorder in 5th semester bsc. nursing and also used ...
Classification of mental disorder in 5th semester bsc. nursing and also used ...Classification of mental disorder in 5th semester bsc. nursing and also used ...
Classification of mental disorder in 5th semester bsc. nursing and also used ...
parmarjuli1412
 
UPMVLE migration to ARAL. A step- by- step guide
UPMVLE migration to ARAL. A step- by- step guideUPMVLE migration to ARAL. A step- by- step guide
UPMVLE migration to ARAL. A step- by- step guide
abmerca
 
TERMINOLOGIES,GRIEF PROCESS AND LOSS AMD ITS TYPES .pptx
TERMINOLOGIES,GRIEF PROCESS AND LOSS AMD ITS TYPES .pptxTERMINOLOGIES,GRIEF PROCESS AND LOSS AMD ITS TYPES .pptx
TERMINOLOGIES,GRIEF PROCESS AND LOSS AMD ITS TYPES .pptx
PoojaSen20
 
Botany Assignment Help Guide - Academic Excellence
Botany Assignment Help Guide - Academic ExcellenceBotany Assignment Help Guide - Academic Excellence
Botany Assignment Help Guide - Academic Excellence
online college homework help
 
How to Share Accounts Between Companies in Odoo 18
How to Share Accounts Between Companies in Odoo 18How to Share Accounts Between Companies in Odoo 18
How to Share Accounts Between Companies in Odoo 18
Celine George
 
Transform tomorrow: Master benefits analysis with Gen AI today webinar, 30 A...
Transform tomorrow: Master benefits analysis with Gen AI today webinar,  30 A...Transform tomorrow: Master benefits analysis with Gen AI today webinar,  30 A...
Transform tomorrow: Master benefits analysis with Gen AI today webinar, 30 A...
Association for Project Management
 
Overview Well-Being and Creative Careers
Overview Well-Being and Creative CareersOverview Well-Being and Creative Careers
Overview Well-Being and Creative Careers
University of Amsterdam
 
Module 1: Foundations of Research
Module 1: Foundations of ResearchModule 1: Foundations of Research
Module 1: Foundations of Research
drroxannekemp
 
Pope Leo XIV, the first Pope from North America.pptx
Pope Leo XIV, the first Pope from North America.pptxPope Leo XIV, the first Pope from North America.pptx
Pope Leo XIV, the first Pope from North America.pptx
Martin M Flynn
 
Cultivation Practice of Garlic in Nepal.pptx
Cultivation Practice of Garlic in Nepal.pptxCultivation Practice of Garlic in Nepal.pptx
Cultivation Practice of Garlic in Nepal.pptx
UmeshTimilsina1
 
What is the Philosophy of Statistics? (and how I was drawn to it)
What is the Philosophy of Statistics? (and how I was drawn to it)What is the Philosophy of Statistics? (and how I was drawn to it)
What is the Philosophy of Statistics? (and how I was drawn to it)
jemille6
 
Mental Health Assessment in 5th semester bsc. nursing and also used in 2nd ye...
Mental Health Assessment in 5th semester bsc. nursing and also used in 2nd ye...Mental Health Assessment in 5th semester bsc. nursing and also used in 2nd ye...
Mental Health Assessment in 5th semester bsc. nursing and also used in 2nd ye...
parmarjuli1412
 
puzzle Irregular Verbs- Simple Past Tense
puzzle Irregular Verbs- Simple Past Tensepuzzle Irregular Verbs- Simple Past Tense
puzzle Irregular Verbs- Simple Past Tense
OlgaLeonorTorresSnch
 
Redesigning Education as a Cognitive Ecosystem: Practical Insights into Emerg...
Redesigning Education as a Cognitive Ecosystem: Practical Insights into Emerg...Redesigning Education as a Cognitive Ecosystem: Practical Insights into Emerg...
Redesigning Education as a Cognitive Ecosystem: Practical Insights into Emerg...
Leonel Morgado
 
spinal cord disorders (Myelopathies and radiculoapthies)
spinal cord disorders (Myelopathies and radiculoapthies)spinal cord disorders (Myelopathies and radiculoapthies)
spinal cord disorders (Myelopathies and radiculoapthies)
Mohamed Rizk Khodair
 
How To Maximize Sales Performance using Odoo 18 Diverse views in sales module
How To Maximize Sales Performance using Odoo 18 Diverse views in sales moduleHow To Maximize Sales Performance using Odoo 18 Diverse views in sales module
How To Maximize Sales Performance using Odoo 18 Diverse views in sales module
Celine George
 
LDMMIA Reiki Yoga S5 Daily Living Workshop
LDMMIA Reiki Yoga S5 Daily Living WorkshopLDMMIA Reiki Yoga S5 Daily Living Workshop
LDMMIA Reiki Yoga S5 Daily Living Workshop
LDM Mia eStudios
 
Drugs in Anaesthesia and Intensive Care,.pdf
Drugs in Anaesthesia and Intensive Care,.pdfDrugs in Anaesthesia and Intensive Care,.pdf
Drugs in Anaesthesia and Intensive Care,.pdf
crewot855
 
antiquity of writing in ancient India- literary & archaeological evidence
antiquity of writing in ancient India- literary & archaeological evidenceantiquity of writing in ancient India- literary & archaeological evidence
antiquity of writing in ancient India- literary & archaeological evidence
PrachiSontakke5
 
Classification of mental disorder in 5th semester bsc. nursing and also used ...
Classification of mental disorder in 5th semester bsc. nursing and also used ...Classification of mental disorder in 5th semester bsc. nursing and also used ...
Classification of mental disorder in 5th semester bsc. nursing and also used ...
parmarjuli1412
 
UPMVLE migration to ARAL. A step- by- step guide
UPMVLE migration to ARAL. A step- by- step guideUPMVLE migration to ARAL. A step- by- step guide
UPMVLE migration to ARAL. A step- by- step guide
abmerca
 
TERMINOLOGIES,GRIEF PROCESS AND LOSS AMD ITS TYPES .pptx
TERMINOLOGIES,GRIEF PROCESS AND LOSS AMD ITS TYPES .pptxTERMINOLOGIES,GRIEF PROCESS AND LOSS AMD ITS TYPES .pptx
TERMINOLOGIES,GRIEF PROCESS AND LOSS AMD ITS TYPES .pptx
PoojaSen20
 
Botany Assignment Help Guide - Academic Excellence
Botany Assignment Help Guide - Academic ExcellenceBotany Assignment Help Guide - Academic Excellence
Botany Assignment Help Guide - Academic Excellence
online college homework help
 
How to Share Accounts Between Companies in Odoo 18
How to Share Accounts Between Companies in Odoo 18How to Share Accounts Between Companies in Odoo 18
How to Share Accounts Between Companies in Odoo 18
Celine George
 
Transform tomorrow: Master benefits analysis with Gen AI today webinar, 30 A...
Transform tomorrow: Master benefits analysis with Gen AI today webinar,  30 A...Transform tomorrow: Master benefits analysis with Gen AI today webinar,  30 A...
Transform tomorrow: Master benefits analysis with Gen AI today webinar, 30 A...
Association for Project Management
 
Overview Well-Being and Creative Careers
Overview Well-Being and Creative CareersOverview Well-Being and Creative Careers
Overview Well-Being and Creative Careers
University of Amsterdam
 
Module 1: Foundations of Research
Module 1: Foundations of ResearchModule 1: Foundations of Research
Module 1: Foundations of Research
drroxannekemp
 
Pope Leo XIV, the first Pope from North America.pptx
Pope Leo XIV, the first Pope from North America.pptxPope Leo XIV, the first Pope from North America.pptx
Pope Leo XIV, the first Pope from North America.pptx
Martin M Flynn
 
Cultivation Practice of Garlic in Nepal.pptx
Cultivation Practice of Garlic in Nepal.pptxCultivation Practice of Garlic in Nepal.pptx
Cultivation Practice of Garlic in Nepal.pptx
UmeshTimilsina1
 
What is the Philosophy of Statistics? (and how I was drawn to it)
What is the Philosophy of Statistics? (and how I was drawn to it)What is the Philosophy of Statistics? (and how I was drawn to it)
What is the Philosophy of Statistics? (and how I was drawn to it)
jemille6
 

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
  翻译: