Skip to main content
added 86 characters in body
Source Link
Doc Brown
  • 220.7k
  • 35
  • 410
  • 625

Dijkstra's algorithm solves the "Single-Source-Shortest-Path" problem and can fail with negative edge weights.

Floyd-Warshall solves the "All-Pairs-Shortest-Path-Problem" and handles negative edge weights correctly.

And not to forget: Floyd-Warshall is simpler to implement (ok, that may be opinionated).

When your graph has only positve edge weights, and you are only looking for a path from one fixed starting point, Dijkstra's algorithm will be more efficient. When you need all shortest paths between all pairs of vertices, however, Floyd-Warshall might be faster than running Dijkstra's algorithm multiple times (for each starting point once). However, in terms of efficiency, both approaches can be implemented in time complexity O(V³).

When your graph has negative edge weights, Dijkstra is not an option.

You find more information here:

Dijkstra's algorithm solves the "Single-Source-Shortest-Path" problem and can fail with negative edge weights.

Floyd-Warshall solves the "All-Pairs-Shortest-Path-Problem" and handles negative edge weights correctly.

When your graph has only positve edge weights, and you are only looking for a path from one fixed starting point, Dijkstra's algorithm will be more efficient. When you need all shortest paths between all pairs of vertices, however, Floyd-Warshall might be faster than running Dijkstra's algorithm multiple times (for each starting point once). However, in terms of efficiency, both approaches can be implemented in time complexity O(V³).

When your graph has negative edge weights, Dijkstra is not an option.

You find more information here:

Dijkstra's algorithm solves the "Single-Source-Shortest-Path" problem and can fail with negative edge weights.

Floyd-Warshall solves the "All-Pairs-Shortest-Path-Problem" and handles negative edge weights correctly.

And not to forget: Floyd-Warshall is simpler to implement (ok, that may be opinionated).

When your graph has only positve edge weights, and you are only looking for a path from one fixed starting point, Dijkstra's algorithm will be more efficient. When you need all shortest paths between all pairs of vertices, however, Floyd-Warshall might be faster than running Dijkstra's algorithm multiple times (for each starting point once). However, in terms of efficiency, both approaches can be implemented in time complexity O(V³).

When your graph has negative edge weights, Dijkstra is not an option.

You find more information here:

added 86 characters in body
Source Link
Doc Brown
  • 220.7k
  • 35
  • 410
  • 625

Dijkstra's algorithm solves the "Single-Source-Shortest-Path" problem and can fail with negative edge weights.

Floyd-Warshall solves the "All-Pairs-Shortest-Path-Problem" and handles negative edge weights correctly.

When your graph has only positve edge weights, and you are only looking for a path from aone fixed starting point, Dijkstra's algorithm will be more efficient. When you need all shortest paths between all pairs of vertices, however, Floyd-Warshall willmight be more efficientfaster than running Dijkstra's algorithm multiple times (for each starting point once). And whenHowever, in terms of efficiency, both approaches can be implemented in time complexity O(V³).

When your graph has negative edge weights, Dijkstra is not an option.

You find more information here: https://www.baeldung.com/cs/dijkstra-vs-floyd-warshall

Dijkstra's algorithm solves the "Single-Source-Shortest-Path" problem and can fail with negative edge weights.

Floyd-Warshall solves the "All-Pairs-Shortest-Path-Problem" and handles negative edge weights correctly.

When your graph has only positve edge weights, and you are looking for a path from a fixed starting point, Dijkstra's algorithm will be more efficient. When you need all shortest paths between all pairs of vertices, however, Floyd-Warshall will be more efficient than running Dijkstra's algorithm multiple times (for each starting point once). And when your graph has negative edge weights, Dijkstra is not an option.

You find more information here: https://www.baeldung.com/cs/dijkstra-vs-floyd-warshall

Dijkstra's algorithm solves the "Single-Source-Shortest-Path" problem and can fail with negative edge weights.

Floyd-Warshall solves the "All-Pairs-Shortest-Path-Problem" and handles negative edge weights correctly.

When your graph has only positve edge weights, and you are only looking for a path from one fixed starting point, Dijkstra's algorithm will be more efficient. When you need all shortest paths between all pairs of vertices, however, Floyd-Warshall might be faster than running Dijkstra's algorithm multiple times (for each starting point once). However, in terms of efficiency, both approaches can be implemented in time complexity O(V³).

When your graph has negative edge weights, Dijkstra is not an option.

You find more information here:

Source Link
Doc Brown
  • 220.7k
  • 35
  • 410
  • 625

Dijkstra's algorithm solves the "Single-Source-Shortest-Path" problem and can fail with negative edge weights.

Floyd-Warshall solves the "All-Pairs-Shortest-Path-Problem" and handles negative edge weights correctly.

When your graph has only positve edge weights, and you are looking for a path from a fixed starting point, Dijkstra's algorithm will be more efficient. When you need all shortest paths between all pairs of vertices, however, Floyd-Warshall will be more efficient than running Dijkstra's algorithm multiple times (for each starting point once). And when your graph has negative edge weights, Dijkstra is not an option.

You find more information here: https://www.baeldung.com/cs/dijkstra-vs-floyd-warshall