Foundations
Linear Structures
Hashing
Array and String Patterns
Recursion, Search, and Sorting
Problem Solving Patterns
Algorithm Searching
Sorting Algorithms
Array Algorithms
Grid Algorithms
Linear Structure Algorithms
Hashing Algorithms
Recursion and Backtracking
Greedy Algorithms
Tree and Heap Algorithms
Graph Algorithms
Dynamic Programming Algorithms
String Algorithms
Math Algorithms
Keyboard ready
Space plays. Arrow keys step. R restarts.
LAB Bellman-Ford Lab
Graphs
Problem shape
Advanced
A
B
C
D
E
Core idea
Relax all edges repeatedly to handle negative weights and detect negative cycles.
Step 1 / 5
Problem shape
Graphs Advanced
Bellman-Ford
Welcome to the Bellman-Ford algorithm lab. Relax all edges repeatedly to handle negative weights and detect negative cycles. Use it when: Use when shortest paths may include negative edges. The time complexity is O(VE), and the space complexity is O(V). The pseudocode is: dist[start] = 0 repeat V - 1 times for each edge u -> v relax edge check one more pass for negative cycle As you practice, track the state that changes and the condition that makes the algorithm stop.
Time
O(VE)
Space
O(V)
Pseudocode
dist[start] = 0
repeat V - 1 times
for each edge u -> v
relax edge
check one more pass for negative cycle 1.0x