ℹ️ Skipped - page is already crawled
| Filter | Status | Condition | Details |
|---|---|---|---|
| HTTP status | PASS | download_http_code = 200 | HTTP 200 |
| Age cutoff | PASS | download_stamp > now() - 6 MONTH | 0.6 months ago |
| History drop | PASS | isNull(history_drop_reason) | No drop reason |
| Spam/ban | PASS | fh_dont_index != 1 AND ml_spam_score = 0 | ml_spam_score=0 |
| Canonical | PASS | meta_canonical IS NULL OR = '' OR = src_unparsed | Not set |
| Property | Value |
|---|---|
| URL | https://algorithm-visualizer.org/dynamic-programming/bellman-fords-shortest-path |
| Last Crawled | 2026-03-21 04:06:53 (19 days ago) |
| First Indexed | 2020-05-22 11:51:09 (5 years ago) |
| HTTP Status Code | 200 |
| Meta Title | Dynamic Programming - Bellman-Ford's Shortest Path |
| Meta Description | The Bellman–Ford algorithm is an algorithm that computes shortest paths from a single source vertex to all of the other vertices in a weighted digraph. It is slower than Dijkstra's algorithm for the same problem, but more versatile, as it is capable of handling graphs in which some of the edge weights are negative numbers. |
| Meta Canonical | null |
| Boilerpipe Text | ...
...
function
BELLMAN_FORD
(
src
,
dest
)
{
const
weights
=
new
Array
(
G
.
length
)
;
let
i
;
let
j
;
for
(
i
=
0
;
i
<
G
.
length
;
i
++
)
{
weights
[
i
]
=
MAX_VALUE
;
...
}
weights
[
src
]
=
0
;
...
...
let
k
=
G
.
length
;
while
(
k
--
)
{
...
for
(
i
=
0
;
i
<
G
.
length
;
i
++
)
{
for
(
j
=
0
;
j
<
G
.
length
;
j
++
)
{
if
(
G
[
i
]
[
j
])
{
if
(
weights
[
j
]
>
(
weights
[
i
]
+
G
[
i
]
[
j
]))
{
weights
[
j
]
=
weights
[
i
]
+
G
[
i
]
[
j
]
;
...
}
...
}
}
}
...
}
logger
.
println
(
'checking for cycle'
)
;
for
(
i
=
0
;
i
<
G
.
length
;
i
++
)
{
for
(
j
=
0
;
j
<
G
.
length
;
j
++
)
{
if
(
G
[
i
]
[
j
])
{
if
(
weights
[
j
]
>
(
weights
[
i
]
+
G
[
i
]
[
j
]))
{
...
return
(
MAX_VALUE
)
;
}
}
}
}
...
return
weights
[
dest
]
;
}
const
src
=
Randomize
.
Integer
({
min
:
0
,
max
:
G
.
length
-
1
})
;
let
dest
;
let
MAX_VALUE
=
0x7fffffff
;
let
minWeight
;
do
{
dest
=
Randomize
.
Integer
({
min
:
0
,
max
:
G
.
length
-
1
})
;
}
while
(
src
===
dest
)
;
...
minWeight
=
BELLMAN_FORD
(
src
,
dest
)
;
... |
| Markdown | You need to enable JavaScript to run this app.
Dynamic Programming
Bellman-Ford's Shortest Path
Fork
[Share](https://www.facebook.com/sharer/sharer.php?u=https%3A%2F%2Falgorithm-visualizer.org%2Fdynamic-programming%2Fbellman-fords-shortest-path)
Fullscreen
[Sign In](https://algorithm-visualizer.org/api/auth/request)
JavaScript
C++
Java
Build
Play
1 / 92
Speed
0
2
4
Backtracking
Branch and Bound
Brute Force
Divide and Conquer
Dynamic Programming
[Bellman-Ford's Shortest Path](https://algorithm-visualizer.org/dynamic-programming/bellman-fords-shortest-path)[Catalan Number](https://algorithm-visualizer.org/dynamic-programming/catalan-number)[Fibonacci Sequence](https://algorithm-visualizer.org/dynamic-programming/fibonacci-sequence)[Floyd-Warshall's Shortest Path](https://algorithm-visualizer.org/dynamic-programming/floyd-warshalls-shortest-path)[Integer Partition](https://algorithm-visualizer.org/dynamic-programming/integer-partition)[Knapsack Problem](https://algorithm-visualizer.org/dynamic-programming/knapsack-problem)[Knuth-Morris-Pratt's String Search](https://algorithm-visualizer.org/dynamic-programming/knuth-morris-pratts-string-search)[Levenshtein's Edit Distance](https://algorithm-visualizer.org/dynamic-programming/levenshteins-edit-distance)[Longest Common Subsequence](https://algorithm-visualizer.org/dynamic-programming/longest-common-subsequence)[Longest Increasing Subsequence](https://algorithm-visualizer.org/dynamic-programming/longest-increasing-subsequence)[Longest Palindromic Subsequence](https://algorithm-visualizer.org/dynamic-programming/longest-palindromic-subsequence)[Maximum Subarray](https://algorithm-visualizer.org/dynamic-programming/maximum-subarray)[Maximum Sum Path](https://algorithm-visualizer.org/dynamic-programming/maximum-sum-path)[Nth Factorial](https://algorithm-visualizer.org/dynamic-programming/nth-factorial)[Pascal's Triangle](https://algorithm-visualizer.org/dynamic-programming/pascals-triangle)[Shortest Common Supersequence](https://algorithm-visualizer.org/dynamic-programming/shortest-common-supersequence)[Sieve of Eratosthenes](https://algorithm-visualizer.org/dynamic-programming/sieve-of-eratosthenes)[Sliding Window](https://algorithm-visualizer.org/dynamic-programming/sliding-window)[Ugly Numbers](https://algorithm-visualizer.org/dynamic-programming/ugly-numbers)[Z String Search](https://algorithm-visualizer.org/dynamic-programming/z-string-search)
Greedy
Simple Recursive
Uncategorized
Scratch Paper
[New ...](https://algorithm-visualizer.org/scratch-paper/new)
[API Reference](https://github.com/algorithm-visualizer/algorithm-visualizer/wiki)
[Fork me on GitHub](https://github.com/algorithm-visualizer/algorithm-visualizer)
GraphTracer
2
1
2
3
5
1
3
1
2
0
1
2
3
4
LogTracer
README.md
code.js
1
4
5
14
15
16
17
18
19
20
21
22
25
26
27
30
31
35
36
37
38
39
43
44
45
46
47
48
49
52
53
59
60
61
62
63
67
68
69
70
71
72
73
74
75
78
79
80
81
82
83
84
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
109
110
111
112
119
// import visualization libraries {...}
// define tracer variables {...}
function BELLMAN\_FORD(src, dest) {
const weights \= new Array(G.length);
let i;
let j;
for (i \= 0; i \< G.length; i\++) {
weights\[i\] \= MAX\_VALUE;
// visualize {...}
}
weights\[src\] \= 0;
// visualize {...}
// logger {...}
// begin BF algorithm execution
let k \= G.length;
while (k\--) {
// logger {...}
for (i \= 0; i \< G.length; i\++) {
for (j \= 0; j \< G.length; j\++) {
if (G\[i\]\[j\]) { // proceed to relax Edges only if a particular weight !== 0 (0 represents no edge)
if (weights\[j\] \> (weights\[i\] \+ G\[i\]\[j\])) {
weights\[j\] \= weights\[i\] \+ G\[i\]\[j\];
// logger {...}
}
// visualize {...}
}
}
}
// logger {...}
}
// check for cycle
logger.println('checking for cycle');
for (i \= 0; i \< G.length; i\++) {
for (j \= 0; j \< G.length; j\++) {
if (G\[i\]\[j\]) {
if (weights\[j\] \> (weights\[i\] \+ G\[i\]\[j\])) {
// logger {...}
return (MAX\_VALUE);
}
}
}
}
// logger {...}
return weights\[dest\];
}
const src \= Randomize.Integer({ min: 0, max: G.length \- 1 });
let dest;
let MAX\_VALUE \= 0x7fffffff;
let minWeight;
/\*
src = start node
dest = start node (but will eventually at as the end node)
\*/
do {
dest \= Randomize.Integer({ min: 0, max: G.length \- 1 });
}
while (src \=== dest);
// logger {...}
minWeight \= BELLMAN\_FORD(src, dest);
// logger {...}
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
Contributed by
[64json](https://github.com/64json)
[Yee172](https://github.com/Yee172)
Delete File |
| Readable Markdown | null |
| Shard | 153 (laksa) |
| Root Hash | 11528942713366511553 |
| Unparsed URL | org,algorithm-visualizer!/dynamic-programming/bellman-fords-shortest-path s443 |