Comparison Mode

Side-by-side: use case, requirements, complexity, strengths, weaknesses, example problems, and a clear “choose this when…”.

DijkstraGraph Algos
Bellman-FordGraph Algos
Use caseSingle-source shortest paths with non-negative edge weights.Single-source shortest paths with negative weights, negative-cycle detection, or "at most k edges".
RequirementsA min-heap; all weights >= 0.Only an edge list; no heap.
Time complexityO((V + E) log V) with a binary heap.O(V * E); O(k * E) when limited to k rounds.
Space complexityO(V) distances plus heap entries up to O(E).O(V); O(2V) with the previous-round copy needed for the k-edge variant.
StrengthsFast on sparse graphs; each node is settled once, so it stops early when a target is reached.Handles negative edges; a V-th improving round proves a negative cycle; trivially bounded to k edges.
WeaknessesWrong answers with negative edges; cannot detect negative cycles; cannot bound the number of edges used.Slow on large graphs; every round scans every edge.
Example problemsNetwork delay time, path with minimum effort, cheapest flights (without the stop limit).Cheapest flights within k stops, currency arbitrage detection, negative-cycle checks.
Choose this whenChoose Dijkstra when weights are non-negative and the graph is large; it is the default weighted shortest-path tool.Choose Bellman-Ford when edges can be negative, when you must detect a negative cycle, or when the path may use at most k edges.