Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
Floyd-Warshall Algorithm
Floyd-Warshall algorithm is a dynamic programming algorithm that is used to find
the shortest paths among all pairs of nodes in a graph, it does not support any
negative length cycles. The main benefit of Floyd-Warshall algorithm is its
simplicity. It majorly used to compare multiple available options
Have an example of a graph, where vertices / nodes were numbered from 1 to n.
Notation dijk means the shortest path from i to j that also passes through
vertex/node k.
The Algorithm compares the two conditions:
1. If shortest path from i to j does not pass through the vertex k then value of
dijk will be equal to dijk-1.
2. If shortest path from i to j crosses over through the vertex k. In this case the
value of dijk will be equal to dikk-1 + dkjk-1.
The base case of this formula is the following:
Shortest Path (i, j, 0) = w( i, j) to calculate the the length of edge between vertices i and j
Shortest Path (i, j, k + 1) = min (Shortest Path (i, j, k), Shortest Path (i, k + 1, k) + Shortest
Path (k + 1, j, k))
Bellman-Ford algorithm
Bellman-Ford algorithm is an algorithm designed to search the entire shortest
paths in a graph from one source to all other vertices / nodes. In this algorithm the
graph does not support any cycles of negative length, but if it does, the algorithm
will detect it.
The algorithm works in a way that it generates multiple numbers of solution paths
from source node to destination node, after running every cycle it the array stores
that minimal distance from starting point to other vertices. After every run it
replaces the value stored in array if found less than previous value.