SlideShare a Scribd company logo
1 of 8
 Introduction
 Warshall's algorithm
 Shortest path algorithm Floyd Warshall
Algorithm (modified warshall algorithm)
What is a Graph?
A graph G = (V,E) is composed of:
V: set of vertices
E: set of edges connecting the vertices in V
An edge e = (u,v) is a pair of vertices
Example:
a b
c
d e
V= {a,b,c,d,e}
E= {(a,b),(a,c),(a,d),
(b,e),(c,d),(c,e),
(d,e)}
0 0 0 1
1 0 1 1
1 0 0 1
0 0 1 0
A1 =
0 0 1 0
1 0 1 2
0 0 1 1
1 0 0 1
1 0 0 1
1 0 2 2
1 0 1 1
0 0 1 1
X
W
Y
Z
A2 = A3 =
Adjacency Matrix and Path Matrix
A4 =
0 0 1 1
2 0 2 3
1 0 1 2
1 0 1 1
B4 = A1 + A2 + A3 + A4
• entry of matrix B4 gives the number of paths of length 4 or less from node vi to vj
• entry of matrix Br gives the number of paths of length r or less from node vi to vj
Number of Paths between Y to W of length 3 are 2
(Y -> Z -> X -> W AND Y->W->Z->W)
Warshall's algorithm
1. Repeat for I, J = 1, 2,…, M: [Initializes P.]
If A[I, J] = 0, then: Set P[I, J] := 0;
Else Set P[I, J] := 1.
[End of loop.]
1. Repeat Steps 3 and 4 for K = 1, 2,…, M: [Updates P.]
2. Repeat Step 4 for I = 1, 2,…, M:
3. Repeat J= 1, 2,…, M:
Set P[I, J] := P[I, J] OR (P[I, K] AND P[K, J] ).
[End of loop.]
[End of Step 3 loop.]
[End of step 2 loop.]
5. Exit
Example:
Floyd Warshall Algorithm
1. Repeat for I, J = 1, 2,…, M: [Initializes P.]
If A[I, J] = 0, then: Set P[I, J] := ∞;
Else Set P[I, J] := W(I, J).
[End of loop.]
1. Repeat Steps 3 and 4 for K = 1, 2,…, M: [Updates P.]
2. Repeat Step 4 for I = 1, 2,…, M:
3. Repeat J= 1, 2,…, M:
Set P[I, J] := MIN(P[I, J], (P[I, K]+P[K, J])).
[End of loop.]
[End of Step 3 loop.]
[End of step 2 loop.]
5. Exit
Example:
Thank You

More Related Content

What's hot

matlab program for TLBO algorithm
matlab program for TLBO algorithmmatlab program for TLBO algorithm
matlab program for TLBO algorithmrajani51
 
Matlab exam codes - Computer Modelling Techniques module
Matlab exam codes - Computer Modelling Techniques moduleMatlab exam codes - Computer Modelling Techniques module
Matlab exam codes - Computer Modelling Techniques moduleLuca Parisi
 
Math34 Trigonometric Formulas
Math34 Trigonometric  FormulasMath34 Trigonometric  Formulas
Math34 Trigonometric FormulasTopTuition
 
Trigonometry cheat sheet
Trigonometry cheat sheetTrigonometry cheat sheet
Trigonometry cheat sheetmelkydinsay
 
Math34 Trigonometric Formulas
Math34 Trigonometric  FormulasMath34 Trigonometric  Formulas
Math34 Trigonometric FormulasTopTuition
 
Math34 Trigonometric Formulas
Math34 Trigonometric  FormulasMath34 Trigonometric  Formulas
Math34 Trigonometric FormulasTopTuition
 
Continuity and differentiation
Continuity and differentiationContinuity and differentiation
Continuity and differentiationDr. Hari Arora
 
Lecture 7.1 to 7.2 bt
Lecture 7.1 to 7.2 btLecture 7.1 to 7.2 bt
Lecture 7.1 to 7.2 btbtmathematics
 

What's hot (17)

matlab program for TLBO algorithm
matlab program for TLBO algorithmmatlab program for TLBO algorithm
matlab program for TLBO algorithm
 
Elements of a sequence
Elements of a sequenceElements of a sequence
Elements of a sequence
 
F(x) terminology
F(x) terminologyF(x) terminology
F(x) terminology
 
