LightMySky
En anglais

Shortest Paths with Negative Weights and Between All Pairs

Dijkstra's greedy choice fails once an edge can reduce a cost, so Bellman-Ford relaxes every edge n minus one times instead, and reports a negative cycle if anything still improves. Floyd-Warshall answers every pair at once by asking which intermediate vertices are allowed.

Commence ce sujetPas besoin de compte. La progression est enregistrée dans ce navigateur.

Ce que l'enfant saura faire ensuite

  • Build a graph with a negative edge where Dijkstra returns the wrong distance
  • Run Bellman-Ford and say what an improvement on the last pass proves
  • Explain what the third index in the Floyd-Warshall recurrence stands for

1 · Lis

Dijkstra locks in each vertex greedily and never looks back. A negative edge can later undercut a locked distance. One graph with a single reducing edge is enough to return the wrong answer.

Try it together

Start S links to A at cost 5 and to B at cost 6, and B links to A at minus 4. Dijkstra locks A at 5, but the path through B costs 2. The greedy lock missed the cheaper route.

Bellman-Ford relaxes every edge n minus one times instead of locking anything. If any edge still improves on the last pass, a negative cycle exists.

Good to know

Floyd-Warshall answers every pair at once. Its third index names which intermediate vertices may be used so far. Grow the allowed set step by step and the table converges to all-pairs answers.

Greedy fails on negative edges, full relaxation detects cycles, and allowed vertices build all pairs.

2 · Regarde

En anglais

Sans écran

Imprimer une fiche d'exercicesFormat A4, avec une page de corrigés pour les adultes. Sans écran, sans internet.

Où se situe ce sujet

Puis s'entraîner

8 questions attendent derrière cette leçon, chacune avec sa réponse expliquée. Chaque réponse nourrit le ciel : les étoiles s'allument à mesure qu'elles sont apprises, et pâlissent quand vient le moment de revenir.

Commence ce sujet