11/**
22 * Bellman–Ford algorithm computes shortest paths from a single source
3- * vertex to all of the other vertices in a weighted digraph (negative weights allowed).<br><br>
4- * Time complexity: O(|V||E|) where V and E are the number of vertices and edges respectively.
3+ * vertex to all of the other vertices in a weighted digraph
4+ * (negative weights allowed).<br><br>
5+ * Time complexity: O(|V||E|) where V and E are the number of
6+ * vertices and edges respectively.
57 *
68 * @example
79 *
8- * var BellmanFord = require('path-to-algorithms/src/graphs/shortest-path/bellman-ford');
10+ * var BellmanFord =
11+ * require('path-to-algorithms/src/graphs/shortest-path/bellman-ford');
912 * var Edge = BellmanFord.Edge;
1013 * var bellmanFord = BellmanFord.bellmanFord;
1114 * var edges = [];
2023 * edges.push(new Edge(1, 4, 2));
2124 * edges.push(new Edge(3, 2, 5));
2225 *
23- * // {
26+ * // {
2427 * // parents: { '0': null, '1': 0, '2': 1, '3': 4, '4': 1 },
2528 * // distances: { '0': 0, '1': -1, '2': 2, '3': -2, '4': 1 }
2629 * // }
4144 * @param {Vertex } v End vertex.
4245 * @param {Number } weight Weight of the edge.
4346 */
44- exports . Edge = function ( u , v , weight ) {
47+ exports . Edge = function ( u , v , weight ) {
4548 this . from = u ;
4649 this . to = v ;
4750 this . weight = weight ;
48- }
51+ } ;
4952
5053 /**
51- * Computes shortest paths from a single source vertex to all of the other vertices.
54+ * Computes shortest paths from a single source
55+ * vertex to all of the other vertices.
5256 *
5357 * @public
5458 * @param {Array } vertexes Vertices of the graph.
5559 * @param {Array } edges Edges of the graph.
5660 * @param {Number } source Start vertex.
57- * @returns {Object } Object with two arrays (parents and distances) with shortest-path information.
58- *
61+ * @returns {Object } Object with two arrays (parents and distances)
62+ * with shortest-path information.
5963 */
60- exports . bellmanFord = function ( vertexes , edges , source ) {
64+ exports . bellmanFord = function ( vertexes , edges , source ) {
6165 var distances = { } , parents = { } , c ;
6266 for ( var i = 0 ; i < vertexes . length ; i += 1 ) {
6367 distances [ vertexes [ i ] ] = Infinity ;
8286 }
8387
8488 return { parents : parents , distances : distances } ;
85- }
89+ } ;
8690
8791} ) ( typeof window === 'undefined' ? module . exports : window ) ;
0 commit comments