Matlab exam codes - Computer Modelling Techniques module
Matlab exam codes - Computer Modelling Techniques moduleMatlab exam codes - Computer Modelling Techniques module
Matlab exam codes - Computer Modelling Techniques module
 
Math34 Trigonometric Formulas
Math34 Trigonometric  FormulasMath34 Trigonometric  Formulas
Math34 Trigonometric Formulas
 
Trigonometry cheat sheet
Trigonometry cheat sheetTrigonometry cheat sheet
Trigonometry cheat sheet
 
Tangent plane
Tangent planeTangent plane
Tangent plane
 
Tangent plane
Tangent planeTangent plane
Tangent plane
 
How to calculate β
How to calculate βHow to calculate β
How to calculate β
 
Differntiation
 Differntiation Differntiation
Differntiation
 
Math34 Trigonometric Formulas
Math34 Trigonometric  FormulasMath34 Trigonometric  Formulas
Math34 Trigonometric Formulas
 
Math34 Trigonometric Formulas
Math34 Trigonometric  FormulasMath34 Trigonometric  Formulas
Math34 Trigonometric Formulas
 
Numerical Method for UOG mech stu prd by Abdrehman Ahmed
Numerical Method for UOG mech stu prd by Abdrehman Ahmed Numerical Method for UOG mech stu prd by Abdrehman Ahmed
Numerical Method for UOG mech stu prd by Abdrehman Ahmed
 
Circle
CircleCircle
Circle
 
Continuity and differentiation
Continuity and differentiationContinuity and differentiation
Continuity and differentiation
 
Lecture 7.1 to 7.2 bt
Lecture 7.1 to 7.2 btLecture 7.1 to 7.2 bt
Lecture 7.1 to 7.2 bt
 
Ch02 13
Ch02 13Ch02 13
Ch02 13
 

Similar to Data Structure and Algorithms Graphs

Similar to Data Structure and Algorithms Graphs (20)

Bellman ford
Bellman fordBellman ford
Bellman ford
 
Pre-Calculus - Vectors
Pre-Calculus - VectorsPre-Calculus - Vectors
Pre-Calculus - Vectors
 
Presentation on calculus
Presentation on calculusPresentation on calculus
Presentation on calculus
 
lec6.pptx
lec6.pptxlec6.pptx
lec6.pptx
 
Problem Solving with Algorithms and Data Structure - Graphs
Problem Solving with Algorithms and Data Structure - GraphsProblem Solving with Algorithms and Data Structure - Graphs
Problem Solving with Algorithms and Data Structure - Graphs
 
presentasi
presentasipresentasi
presentasi
 
Graphs - Discrete Math
Graphs - Discrete MathGraphs - Discrete Math
Graphs - Discrete Math
 
Class1
 Class1 Class1
Class1
 
Vectors in Two and Three.pptx
Vectors in Two and Three.pptxVectors in Two and Three.pptx
Vectors in Two and Three.pptx
 
Barisan dan deret .ingg
Barisan dan deret .inggBarisan dan deret .ingg
Barisan dan deret .ingg
 
Barisan dan deret .ingg
Barisan dan deret .inggBarisan dan deret .ingg
Barisan dan deret .ingg
 
Shortest path algorithms
Shortest path algorithmsShortest path algorithms
Shortest path algorithms
 
Johnson's algorithm
Johnson's algorithmJohnson's algorithm
Johnson's algorithm
 
E field dipole
E field dipoleE field dipole
E field dipole
 
Vector space
Vector spaceVector space
Vector space
 
Maths digital text
Maths digital textMaths digital text
Maths digital text
 
Mathematics
MathematicsMathematics
Mathematics
 
Mathematics
MathematicsMathematics
Mathematics
 
Question bank -xi (hots)
Question bank -xi (hots)Question bank -xi (hots)
Question bank -xi (hots)
 
Daa chpater14
Daa chpater14Daa chpater14
Daa chpater14
 

More from ManishPrajapati78

Data Structure and Algorithms Binary Search Tree
Data Structure and Algorithms Binary Search TreeData Structure and Algorithms Binary Search Tree
Data Structure and Algorithms Binary Search TreeManishPrajapati78
 
Data Structure and Algorithms Binary Tree
Data Structure and Algorithms Binary TreeData Structure and Algorithms Binary Tree
Data Structure and Algorithms Binary TreeManishPrajapati78
 
