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

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
 
XpertSolvers: Your Partner in Building Innovative Software Solutions
XpertSolvers: Your Partner in Building Innovative Software SolutionsXpertSolvers: Your Partner in Building Innovative Software Solutions
XpertSolvers: Your Partner in Building Innovative Software SolutionsMehedi Hasan Shohan
 
cybersecurity notes for mca students for learning
cybersecurity notes for mca students for learningcybersecurity notes for mca students for learning
cybersecurity notes for mca students for learningVitsRangannavar
 
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
 
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...MyIntelliSource, Inc.
 
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样umasea
 
Cloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStackCloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStackVICTOR MAESTRE RAMIREZ
 
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptxKnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptxTier1 app
 
chapter--4-software-project-planning.ppt
chapter--4-software-project-planning.pptchapter--4-software-project-planning.ppt
chapter--4-software-project-planning.pptkotipi9215
 
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
 
buds n tech IT solutions
buds n  tech IT                solutionsbuds n  tech IT                solutions
buds n tech IT solutionsmonugehlot87
 
Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024Andreas Granig
 
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...soniya singh
 
Implementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with AzureImplementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with AzureDinusha Kumarasiri
 
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed DataAlluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed DataAlluxio, Inc.
 
Building Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop SlideBuilding Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop SlideChristina Lin
 
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
 
Der Spagat zwischen BIAS und FAIRNESS (2024)
Der Spagat zwischen BIAS und FAIRNESS (2024)Der Spagat zwischen BIAS und FAIRNESS (2024)
Der Spagat zwischen BIAS und FAIRNESS (2024)OPEN KNOWLEDGE GmbH
 
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
 

Recently uploaded (20)

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
 
XpertSolvers: Your Partner in Building Innovative Software Solutions
XpertSolvers: Your Partner in Building Innovative Software SolutionsXpertSolvers: Your Partner in Building Innovative Software Solutions
XpertSolvers: Your Partner in Building Innovative Software Solutions
 
cybersecurity notes for mca students for learning
cybersecurity notes for mca students for learningcybersecurity notes for mca students for learning
cybersecurity notes for mca students for learning
 
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
 
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
 
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
 
Cloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStackCloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStack
 
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...
 
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptxKnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
 
chapter--4-software-project-planning.ppt
chapter--4-software-project-planning.pptchapter--4-software-project-planning.ppt
chapter--4-software-project-planning.ppt
 
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
 
buds n tech IT solutions
buds n  tech IT                solutionsbuds n  tech IT                solutions
buds n tech IT solutions
 
Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024
 
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
 
Implementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with AzureImplementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with Azure
 
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed DataAlluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
 
Building Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop SlideBuilding Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
 
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
 
Der Spagat zwischen BIAS und FAIRNESS (2024)
Der Spagat zwischen BIAS und FAIRNESS (2024)Der Spagat zwischen BIAS und FAIRNESS (2024)
Der Spagat zwischen BIAS und FAIRNESS (2024)
 
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...
 

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