Implementation (Part 2)
Lesson 6 of 9 in Coddy's Bellman-Ford Algorithm - Graph Algorithms course.
Now repeat the pass until the distances are final.
Challenge
MediumNow the full algorithm: repeat the relaxation pass until distances settle.
Write a function named bellmanFord that takes n, the flat edges array (triples, directed, possibly negative), and a source, and returns the shortest distance from source to every vertex. Use -1 for unreachable vertices. Assume there is no negative cycle.
Relax all edges n - 1 times.
Try it yourself
#include <stdlib.h>
int* bellmanFord(int n, int* edges, int edges_size, int source, int* returnSize) {
// Write code here
*returnSize = 0;
return edges;
}
This lesson includes a short quiz. Start the lesson to answer it and track your progress.
All lessons in Bellman-Ford Algorithm - Graph Algorithms
2The Algorithm
How it works?Pseudo CodeImplementation (Part 1)Implementation (Part 2)