Data Structure and Algorithms Queues
Data Structure and Algorithms QueuesData Structure and Algorithms Queues
Data Structure and Algorithms QueuesManishPrajapati78
 
Data Structure and Algorithms Merge Sort
Data Structure and Algorithms Merge SortData Structure and Algorithms Merge Sort
Data Structure and Algorithms Merge SortManishPrajapati78
 
Data Structure and Algorithms The Tower of Hanoi
Data Structure and Algorithms The Tower of HanoiData Structure and Algorithms The Tower of Hanoi
Data Structure and Algorithms The Tower of HanoiManishPrajapati78
 
Data Structure and Algorithms Stacks
Data Structure and Algorithms StacksData Structure and Algorithms Stacks
Data Structure and Algorithms StacksManishPrajapati78
 
Data Structure and Algorithms Linked List
Data Structure and Algorithms Linked ListData Structure and Algorithms Linked List
Data Structure and Algorithms Linked ListManishPrajapati78
 
Data Structure and Algorithms Sorting
Data Structure and Algorithms SortingData Structure and Algorithms Sorting
Data Structure and Algorithms SortingManishPrajapati78
 
Data Structure and Algorithms Arrays
Data Structure and Algorithms ArraysData Structure and Algorithms Arrays
Data Structure and Algorithms ArraysManishPrajapati78
 
Data Structure and Algorithms
Data Structure and Algorithms Data Structure and Algorithms
Data Structure and Algorithms ManishPrajapati78
 
Data Structure and Algorithms Hashing
Data Structure and Algorithms HashingData Structure and Algorithms Hashing
Data Structure and Algorithms HashingManishPrajapati78
 
Data Structure and Algorithms Graph Traversal
Data Structure and Algorithms Graph TraversalData Structure and Algorithms Graph Traversal
Data Structure and Algorithms Graph TraversalManishPrajapati78
 
Data Structure and Algorithms Huffman Coding Algorithm
Data Structure and Algorithms Huffman Coding AlgorithmData Structure and Algorithms Huffman Coding Algorithm
Data Structure and Algorithms Huffman Coding AlgorithmManishPrajapati78
 
Data Structure and Algorithms Heaps and Trees
Data Structure and Algorithms Heaps and TreesData Structure and Algorithms Heaps and Trees
Data Structure and Algorithms Heaps and TreesManishPrajapati78
 
Data Structure and Algorithms AVL Trees
Data Structure and Algorithms AVL TreesData Structure and Algorithms AVL Trees
Data Structure and Algorithms AVL TreesManishPrajapati78
 

More from ManishPrajapati78 (15)

Data Structure and Algorithms Binary Search Tree
Data Structure and Algorithms Binary Search TreeData Structure and Algorithms Binary Search Tree
Data Structure and Algorithms Binary Search Tree
 
Data Structure and Algorithms Binary Tree
Data Structure and Algorithms Binary TreeData Structure and Algorithms Binary Tree
Data Structure and Algorithms Binary Tree
 
Data Structure and Algorithms Queues
Data Structure and Algorithms QueuesData Structure and Algorithms Queues
Data Structure and Algorithms Queues
 
Data Structure and Algorithms Merge Sort
Data Structure and Algorithms Merge SortData Structure and Algorithms Merge Sort
Data Structure and Algorithms Merge Sort
 
Data Structure and Algorithms The Tower of Hanoi
Data Structure and Algorithms The Tower of HanoiData Structure and Algorithms The Tower of Hanoi
Data Structure and Algorithms The Tower of Hanoi
 
Data Structure and Algorithms Stacks
Data Structure and Algorithms StacksData Structure and Algorithms Stacks
Data Structure and Algorithms Stacks
 
Data Structure and Algorithms Linked List
Data Structure and Algorithms Linked ListData Structure and Algorithms Linked List
Data Structure and Algorithms Linked List
 
Data Structure and Algorithms Sorting
Data Structure and Algorithms SortingData Structure and Algorithms Sorting
Data Structure and Algorithms Sorting
 
Data Structure and Algorithms Arrays
Data Structure and Algorithms ArraysData Structure and Algorithms Arrays
Data Structure and Algorithms Arrays
 
Data Structure and Algorithms
Data Structure and Algorithms Data Structure and Algorithms
Data Structure and Algorithms
 
Data Structure and Algorithms Hashing
Data Structure and Algorithms HashingData Structure and Algorithms Hashing
Data Structure and Algorithms Hashing
 
