Claviro

Shortest Path

Bellman-Ford Algorithm

Algorithm
50%

Understanding Shortest Path Algorithms

Dijkstra vs Bellman-Ford

Dijkstra: Greedy, faster, doesn't handle negative weights.

Bellman-Ford: Slower, handles negative weights, detects negative cycles.

Distance Update Rule

d^{(k)}(s,v) = \min\{d^{(k-1)}(s,v), \min_u\{d^{(k-1)}(s,u) + w(u,v)\}\}

About this concept

What to notice

Bellman-Ford relaxes edges repeatedly, gradually improving distance estimates.

Why it matters

Bellman-Ford handles negative weights and can detect negative cycles, making it more flexible than Dijkstra.

Think about

How would you handle currencies with exchange rates that create profitable cycles?

Formula & Application

Key Formula

d^{(k)}(s,v) = \min\{d^{(k-1)}(s,v), \min_u\{d^{(k-1)}(s,u) + w(u,v)\}\}

Use this formula to calculate the relationship between different variables in this concept.

Example

Detecting arbitrage opportunities in currency exchange rates.