Skip to content

Commit 4cfa461

Browse files
committed
added floyd warshall doc
1 parent d0659c7 commit 4cfa461

File tree

1 file changed

+17
-0
lines changed
  • Competitive Coding/Graphs/Shortest Path/Floyd Warshall

1 file changed

+17
-0
lines changed
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
## Floyd–Warshall algorithm
2+
An algorithm for finding shortest paths in a weighted graph with positive or negative edge weights (but with no negative cycles). A single execution of the algorithm will find the lengths (summed weights) of the shortest paths between all pairs of vertices.
3+
4+
------------------------------
5+
![](https://ds055uzetaobb.cloudfront.net/image_optimizer/bec3c44826d7cab9b828f339e4844b5a09df5fce.png)
6+
7+
### Algorithm
8+
9+
If w(i,j) is the weight of the edge between
10+
vertices i and j, we can define shortestPath (i,j,k) in terms of the following recursive formula: the base case is shortestPath (i,j,0)=w(i,j) and the recursive case is shortestPath (i,j,k) = min( shortestPath (i,j,k-1), shortestPath (i,k,k-1)+ shortestPath (k,j,k-1)).
11+
This formula is the heart of the Floyd–Warshall algorithm. The algorithm works by first computing shortestPath (i,j,k) for all (i,j) pairs for k=1, then k=2, etc. This process continues until k=N, and we have found the shortest path for all (i,j) pairs using any intermediate vertices.
12+
13+
----------------------------
14+
### Performance Analysis
15+
* Worst-case performance O(|V|^3)
16+
* Best-case performance O(|V|^3)
17+
* Average performance O(|V|^3)

0 commit comments

Comments
 (0)