Data Structure and Algorithms Graph Traversal
Data Structure and Algorithms Graph TraversalData Structure and Algorithms Graph Traversal
Data Structure and Algorithms Graph Traversal
 
Data Structure and Algorithms Huffman Coding Algorithm
Data Structure and Algorithms Huffman Coding AlgorithmData Structure and Algorithms Huffman Coding Algorithm
Data Structure and Algorithms Huffman Coding Algorithm
 
Data Structure and Algorithms Heaps and Trees
Data Structure and Algorithms Heaps and TreesData Structure and Algorithms Heaps and Trees
Data Structure and Algorithms Heaps and Trees
 
Data Structure and Algorithms AVL Trees
Data Structure and Algorithms AVL TreesData Structure and Algorithms AVL Trees
Data Structure and Algorithms AVL Trees
 

Recently uploaded

Salesforce Certified Field Service Consultant
Salesforce Certified Field Service ConsultantSalesforce Certified Field Service Consultant
Salesforce Certified Field Service ConsultantAxelRicardoTrocheRiq
 
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer DataAdobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer DataBradBedford3
 
What is Binary Language? Computer Number Systems
What is Binary Language?  Computer Number SystemsWhat is Binary Language?  Computer Number Systems
What is Binary Language? Computer Number SystemsJheuzeDellosa
 
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptxKnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptxTier1 app
 
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...kellynguyen01
 
chapter--4-software-project-planning.ppt
chapter--4-software-project-planning.pptchapter--4-software-project-planning.ppt
chapter--4-software-project-planning.pptkotipi9215
 
Engage Usergroup 2024 - The Good The Bad_The Ugly
Engage Usergroup 2024 - The Good The Bad_The UglyEngage Usergroup 2024 - The Good The Bad_The Ugly
Engage Usergroup 2024 - The Good The Bad_The UglyFrank van der Linden
 
Call Girls in Naraina Delhi 💯Call Us 🔝8264348440🔝
Call Girls in Naraina Delhi 💯Call Us 🔝8264348440🔝Call Girls in Naraina Delhi 💯Call Us 🔝8264348440🔝
Call Girls in Naraina Delhi 💯Call Us 🔝8264348440🔝soniya singh
 
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfLearn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfkalichargn70th171
 
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...ICS
 
Asset Management Software - Infographic
Asset Management Software - InfographicAsset Management Software - Infographic
Asset Management Software - InfographicHr365.us smith
 
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdf
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdfThe Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdf
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdfkalichargn70th171
 
EY_Graph Database Powered Sustainability
EY_Graph Database Powered SustainabilityEY_Graph Database Powered Sustainability
EY_Graph Database Powered SustainabilityNeo4j
 
why an Opensea Clone Script might be your perfect match.pdf
why an Opensea Clone Script might be your perfect match.pdfwhy an Opensea Clone Script might be your perfect match.pdf
why an Opensea Clone Script might be your perfect match.pdfjoe51371421
 
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASEBATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASEOrtus Solutions, Corp
 
The Evolution of Karaoke From Analog to App.pdf
The Evolution of Karaoke From Analog to App.pdfThe Evolution of Karaoke From Analog to App.pdf
The Evolution of Karaoke From Analog to App.pdfPower Karaoke
 
Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...OnePlan Solutions
 
Unit 1.1 Excite Part 1, class 9, cbse...
Unit 1.1 Excite Part 1, class 9, cbse...Unit 1.1 Excite Part 1, class 9, cbse...
Unit 1.1 Excite Part 1, class 9, cbse...aditisharan08
 
HR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comHR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comFatema Valibhai
 

Recently uploaded (20)

Salesforce Certified Field Service Consultant
Salesforce Certified Field Service ConsultantSalesforce Certified Field Service Consultant
Salesforce Certified Field Service Consultant
 
Call Girls In Mukherjee Nagar 📱 9999965857 🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...
Call Girls In Mukherjee Nagar 📱  9999965857  🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...Call Girls In Mukherjee Nagar 📱  9999965857  🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...
Call Girls In Mukherjee Nagar 📱 9999965857 🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...
 
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer DataAdobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
 
What is Binary Language? Computer Number Systems
What is Binary Language?  Computer Number SystemsWhat is Binary Language?  Computer Number Systems
What is Binary Language? Computer Number Systems
 
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptxKnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
 
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
 
