The FloydWarshall Algorithm - PowerPoint PPT Presentation

1 / 12
About This Presentation
Title:

The FloydWarshall Algorithm

Description:

By Dale Earnest. MET CS566. The Floyd-Warshall Algorithm ... Appointed associate Prof at Carnegie Mellon at 27, full professor at Stanford at ... – PowerPoint PPT presentation

Number of Views:538
Avg rating:3.0/5.0
Slides: 13
Provided by: dear4
Category:

less

Transcript and Presenter's Notes

Title: The FloydWarshall Algorithm


1
The Floyd-Warshall Algorithm
  • Or There and Back Again, a Directed, Weighted
    Graphs Tale
  • By Dale Earnest
  • MET CS566

2
The Floyd-Warshall Algorithm
  • Graph analysis algorithm for finding shortest
    paths in a weighted, directed graph
  • Graph can have negative weights, but not negative
    weight cycles
  • Example of dynamic programming, a method of
    solving problems where one needs to find the best
    decision one after another

3
Designers
  • Robert Floyd
  • Eminent computer scientist
  • Appointed associate Prof at Carnegie Mellon at
    27, full professor at Stanford at 33, never
    earned a PhD
  • Worked closely with Knuth and was a major
    reviewer of the Art of Programming
  • Earned Turing award in 1978
  • Stephen Warshall
  • Founder of Applied Data Research, now part of
    Computer Associates

4
Initialization
  • Find all the minimal distances for pairs without
    using intermediate vertices
  • Load a matrix with the values

5
Pseudo code
  • M matrix
  • n number of nodes
  • k n loops
  • i vertical axis (start point)
  • j horizontal axis (end point)

for ( k0 k lt n k ) for ( i0 i lt n
i ) for ( j0 j lt n j )
Mij min( Mij, Mik Mkj)

6
First Loop
  • n 6
  • k 0
  • i 0
  • j 0
  • Mij min( Mij, Mik Mkj)
  • M00 min( M00, M00 M00 )
  • M00 min (0, 0) 0
  • So MAA 0

7
First Loop, cont
  • n 6
  • k 0
  • i 1
  • j 3
  • Mij min( Mij, Mik Mkj)
  • M13 min( M13, M10 M03 )
  • M13 min (999, 5 3) 8
  • So MBD 8

8
First Loop, final
  • n 6
  • k 0
  • i 1
  • j 5
  • Mij min( Mij, Mik Mkj)
  • M15 min( M15, M10 M05 )
  • M15 min (999, 5 2) 7
  • So MBF 7

9
Matrix Final State (all shortest paths)
10
Efficiency
  • Three for-loops
  • The matrix is examined n n n
  • O(n3)

11
Drawbacks
  • Negative cycles

12
Applications
  • Shortest path in directed graphs
  • Transitive closure of directed graphs
  • Regular expressions
  • Matrix inversion
  • Optimal routing
  • Determining if an undirected graph is bipartite
Write a Comment
User Comments (0)
About PowerShow.com