Menu
Coddy logo textTech

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 icon

Challenge

Medium

Now 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;
}
quiz iconTest yourself

This lesson includes a short quiz. Start the lesson to answer it and track your progress.

All lessons in Bellman-Ford Algorithm - Graph Algorithms