chapter--4-software-project-planning.ppt
chapter--4-software-project-planning.pptchapter--4-software-project-planning.ppt
chapter--4-software-project-planning.ppt
 
Engage Usergroup 2024 - The Good The Bad_The Ugly
Engage Usergroup 2024 - The Good The Bad_The UglyEngage Usergroup 2024 - The Good The Bad_The Ugly
Engage Usergroup 2024 - The Good The Bad_The Ugly
 
Call Girls in Naraina Delhi 💯Call Us 🔝8264348440🔝
Call Girls in Naraina Delhi 💯Call Us 🔝8264348440🔝Call Girls in Naraina Delhi 💯Call Us 🔝8264348440🔝
Call Girls in Naraina Delhi 💯Call Us 🔝8264348440🔝
 
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfLearn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
 
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
 
Asset Management Software - Infographic
Asset Management Software - InfographicAsset Management Software - Infographic
Asset Management Software - Infographic
 
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdf
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdfThe Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdf
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdf
 
EY_Graph Database Powered Sustainability
EY_Graph Database Powered SustainabilityEY_Graph Database Powered Sustainability
EY_Graph Database Powered Sustainability
 
why an Opensea Clone Script might be your perfect match.pdf
why an Opensea Clone Script might be your perfect match.pdfwhy an Opensea Clone Script might be your perfect match.pdf
why an Opensea Clone Script might be your perfect match.pdf
 
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASEBATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
 
The Evolution of Karaoke From Analog to App.pdf
The Evolution of Karaoke From Analog to App.pdfThe Evolution of Karaoke From Analog to App.pdf
The Evolution of Karaoke From Analog to App.pdf
 
Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...
 
Unit 1.1 Excite Part 1, class 9, cbse...
Unit 1.1 Excite Part 1, class 9, cbse...Unit 1.1 Excite Part 1, class 9, cbse...
Unit 1.1 Excite Part 1, class 9, cbse...
 
HR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comHR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.com
 

Data Structure and Algorithms Graphs

  • 1.  Introduction  Warshall's algorithm  Shortest path algorithm Floyd Warshall Algorithm (modified warshall algorithm)
  • 2. What is a Graph? A graph G = (V,E) is composed of: V: set of vertices E: set of edges connecting the vertices in V An edge e = (u,v) is a pair of vertices Example: a b c d e V= {a,b,c,d,e} E= {(a,b),(a,c),(a,d), (b,e),(c,d),(c,e), (d,e)}
  • 3. 0 0 0 1 1 0 1 1 1 0 0 1 0 0 1 0 A1 = 0 0 1 0 1 0 1 2 0 0 1 1 1 0 0 1 1 0 0 1 1 0 2 2 1 0 1 1 0 0 1 1 X W Y Z A2 = A3 = Adjacency Matrix and Path Matrix A4 = 0 0 1 1 2 0 2 3 1 0 1 2 1 0 1 1 B4 = A1 + A2 + A3 + A4 • entry of matrix B4 gives the number of paths of length 4 or less from node vi to vj • entry of matrix Br gives the number of paths of length r or less from node vi to vj Number of Paths between Y to W of length 3 are 2 (Y -> Z -> X -> W AND Y->W->Z->W)
  • 4. Warshall's algorithm 1. Repeat for I, J = 1, 2,…, M: [Initializes P.] If A[I, J] = 0, then: Set P[I, J] := 0; Else Set P[I, J] := 1. [End of loop.] 1. Repeat Steps 3 and 4 for K = 1, 2,…, M: [Updates P.] 2. Repeat Step 4 for I = 1, 2,…, M: 3. Repeat J= 1, 2,…, M: Set P[I, J] := P[I, J] OR (P[I, K] AND P[K, J] ). [End of loop.] [End of Step 3 loop.] [End of step 2 loop.] 5. Exit
  • 6. Floyd Warshall Algorithm 1. Repeat for I, J = 1, 2,…, M: [Initializes P.] If A[I, J] = 0, then: Set P[I, J] := ∞; Else Set P[I, J] := W(I, J). [End of loop.] 1. Repeat Steps 3 and 4 for K = 1, 2,…, M: [Updates P.] 2. Repeat Step 4 for I = 1, 2,…, M: 3. Repeat J= 1, 2,…, M: Set P[I, J] := MIN(P[I, J], (P[I, K]+P[K, J])). [End of loop.] [End of Step 3 loop.] [End of step 2 loop.] 5. Exit