SlideShare a Scribd company logo
Name: Md Mamun Hasan
Roll: 1907555 (KUET)
Course: CSE 6101
Find Transitive Closure using
Warshall’s Algorithm
Transitive Closure
• Given a digraph G, the transitive
closure of G is the digraph G* such
that
• G* has the same vertices as G
• if G has a directed path from u
to v (u  v), G* has a directed
edge from u to v
• The transitive closure provides
reachability information about a
digraph
2
1
4
3
5
2
1
4 5
G
3
Warshall’s Algorithm
Main Idea
Suppose two nodes 1 & 5
A path exists between two vertices 1, 5, iff
• there is an edge from 1 to 5; or
• there is a path from 1 to 5 going through vertex 2; or
• there is a path from 1 to 5 going through vertex 2 and/or
3; or
• there is a path from 1 to 5 going through vertex 2, 3,
and/or 4
…
So, (1, 5) is a transitive closure
2
1
4
3
5
2
1
4
3
5
2
1
4
3
5
Warshall’s Algorithm
On the kth iteration, the algorithm determine if a path exists between two
vertices i, j using just vertices among 1,…,k allowed as intermediate
𝑅 𝑘
[i, j]
= {𝑅 𝑘−1
[i, j] (path using just 1 ,…,k-1)
Or
𝑅 𝑘−1
[i, k] and 𝑅 𝑘−1
[k, j] (path from i to k and from k to i using just 1
,…,k-1)
i
j
k
𝑘 𝑡ℎ iteration
Warshall’s Algorithm
Algorithm Warshall
Input: Adjacency matrix A of relation R on a set of n elements
Output: Adjacency matrix T of the transitive closure of R.
Algorithm Body:
T := A [initialize T to A]
for j := 1 to n
for i := 1 to n
if 𝑻𝒊,𝒋 = 1 then
𝑇𝑖 := 𝑇𝑖∨ 𝑇𝑗[form the Boolean OR of row iand row j, store it in 𝑇𝑖]
next i
next j
end Algorithm Warshall
Warshall’s Algorithm
2
1
4
3
5
0 0 1 0 0
0 0 1 1 0
0 0 0 1 0
0 0 0 0 1
0 0 0 0 0
Here A = T =
1 2 3 4
5 j1
2
3
4
5
i
j = 1
i = 1 𝑇𝑖,𝑗 = 0 no action
i = 2 𝑇𝑖,𝑗 = 0 no action
i = 3 𝑇𝑖,𝑗 = 0 no action
i = 4 𝑇𝑖,𝑗 = 0 no action
i = 5 𝑇𝑖,𝑗 = 0 no action
𝐴𝑖,𝑗 =
1 𝑖𝑓 𝑡ℎ𝑒 𝑑𝑖𝑔𝑟𝑎𝑝ℎ ℎ𝑎𝑠 𝑎𝑛 𝑒𝑑𝑔𝑒 𝑓𝑟𝑜𝑚 𝑣𝑖 𝑡𝑜 𝑣𝑗
0 𝑖𝑓 𝑡ℎ𝑒 𝑑𝑖𝑔𝑟𝑎𝑝ℎ ℎ𝑎𝑠 𝑛𝑜 𝑒𝑑𝑔𝑒 𝑓𝑟𝑜𝑚 𝑣𝑖 𝑡𝑜 𝑣𝑗
Warshall’s Algorithm
0 0 1 0 0
0 0 1 1 0
0 0 0 1 0
0 0 0 0 1
0 0 0 0 0
1 2 3 4
51
2
3
4
5
𝑇1 =
j= 2
i = 1 𝑇𝑖,𝑗 = 0 no action
i = 2 𝑇𝑖,𝑗 = 0 no action
i = 3 𝑇𝑖,𝑗 = 0 no action
i = 4 𝑇𝑖,𝑗 = 0 no action
i = 5 𝑇𝑖,𝑗 = 0 no action
2
1
4
3
5
Warshall’s Algorithm
0 0 1 0 0
0 0 1 1 0
0 0 0 1 0
0 0 0 0 1
0 0 0 0 0
1 2 3 4
51
2
3
4
5
j=3
i = 1 𝑇𝑖,𝑗 = 1 𝑇1 = 𝑇1 ∨ 𝑇3 = (0 0 1 0 0) ∨ (0 0 0 1 0) = (0 0 1 1 0)
i = 2 𝑇𝑖,𝑗 = 1 𝑇2 = 𝑇2 ∨ 𝑇3 = (0 0 1 1 0) ∨ (0 0 0 1 0) = (0 0 1 1 0)
i = 3 𝑇𝑖,𝑗 = 0 no action
i = 4 𝑇𝑖,𝑗 = 0 no action
i = 5 𝑇𝑖,𝑗 = 0 no action
𝑇2 =
2
1
4
3
5
Warshall’s Algorithm
0 0 1 1 0
0 0 1 1 0
0 0 0 1 0
0 0 0 0 1
0 0 0 0 0
1 2 3 4
51
2
3
4
5
j=4
i = 1 𝑇𝑖,𝑗 = 1 𝑇1 = 𝑇1 ∨ 𝑇4 = (0 0 1 1 0) ∨ (0 0 0 0 1) = (0 0
1 1 1)
i = 2 𝑇𝑖,𝑗 = 1 𝑇2 = 𝑇2 ∨ 𝑇4 = (0 0 1 1 0) ∨ (0 0 0 0 1) = (0 0 1 1
1)
i = 3 𝑇𝑖,𝑗 = 1 𝑇3 = 𝑇3 ∨ 𝑇4 = (0 0 0 1 0) ∨ (0 0 0 0 1) = (0 0 0 1
1)
i = 4 𝑇𝑖,𝑗 = 0 no action
i = 5 𝑇𝑖,𝑗 = 0 no action
𝑇3 =
2
1
4
3
5
Warshall’s Algorithm
0 0 1 1 1
0 0 1 1 1
0 0 0 1 1
0 0 0 0 1
0 0 0 0 0
1 2 3 4
51
2
3
4
5
j=5
i = 1 𝑇𝑖,𝑗 = 1 𝑇1 = 𝑇1 ∨ 𝑇5 = (0 0 1 1 1) ∨ (0 0 0 0 0) = (0 0
1 1 1)
i = 2 𝑇𝑖,𝑗 = 1 𝑇2 = 𝑇2 ∨ 𝑇5 = (0 0 1 1 1) ∨ (0 0 0 0 0) = (0 0 1 1
1)
i = 3 𝑇𝑖,𝑗 = 1 𝑇3 = 𝑇3 ∨ 𝑇5 = (0 0 0 1 1) ∨ (0 0 0 0 0) = (0 0 0 1
1)
i = 4 𝑇𝑖,𝑗 = 1 𝑇4 = 𝑇4 ∨ 𝑇5 = (0 0 0 0 1) ∨ (0 0 0 0 0) = (0 0 0 0
1)
i = 5 𝑇𝑖,𝑗 = 0 no action
𝑇4 =
2
1
4
3
5
Warshall’s Algorithm
0 0 1 1 1
0 0 1 1 1
0 0 0 1 1
0 0 0 0 1
0 0 0 0 0
1 2 3 4
51
2
3
4
5
T = 𝑇5 =
2
1
4
3
5
G*
Warshall’s Algorithm
Time Complexity
This algorithm has two nested loops containing
a Θ(n) core, so it takes Θ (𝑛3
) time.
Time complexity = n * Θ (𝑛2) = Θ (𝑛3)
Space Complexity
At any point in the algorithm, we only need the
last two matrices computed, so we can re-use
the storage from the other matrices.
space complexity = Θ (𝑛2
)
Thank You
Any Question?

More Related Content

What's hot

01 Knapsack using Dynamic Programming
01 Knapsack using Dynamic Programming01 Knapsack using Dynamic Programming
01 Knapsack using Dynamic Programming
Fenil Shah
 
Find Transitive closure of a Graph Using Warshall's Algorithm
Find Transitive closure of a Graph Using Warshall's AlgorithmFind Transitive closure of a Graph Using Warshall's Algorithm
Find Transitive closure of a Graph Using Warshall's Algorithm
Safayet Hossain
 
Dijkstra’S Algorithm
Dijkstra’S AlgorithmDijkstra’S Algorithm
Dijkstra’S Algorithm
ami_01
 
Dijkstra's algorithm
Dijkstra's algorithmDijkstra's algorithm
Dijkstra's algorithmgsp1294
 
Graph Theory
Graph TheoryGraph Theory
Graph Theory
Ehsan Hamzei
 
Algorithm
AlgorithmAlgorithm
Algorithm
DebleenaBiswas4
 
Graph theory
Graph theory Graph theory
Graph theory
iranian translate
 
Prim's algorithm
Prim's algorithmPrim's algorithm
Prim's algorithm
Pankaj Thakur
 
All pairs shortest path algorithm
All pairs shortest path algorithmAll pairs shortest path algorithm
All pairs shortest path algorithmSrikrishnan Suresh
 
Introduction to Graph Theory
Introduction to Graph TheoryIntroduction to Graph Theory
Introduction to Graph Theory
Yosuke Mizutani
 
mathematical induction
mathematical inductionmathematical induction
mathematical inductionankush_kumar
 
introduction to graph theory
introduction to graph theoryintroduction to graph theory
introduction to graph theoryChuckie Balbuena
 
Approximation Algorithms
Approximation AlgorithmsApproximation Algorithms
Approximation Algorithms
Nicolas Bettenburg
 
Prims and kruskal algorithms
Prims and kruskal algorithmsPrims and kruskal algorithms
Prims and kruskal algorithms
Saga Valsalan
 
Dijkstra.ppt
Dijkstra.pptDijkstra.ppt
Dijkstra.ppt
Ruchika Sinha
 
Graph data structure
Graph data structureGraph data structure
Graph data structureTech_MX
 
daa-unit-3-greedy method
daa-unit-3-greedy methoddaa-unit-3-greedy method
daa-unit-3-greedy method
hodcsencet
 
Bellman Ford's Algorithm
Bellman Ford's AlgorithmBellman Ford's Algorithm
Bellman Ford's Algorithm
Tanmay Baranwal
 
Logical equivalence, laws of logic
Logical equivalence, laws of logicLogical equivalence, laws of logic
Logical equivalence, laws of logic
Lakshmi R
 

What's hot (20)

01 Knapsack using Dynamic Programming
01 Knapsack using Dynamic Programming01 Knapsack using Dynamic Programming
01 Knapsack using Dynamic Programming
 
Find Transitive closure of a Graph Using Warshall's Algorithm
Find Transitive closure of a Graph Using Warshall's AlgorithmFind Transitive closure of a Graph Using Warshall's Algorithm
Find Transitive closure of a Graph Using Warshall's Algorithm
 
Dijkstra’S Algorithm
Dijkstra’S AlgorithmDijkstra’S Algorithm
Dijkstra’S Algorithm
 
Dijkstra's algorithm
Dijkstra's algorithmDijkstra's algorithm
Dijkstra's algorithm
 
Graph Theory
Graph TheoryGraph Theory
Graph Theory
 
Algorithm
AlgorithmAlgorithm
Algorithm
 
Graph theory
Graph theory Graph theory
Graph theory
 
Disjoint sets
Disjoint setsDisjoint sets
Disjoint sets
 
Prim's algorithm
Prim's algorithmPrim's algorithm
Prim's algorithm
 
All pairs shortest path algorithm
All pairs shortest path algorithmAll pairs shortest path algorithm
All pairs shortest path algorithm
 
Introduction to Graph Theory
Introduction to Graph TheoryIntroduction to Graph Theory
Introduction to Graph Theory
 
mathematical induction
mathematical inductionmathematical induction
mathematical induction
 
introduction to graph theory
introduction to graph theoryintroduction to graph theory
introduction to graph theory
 
Approximation Algorithms
Approximation AlgorithmsApproximation Algorithms
Approximation Algorithms
 
Prims and kruskal algorithms
Prims and kruskal algorithmsPrims and kruskal algorithms
Prims and kruskal algorithms
 
Dijkstra.ppt
Dijkstra.pptDijkstra.ppt
Dijkstra.ppt
 
Graph data structure
Graph data structureGraph data structure
Graph data structure
 
daa-unit-3-greedy method
daa-unit-3-greedy methoddaa-unit-3-greedy method
daa-unit-3-greedy method
 
Bellman Ford's Algorithm
Bellman Ford's AlgorithmBellman Ford's Algorithm
Bellman Ford's Algorithm
 
Logical equivalence, laws of logic
Logical equivalence, laws of logicLogical equivalence, laws of logic
Logical equivalence, laws of logic
 

Similar to Find transitive-closure using warshalls-algorithm

Fourier series
Fourier series Fourier series
Fourier series
Santhanam Krishnan
 
Knapsack problem dynamicprogramming
Knapsack problem dynamicprogrammingKnapsack problem dynamicprogramming
Knapsack problem dynamicprogramming
rowntu
 
On ranges and null spaces of a special type of operator named 𝝀 − 𝒋𝒆𝒄𝒕𝒊𝒐𝒏. – ...
On ranges and null spaces of a special type of operator named 𝝀 − 𝒋𝒆𝒄𝒕𝒊𝒐𝒏. – ...On ranges and null spaces of a special type of operator named 𝝀 − 𝒋𝒆𝒄𝒕𝒊𝒐𝒏. – ...
On ranges and null spaces of a special type of operator named 𝝀 − 𝒋𝒆𝒄𝒕𝒊𝒐𝒏. – ...
IJMER
 
F04573843
F04573843F04573843
F04573843
IOSR-JEN
 
Gram-Schmidt process linear algbera.pptx
Gram-Schmidt process linear algbera.pptxGram-Schmidt process linear algbera.pptx
Gram-Schmidt process linear algbera.pptx
Md. Al-Amin
 
Ee315 probability muqaibel ch1
Ee315 probability muqaibel ch1Ee315 probability muqaibel ch1
Ee315 probability muqaibel ch1
MuhannadSaleh
 
Maximum Likelihood Estimation of Beetle
Maximum Likelihood Estimation of BeetleMaximum Likelihood Estimation of Beetle
Maximum Likelihood Estimation of BeetleLiang Kai Hu
 
Topological sort
Topological sortTopological sort
Topological sort
stella D
 
Optimum Receiver for CPM over AWGN channel
Optimum Receiver for CPM over AWGN channelOptimum Receiver for CPM over AWGN channel
Optimum Receiver for CPM over AWGN channelMohsen Jamalabdollahi
 
Ranjak Vaidic Ganit Preview (Marathi Research Book)
Ranjak Vaidic Ganit Preview (Marathi Research Book)Ranjak Vaidic Ganit Preview (Marathi Research Book)
Ranjak Vaidic Ganit Preview (Marathi Research Book)
Vitthal Jadhav
 
Semana 24 funciones iv álgebra uni ccesa007
Semana 24 funciones iv álgebra uni ccesa007Semana 24 funciones iv álgebra uni ccesa007
Semana 24 funciones iv álgebra uni ccesa007
Demetrio Ccesa Rayme
 
On ranges and null spaces of a special type of operator named 𝝀 − 𝒋𝒆𝒄𝒕𝒊𝒐𝒏. – ...
On ranges and null spaces of a special type of operator named 𝝀 − 𝒋𝒆𝒄𝒕𝒊𝒐𝒏. – ...On ranges and null spaces of a special type of operator named 𝝀 − 𝒋𝒆𝒄𝒕𝒊𝒐𝒏. – ...
On ranges and null spaces of a special type of operator named 𝝀 − 𝒋𝒆𝒄𝒕𝒊𝒐𝒏. – ...
IJMER
 
TAoCP 7.7.7.2 Satisfiability の輪読
TAoCP 7.7.7.2 Satisfiability の輪読TAoCP 7.7.7.2 Satisfiability の輪読
TAoCP 7.7.7.2 Satisfiability の輪読
Kotaro Okazaki
 
The Art of Computer Programming volume 4 fascicle 6 7.7.7.2 p.47-76
The Art of Computer Programming volume 4 fascicle 6 7.7.7.2 p.47-76 The Art of Computer Programming volume 4 fascicle 6 7.7.7.2 p.47-76
The Art of Computer Programming volume 4 fascicle 6 7.7.7.2 p.47-76
Kotaro Okazaki
 
1. Probability.pdf
1. Probability.pdf1. Probability.pdf
1. Probability.pdf
SurajRajTripathy
 
Further Results On The Basis Of Cauchy’s Proper Bound for the Zeros of Entire...
Further Results On The Basis Of Cauchy’s Proper Bound for the Zeros of Entire...Further Results On The Basis Of Cauchy’s Proper Bound for the Zeros of Entire...
Further Results On The Basis Of Cauchy’s Proper Bound for the Zeros of Entire...
IJMER
 
A Weird Soviet Method to Partially Solve the Perebor Problem
A Weird Soviet Method to Partially Solve the Perebor ProblemA Weird Soviet Method to Partially Solve the Perebor Problem
A Weird Soviet Method to Partially Solve the Perebor Problem
Sing Kuang Tan
 
Backpropagation
BackpropagationBackpropagation
Backpropagation
강민국 강민국
 
Orbital_Simulation (2).pptx
Orbital_Simulation (2).pptxOrbital_Simulation (2).pptx
Orbital_Simulation (2).pptx
MSPrasad7
 

Similar to Find transitive-closure using warshalls-algorithm (20)

Fourier series
Fourier series Fourier series
Fourier series
 
Knapsack problem dynamicprogramming
Knapsack problem dynamicprogrammingKnapsack problem dynamicprogramming
Knapsack problem dynamicprogramming
 
On ranges and null spaces of a special type of operator named 𝝀 − 𝒋𝒆𝒄𝒕𝒊𝒐𝒏. – ...
On ranges and null spaces of a special type of operator named 𝝀 − 𝒋𝒆𝒄𝒕𝒊𝒐𝒏. – ...On ranges and null spaces of a special type of operator named 𝝀 − 𝒋𝒆𝒄𝒕𝒊𝒐𝒏. – ...
On ranges and null spaces of a special type of operator named 𝝀 − 𝒋𝒆𝒄𝒕𝒊𝒐𝒏. – ...
 
F04573843
F04573843F04573843
F04573843
 
Gram-Schmidt process linear algbera.pptx
Gram-Schmidt process linear algbera.pptxGram-Schmidt process linear algbera.pptx
Gram-Schmidt process linear algbera.pptx
 
Ee315 probability muqaibel ch1
Ee315 probability muqaibel ch1Ee315 probability muqaibel ch1
Ee315 probability muqaibel ch1
 
Maximum Likelihood Estimation of Beetle
Maximum Likelihood Estimation of BeetleMaximum Likelihood Estimation of Beetle
Maximum Likelihood Estimation of Beetle
 
Topological sort
Topological sortTopological sort
Topological sort
 
Optimum Receiver for CPM over AWGN channel
Optimum Receiver for CPM over AWGN channelOptimum Receiver for CPM over AWGN channel
Optimum Receiver for CPM over AWGN channel
 
Ranjak Vaidic Ganit Preview (Marathi Research Book)
Ranjak Vaidic Ganit Preview (Marathi Research Book)Ranjak Vaidic Ganit Preview (Marathi Research Book)
Ranjak Vaidic Ganit Preview (Marathi Research Book)
 
Semana 24 funciones iv álgebra uni ccesa007
Semana 24 funciones iv álgebra uni ccesa007Semana 24 funciones iv álgebra uni ccesa007
Semana 24 funciones iv álgebra uni ccesa007
 
On ranges and null spaces of a special type of operator named 𝝀 − 𝒋𝒆𝒄𝒕𝒊𝒐𝒏. – ...
On ranges and null spaces of a special type of operator named 𝝀 − 𝒋𝒆𝒄𝒕𝒊𝒐𝒏. – ...On ranges and null spaces of a special type of operator named 𝝀 − 𝒋𝒆𝒄𝒕𝒊𝒐𝒏. – ...
On ranges and null spaces of a special type of operator named 𝝀 − 𝒋𝒆𝒄𝒕𝒊𝒐𝒏. – ...
 
TAoCP 7.7.7.2 Satisfiability の輪読
TAoCP 7.7.7.2 Satisfiability の輪読TAoCP 7.7.7.2 Satisfiability の輪読
TAoCP 7.7.7.2 Satisfiability の輪読
 
The Art of Computer Programming volume 4 fascicle 6 7.7.7.2 p.47-76
The Art of Computer Programming volume 4 fascicle 6 7.7.7.2 p.47-76 The Art of Computer Programming volume 4 fascicle 6 7.7.7.2 p.47-76
The Art of Computer Programming volume 4 fascicle 6 7.7.7.2 p.47-76
 
1. Probability.pdf
1. Probability.pdf1. Probability.pdf
1. Probability.pdf
 
Further Results On The Basis Of Cauchy’s Proper Bound for the Zeros of Entire...
Further Results On The Basis Of Cauchy’s Proper Bound for the Zeros of Entire...Further Results On The Basis Of Cauchy’s Proper Bound for the Zeros of Entire...
Further Results On The Basis Of Cauchy’s Proper Bound for the Zeros of Entire...
 
Linear equations 2-3
Linear equations   2-3Linear equations   2-3
Linear equations 2-3
 
A Weird Soviet Method to Partially Solve the Perebor Problem
A Weird Soviet Method to Partially Solve the Perebor ProblemA Weird Soviet Method to Partially Solve the Perebor Problem
A Weird Soviet Method to Partially Solve the Perebor Problem
 
Backpropagation
BackpropagationBackpropagation
Backpropagation
 
Orbital_Simulation (2).pptx
Orbital_Simulation (2).pptxOrbital_Simulation (2).pptx
Orbital_Simulation (2).pptx
 

Recently uploaded

Fish and Chips - have they had their chips
Fish and Chips - have they had their chipsFish and Chips - have they had their chips
Fish and Chips - have they had their chips
GeoBlogs
 
How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...
Jisc
 
Language Across the Curriculm LAC B.Ed.
Language Across the  Curriculm LAC B.Ed.Language Across the  Curriculm LAC B.Ed.
Language Across the Curriculm LAC B.Ed.
Atul Kumar Singh
 
Digital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and ResearchDigital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and Research
Vikramjit Singh
 
MARUTI SUZUKI- A Successful Joint Venture in India.pptx
MARUTI SUZUKI- A Successful Joint Venture in India.pptxMARUTI SUZUKI- A Successful Joint Venture in India.pptx
MARUTI SUZUKI- A Successful Joint Venture in India.pptx
bennyroshan06
 
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
EugeneSaldivar
 
Unit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdfUnit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdf
Thiyagu K
 
PART A. Introduction to Costumer Service
PART A. Introduction to Costumer ServicePART A. Introduction to Costumer Service
PART A. Introduction to Costumer Service
PedroFerreira53928
 
How to Split Bills in the Odoo 17 POS Module
How to Split Bills in the Odoo 17 POS ModuleHow to Split Bills in the Odoo 17 POS Module
How to Split Bills in the Odoo 17 POS Module
Celine George
 
How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17
Celine George
 
Synthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptxSynthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptx
Pavel ( NSTU)
 
Overview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with MechanismOverview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with Mechanism
DeeptiGupta154
 
The approach at University of Liverpool.pptx
The approach at University of Liverpool.pptxThe approach at University of Liverpool.pptx
The approach at University of Liverpool.pptx
Jisc
 
The Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official PublicationThe Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official Publication
Delapenabediema
 
Students, digital devices and success - Andreas Schleicher - 27 May 2024..pptx
Students, digital devices and success - Andreas Schleicher - 27 May 2024..pptxStudents, digital devices and success - Andreas Schleicher - 27 May 2024..pptx
Students, digital devices and success - Andreas Schleicher - 27 May 2024..pptx
EduSkills OECD
 
Chapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptxChapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptx
Mohd Adib Abd Muin, Senior Lecturer at Universiti Utara Malaysia
 
ESC Beyond Borders _From EU to You_ InfoPack general.pdf
ESC Beyond Borders _From EU to You_ InfoPack general.pdfESC Beyond Borders _From EU to You_ InfoPack general.pdf
ESC Beyond Borders _From EU to You_ InfoPack general.pdf
Fundacja Rozwoju Społeczeństwa Przedsiębiorczego
 
The French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free downloadThe French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free download
Vivekanand Anglo Vedic Academy
 
Home assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdfHome assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdf
Tamralipta Mahavidyalaya
 
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCECLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
BhavyaRajput3
 

Recently uploaded (20)

Fish and Chips - have they had their chips
Fish and Chips - have they had their chipsFish and Chips - have they had their chips
Fish and Chips - have they had their chips
 
How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...
 
Language Across the Curriculm LAC B.Ed.
Language Across the  Curriculm LAC B.Ed.Language Across the  Curriculm LAC B.Ed.
Language Across the Curriculm LAC B.Ed.
 
Digital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and ResearchDigital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and Research
 
MARUTI SUZUKI- A Successful Joint Venture in India.pptx
MARUTI SUZUKI- A Successful Joint Venture in India.pptxMARUTI SUZUKI- A Successful Joint Venture in India.pptx
MARUTI SUZUKI- A Successful Joint Venture in India.pptx
 
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
 
Unit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdfUnit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdf
 
PART A. Introduction to Costumer Service
PART A. Introduction to Costumer ServicePART A. Introduction to Costumer Service
PART A. Introduction to Costumer Service
 
How to Split Bills in the Odoo 17 POS Module
How to Split Bills in the Odoo 17 POS ModuleHow to Split Bills in the Odoo 17 POS Module
How to Split Bills in the Odoo 17 POS Module
 
How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17
 
Synthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptxSynthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptx
 
Overview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with MechanismOverview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with Mechanism
 
The approach at University of Liverpool.pptx
The approach at University of Liverpool.pptxThe approach at University of Liverpool.pptx
The approach at University of Liverpool.pptx
 
The Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official PublicationThe Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official Publication
 
Students, digital devices and success - Andreas Schleicher - 27 May 2024..pptx
Students, digital devices and success - Andreas Schleicher - 27 May 2024..pptxStudents, digital devices and success - Andreas Schleicher - 27 May 2024..pptx
Students, digital devices and success - Andreas Schleicher - 27 May 2024..pptx
 
Chapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptxChapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptx
 
ESC Beyond Borders _From EU to You_ InfoPack general.pdf
ESC Beyond Borders _From EU to You_ InfoPack general.pdfESC Beyond Borders _From EU to You_ InfoPack general.pdf
ESC Beyond Borders _From EU to You_ InfoPack general.pdf
 
The French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free downloadThe French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free download
 
Home assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdfHome assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdf
 
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCECLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
 

Find transitive-closure using warshalls-algorithm

  • 1. Name: Md Mamun Hasan Roll: 1907555 (KUET) Course: CSE 6101 Find Transitive Closure using Warshall’s Algorithm
  • 2. Transitive Closure • Given a digraph G, the transitive closure of G is the digraph G* such that • G* has the same vertices as G • if G has a directed path from u to v (u  v), G* has a directed edge from u to v • The transitive closure provides reachability information about a digraph 2 1 4 3 5 2 1 4 5 G 3
  • 3. Warshall’s Algorithm Main Idea Suppose two nodes 1 & 5 A path exists between two vertices 1, 5, iff • there is an edge from 1 to 5; or • there is a path from 1 to 5 going through vertex 2; or • there is a path from 1 to 5 going through vertex 2 and/or 3; or • there is a path from 1 to 5 going through vertex 2, 3, and/or 4 … So, (1, 5) is a transitive closure 2 1 4 3 5 2 1 4 3 5 2 1 4 3 5
  • 4. Warshall’s Algorithm On the kth iteration, the algorithm determine if a path exists between two vertices i, j using just vertices among 1,…,k allowed as intermediate 𝑅 𝑘 [i, j] = {𝑅 𝑘−1 [i, j] (path using just 1 ,…,k-1) Or 𝑅 𝑘−1 [i, k] and 𝑅 𝑘−1 [k, j] (path from i to k and from k to i using just 1 ,…,k-1) i j k 𝑘 𝑡ℎ iteration
  • 5. Warshall’s Algorithm Algorithm Warshall Input: Adjacency matrix A of relation R on a set of n elements Output: Adjacency matrix T of the transitive closure of R. Algorithm Body: T := A [initialize T to A] for j := 1 to n for i := 1 to n if 𝑻𝒊,𝒋 = 1 then 𝑇𝑖 := 𝑇𝑖∨ 𝑇𝑗[form the Boolean OR of row iand row j, store it in 𝑇𝑖] next i next j end Algorithm Warshall
  • 6. Warshall’s Algorithm 2 1 4 3 5 0 0 1 0 0 0 0 1 1 0 0 0 0 1 0 0 0 0 0 1 0 0 0 0 0 Here A = T = 1 2 3 4 5 j1 2 3 4 5 i j = 1 i = 1 𝑇𝑖,𝑗 = 0 no action i = 2 𝑇𝑖,𝑗 = 0 no action i = 3 𝑇𝑖,𝑗 = 0 no action i = 4 𝑇𝑖,𝑗 = 0 no action i = 5 𝑇𝑖,𝑗 = 0 no action 𝐴𝑖,𝑗 = 1 𝑖𝑓 𝑡ℎ𝑒 𝑑𝑖𝑔𝑟𝑎𝑝ℎ ℎ𝑎𝑠 𝑎𝑛 𝑒𝑑𝑔𝑒 𝑓𝑟𝑜𝑚 𝑣𝑖 𝑡𝑜 𝑣𝑗 0 𝑖𝑓 𝑡ℎ𝑒 𝑑𝑖𝑔𝑟𝑎𝑝ℎ ℎ𝑎𝑠 𝑛𝑜 𝑒𝑑𝑔𝑒 𝑓𝑟𝑜𝑚 𝑣𝑖 𝑡𝑜 𝑣𝑗
  • 7. Warshall’s Algorithm 0 0 1 0 0 0 0 1 1 0 0 0 0 1 0 0 0 0 0 1 0 0 0 0 0 1 2 3 4 51 2 3 4 5 𝑇1 = j= 2 i = 1 𝑇𝑖,𝑗 = 0 no action i = 2 𝑇𝑖,𝑗 = 0 no action i = 3 𝑇𝑖,𝑗 = 0 no action i = 4 𝑇𝑖,𝑗 = 0 no action i = 5 𝑇𝑖,𝑗 = 0 no action 2 1 4 3 5
  • 8. Warshall’s Algorithm 0 0 1 0 0 0 0 1 1 0 0 0 0 1 0 0 0 0 0 1 0 0 0 0 0 1 2 3 4 51 2 3 4 5 j=3 i = 1 𝑇𝑖,𝑗 = 1 𝑇1 = 𝑇1 ∨ 𝑇3 = (0 0 1 0 0) ∨ (0 0 0 1 0) = (0 0 1 1 0) i = 2 𝑇𝑖,𝑗 = 1 𝑇2 = 𝑇2 ∨ 𝑇3 = (0 0 1 1 0) ∨ (0 0 0 1 0) = (0 0 1 1 0) i = 3 𝑇𝑖,𝑗 = 0 no action i = 4 𝑇𝑖,𝑗 = 0 no action i = 5 𝑇𝑖,𝑗 = 0 no action 𝑇2 = 2 1 4 3 5
  • 9. Warshall’s Algorithm 0 0 1 1 0 0 0 1 1 0 0 0 0 1 0 0 0 0 0 1 0 0 0 0 0 1 2 3 4 51 2 3 4 5 j=4 i = 1 𝑇𝑖,𝑗 = 1 𝑇1 = 𝑇1 ∨ 𝑇4 = (0 0 1 1 0) ∨ (0 0 0 0 1) = (0 0 1 1 1) i = 2 𝑇𝑖,𝑗 = 1 𝑇2 = 𝑇2 ∨ 𝑇4 = (0 0 1 1 0) ∨ (0 0 0 0 1) = (0 0 1 1 1) i = 3 𝑇𝑖,𝑗 = 1 𝑇3 = 𝑇3 ∨ 𝑇4 = (0 0 0 1 0) ∨ (0 0 0 0 1) = (0 0 0 1 1) i = 4 𝑇𝑖,𝑗 = 0 no action i = 5 𝑇𝑖,𝑗 = 0 no action 𝑇3 = 2 1 4 3 5
  • 10. Warshall’s Algorithm 0 0 1 1 1 0 0 1 1 1 0 0 0 1 1 0 0 0 0 1 0 0 0 0 0 1 2 3 4 51 2 3 4 5 j=5 i = 1 𝑇𝑖,𝑗 = 1 𝑇1 = 𝑇1 ∨ 𝑇5 = (0 0 1 1 1) ∨ (0 0 0 0 0) = (0 0 1 1 1) i = 2 𝑇𝑖,𝑗 = 1 𝑇2 = 𝑇2 ∨ 𝑇5 = (0 0 1 1 1) ∨ (0 0 0 0 0) = (0 0 1 1 1) i = 3 𝑇𝑖,𝑗 = 1 𝑇3 = 𝑇3 ∨ 𝑇5 = (0 0 0 1 1) ∨ (0 0 0 0 0) = (0 0 0 1 1) i = 4 𝑇𝑖,𝑗 = 1 𝑇4 = 𝑇4 ∨ 𝑇5 = (0 0 0 0 1) ∨ (0 0 0 0 0) = (0 0 0 0 1) i = 5 𝑇𝑖,𝑗 = 0 no action 𝑇4 = 2 1 4 3 5
  • 11. Warshall’s Algorithm 0 0 1 1 1 0 0 1 1 1 0 0 0 1 1 0 0 0 0 1 0 0 0 0 0 1 2 3 4 51 2 3 4 5 T = 𝑇5 = 2 1 4 3 5 G*
  • 12. Warshall’s Algorithm Time Complexity This algorithm has two nested loops containing a Θ(n) core, so it takes Θ (𝑛3 ) time. Time complexity = n * Θ (𝑛2) = Θ (𝑛3) Space Complexity At any point in the algorithm, we only need the last two matrices computed, so we can re-use the storage from the other matrices. space complexity = Θ (𝑛2 )