Knowledge

Bellman–Ford algorithm

Source 📝

38: 376: 1749:. This variation can be implemented by keeping a collection of vertices whose outgoing edges need to be relaxed, removing a vertex from this collection when its edges are relaxed, and adding to the collection any vertex whose distance value is changed by a relaxation step. In China, this algorithm was popularized by Fanding Duan, who rediscovered it in 1994, as the "shortest path faster algorithm". 1543: 1139: 315: 399:, in which approximations to the correct distance are replaced by better ones until they eventually reach the solution. In both algorithms, the approximate distance to each vertex is always an overestimate of the true distance, and is replaced by the minimum of its old value and the length of a newly found path. 1520:
When the algorithm is used to find shortest paths, the existence of negative cycles is a problem, preventing the algorithm from finding a correct answer. However, since it terminates upon finding a negative cycle, the Bellman–Ford algorithm can be used for applications in which this is the target to
483:
In each of these repetitions, the number of vertices with correctly calculated distances grows, from which it follows that eventually all vertices will have their correct distances. This method allows the Bellman–Ford algorithm to be applied to a wider class of inputs than Dijkstra's algorithm. The
1659:
The Bellman–Ford algorithm may be improved in practice (although not in the worst case) by the observation that, if an iteration of the main loop of the algorithm terminates without making any changes, the algorithm can be immediately terminated, as subsequent iterations will not make any more
1004:
A common improvement when implementing the algorithm is to return early when an iteration of step 2 fails to relax any edges, which implies all shortest paths have been found, and therefore there are no negative cycles. In that case, the complexity of the algorithm is reduced from
992:
The edge (u, v) that is found in step 3 must be reachable from a negative cycle, but it isn't necessarily part of the cycle itself, which is why it's necessary to follow the path of predecessors backwards until a cycle is detected. The above pseudo-code uses a Boolean array
794:
Simply put, the algorithm initializes the distance to the source to 0 and all other nodes to infinity. Then for all edges, if the distance to the destination can be shortened by taking the edge, the distance is updated to the new lower value.
1479:
If there are no negative-weight cycles, then every shortest path visits each vertex at most once, so at step 3 no further improvements can be made. Conversely, suppose no improvement can be made. Then for any cycle with vertices
1744:
a second time. In this way, as the number of vertices with correct distance values grows, the number whose outgoing edges that need to be relaxed in each iteration shrinks, leading to a constant-factor savings in time for
1755:
described another improvement to the Bellman–Ford algorithm. His improvement first assigns some arbitrary linear order on all vertices and then partitions the set of all edges into two subsets. The first subset,
1646:
if link or node failures render a node unreachable from some set of other nodes, those nodes may spend forever gradually increasing their estimates of the distance to it, and in the meantime there may be routing
254:
for the same problem, but more versatile, as it is capable of handling graphs in which some of the edge weights are negative numbers. The algorithm was first proposed by Alfonso Shimbel (
1886:. Each iteration of the main loop of the algorithm, after the first one, adds at least two edges to the set of edges whose relaxed distances match the correct shortest path distances: one from 410:
select the closest vertex that has not yet been processed, and performs this relaxation process on all of its outgoing edges; by contrast, the Bellman–Ford algorithm simply relaxes
387:
or 4 iterations for the distance estimates to converge. Conversely, if the edges are processed in the best order, from left to right, the algorithm converges in a single iteration.
2493: 1723: 1058: 540: 123: 1103: 223: 173: 838: 2013: 1946: 957: 921: 448: 987: 603: 573: 478: 959:
times to ensure the shortest path has been found for all nodes. A final scan of all the edges is performed and if any distance is updated, then a path of length
1123: 858: 1625:
When a node receives distance tables from its neighbors, it calculates the shortest routes to all other nodes and updates its own table to reflect any changes.
1564: 1160: 336: 2165:. Proceedings of the Symposium on Information Networks. New York, New York: Polytechnic Press of the Polytechnic Institute of Brooklyn. pp. 199–203. 289:
Negative edge weights are found in various applications of graphs. This is why this algorithm is useful. If a graph contains a "negative cycle" (i.e. a
2486: 2594: 2437: 2411: 2391: 2342: 1959:. This change makes the worst case for Yen's improvement (in which the edges of a shortest path strictly alternate between the two subsets 379:
In this example graph, assuming that A is the source and edges are processed in the worst order, from right to left, it requires the full
2479: 48: 2572: 2732: 2451: 1590: 1186: 362: 1643: 1604: 2441: 2659: 1568: 1164: 340: 2229:. Proc. Internat. Sympos. Switching Theory 1957, Part II. Cambridge, Massachusetts: Harvard Univ. Press. pp. 285–292. 1619:
Each node calculates the distances between itself and all other nodes within the AS and stores this information as a table.
2577: 2649: 2737: 1612: 1608: 179: 129: 66: 1732:, reduces the number of relaxation steps that need to be performed within each iteration of the algorithm. If a vertex 1670:
iterations, even though the worst case of the algorithm remains unchanged. The following improvements all maintain the
2379: 396: 2727: 1522: 2682: 1301:
For the inductive case, we first prove the first part. Consider a moment when a vertex's distance is updated by
301:
around the negative cycle. In such a case, the Bellman–Ford algorithm can detect and report the negative cycle.
2697: 1553: 1149: 325: 2742: 2644: 2616: 1572: 1557: 1168: 1153: 392: 344: 329: 251: 37: 2523: 2244:"An algorithm for finding shortest routes from all source nodes to a given destination in general networks" 2052: 2687: 2654: 2535: 1200: 59: 2674: 2631: 243: 1900:. This modification reduces the worst-case number of iterations of the main loop of the algorithm from 2567: 2562: 2540: 2372: 1673: 1008: 490: 290: 76: 1660:
changes. With this early termination condition, the main loop may in some cases use many fewer than
2692: 2528: 1063: 375: 298: 484:
intermediate answers depend on the order of edges relaxed, but the final answer remains the same.
189: 139: 2708: 2589: 2286: 1956: 801: 2664: 2331:
Bang-Jensen, Jørgen; Gutin, Gregory (2000). "Section 2.3.4: The Bellman-Ford-Moore algorithm".
2611: 2552: 2447: 2407: 2403: 2387: 2338: 1611:(RIP). The algorithm is distributed because it involves a number of nodes (routers) within an 989:
edges has been found which can only occur if at least one negative cycle exists in the graph.
1615:, a collection of IP networks typically owned by an ISP. It consists of the following steps: 2368: 2296: 2255: 2186: 2101: 1955:, replaces the arbitrary linear order of the vertices used in Yen's second improvement by a 1637: 407: 247: 182: 17: 2398:
Heineman, George T.; Pollice, Gary; Selkow, Stanley (2008). "Chapter 6: Graph Algorithms".
2269: 2234: 2200: 1980: 1913: 926: 890: 417: 2515: 2502: 2319: 2265: 2230: 2222: 2196: 2170: 998: 275: 259: 132: 69: 962: 798:
The core of the algorithm is a loop that scans across all edges at every loop. For every
677:// The distance from the source to itself is, of course, zero distance := 0 578: 548: 453: 293:
whose edges sum to a negative value) that is reachable from the source, then there is no
2394:. Section 22.1: The Bellman–Ford algorithm, pp. 612–616. Problem 22–1, p. 640. 2506: 2315: 2278: 2208: 1974: 1108: 843: 783:
ncycle := concatenate(, ncycle) v := predecessor
542: 403: 263: 2471: 297:
path: any path that has a point on the negative cycle can be made cheaper by one more
2721: 2606: 2425: 2421: 1629:
The main disadvantages of the Bellman–Ford algorithm in this setting are as follows:
239: 2457: 2285:. Analytic Algorithmics and Combinatorics (ANALCO12), Kyoto, Japan. pp. 41–47. 1526: 2557: 2353: 1746: 1542: 1388:
edges, since if it were not, then there must be some strictly shorter path from
1138: 669:// Initialize the distance to all vertices to infinity distance := 314: 1736:
has a distance value that has not changed since the last time the edges out of
2376: 2300: 2212: 235: 2260: 2243: 2191: 2174: 1973:) very unlikely to happen. With a randomly permuted vertex ordering, the 2332: 1248:
edges, then Distance(u) is at most the length of the shortest path from
711:
distance := distance + w predecessor := u
2135: 2291: 1275:
loop is executed for the first time. Then, for the source vertex,
374: 2621: 2545: 1640:
are not reflected quickly since updates are spread node-by-node.
2475: 1603:
A distributed variant of the Bellman–Ford algorithm is used in
1225:) is not infinity, it is equal to the length of some path from 1740:
were relaxed, then there is no need to relax the edges out of
1536: 1132: 775:ncycle := v := predecessor 308: 673:// And having a null predecessor predecessor := 2601: 2584: 773:// u is a vertex in a negative cycle, find the cycle itself 2354:"On the history of combinatorial optimization (till 1960)" 2217:. Paper P-923. Santa Monica, California: RAND Corporation. 876:
is a lower bound to the length of any path from source to
634:// and fills two arrays (distance and predecessor) holding 631:// lists of vertices (represented as integers ) and edges, 1977:
number of iterations needed in the main loop is at most
1728:
A variation of the Bellman–Ford algorithm described by
1125:
is the maximum length of a shortest path in the graph.
887:
Since the longest possible path without a cycle can be
739:// A negative cycle exists; find a vertex on the cycle 628:// This implementation takes in a graph, represented as 1420:−1 iterations is at most the length of this path from 1290:, which is also correct because there is no path from 868:
yields a path that has a total weight that is at most
282:, and for this reason it is also sometimes called the 2142:, 4th ed., exercises 5 and 12 (retrieved 2013-01-30). 1983: 1916: 1676: 1111: 1066: 1011: 1001:
algorithm can be used to find a vertex on the cycle.
965: 929: 893: 846: 804: 787:"Graph contains a negative-weight cycle", ncycle 581: 551: 493: 456: 420: 192: 142: 79: 2102:"关于最短路径的SPFA快速算法 [About the SPFA algorithm]" 2673: 2630: 2514: 1622:
Each node sends its table to all neighboring nodes.
637:// the shortest path from the source to each vertex 605:are the number of vertices and edges respectively. 178: 128: 65: 55: 44: 2048: 2046: 2007: 1940: 1879:, relaxing each outgoing edge from that vertex in 1841:, relaxing each outgoing edge from that vertex in 1717: 1117: 1097: 1052: 981: 951: 915: 852: 832: 597: 567: 534: 472: 442: 217: 167: 117: 27:Algorithm for finding the shortest paths in graphs 1952: 1199:The correctness of the algorithm can be shown by 2283:Randomized speedup of the Bellman–Ford algorithm 2038: 2440:(2002). "Section 21.7: Negative Edge Weights". 2326:. Princeton University Press. pp. 130–134. 2087: 278:also published a variation of the algorithm in 1368:on this path. Then, the part of the path from 1344:For the second part, consider a shortest path 864:, following the predecessor trail recorded in 2487: 2334:Digraphs: Theory, Algorithms and Applications 2122:Cormen et al., 4th ed., Problem 22-1, p. 640. 1464:, i.e., the length of the shortest path from 8: 30: 1848:. Each vertex is then visited in the order 1571:. Unsourced material may be challenged and 1412:—a contradiction. By inductive assumption, 1404:to this path to obtain a path with at most 1267:. For the base case of induction, consider 1167:. Unsourced material may be challenged and 713:// Step 3: check for negative-weight cycles 343:. Unsourced material may be challenged and 2494: 2480: 2472: 1512:I.e., every cycle has nonnegative weight. 36: 2290: 2259: 2190: 2075: 2064: 1997: 1992: 1984: 1982: 1930: 1925: 1917: 1915: 1707: 1699: 1691: 1683: 1675: 1591:Learn how and when to remove this message 1400:edges, and we could then append the edge 1303:v.distance := u.distance + uv.weight 1187:Learn how and when to remove this message 1110: 1087: 1079: 1065: 1042: 1034: 1026: 1018: 1010: 997:) to find a vertex on the cycle, but any 974: 966: 964: 938: 930: 928: 902: 894: 892: 845: 819: 811: 803: 590: 582: 580: 560: 552: 550: 524: 516: 508: 500: 492: 465: 457: 455: 429: 421: 419: 363:Learn how and when to remove this message 207: 199: 191: 157: 149: 141: 107: 99: 94: 86: 78: 2130: 2128: 2106:Journal of Southwest Jiaotong University 480:is the number of vertices in the graph. 2024: 1492:v.distance <= v.distance + vv.weight 1279:, which is correct. For other vertices 267: 255: 2322:(1962). "A shortest chain algorithm". 2034: 2032: 2030: 2028: 1814:. Each vertex is visited in the order 29: 1729: 402:However, Dijkstra's algorithm uses a 279: 7: 1569:adding citations to reliable sources 1508:0 <= sum from 1 to k of vv.weight 1408:edges that is strictly shorter than 1165:adding citations to reliable sources 341:adding citations to reliable sources 271: 2432:. New York: Pearson Education, Inc. 2386:, Fourth Edition. MIT Press, 2022. 1752: 49:Single-source shortest path problem 1348:(there may be more than one) from 771:u := predecessor 737:predecessor := u 246:to all of the other vertices in a 193: 143: 80: 25: 2361:Handbook of Discrete Optimization 1605:distance-vector routing protocols 923:edges, the edges must be scanned 679:// Step 2: relax edges repeatedly 2248:Quarterly of Applied Mathematics 2227:The shortest path through a maze 2179:Quarterly of Applied Mathematics 1541: 1504:.distance terms cancel, leaving 1309:is the length of some path from 1137: 313: 2709:List of graph search algorithms 2163:Structure in communication nets 1953:Bannister & Eppstein (2012) 1718:{\displaystyle O(|V|\cdot |E|)} 1321:is the length of the path from 1053:{\displaystyle O(|V|\cdot |E|)} 860:-th iteration, from any vertex 535:{\displaystyle O(|V|\cdot |E|)} 118:{\displaystyle \Theta (|V||E|)} 2039:Bang-Jensen & Gutin (2000) 1993: 1985: 1926: 1918: 1712: 1708: 1700: 1692: 1684: 1680: 1496:Summing around the cycle, the 1092: 1088: 1080: 1070: 1047: 1043: 1035: 1027: 1019: 1015: 975: 967: 939: 931: 903: 895: 820: 812: 591: 583: 561: 553: 529: 525: 517: 509: 501: 497: 466: 458: 430: 422: 258:), but is instead named after 212: 208: 200: 196: 162: 158: 150: 146: 112: 108: 100: 95: 87: 83: 51:(for weighted directed graphs) 1: 2352:Schrijver, Alexander (2005). 2088:Kleinberg & Tardos (2006) 1452:is smaller. Therefore, after 1098:{\displaystyle O(l\cdot |E|)} 2384:. MIT Press and McGraw-Hill. 2337:(First ed.). Springer. 1725:worst-case time complexity. 1609:Routing Information Protocol 1448:, and is set equal to it if 1329:that follows the path from 284:Bellman–Ford–Moore algorithm 218:{\displaystyle \Theta (|V|)} 168:{\displaystyle \Theta (|E|)} 18:Bellman–Ford–Moore algorithm 1521:be sought – for example in 1305:. By inductive assumption, 833:{\displaystyle i\leq |V|-1} 733:distance + w < distance 707:distance + w < distance 656:// Step 1: initialize graph 395:, Bellman–Ford proceeds by 2759: 2381:Introduction to Algorithms 1364:be the last vertex before 2706: 2301:10.1137/1.9781611973020.6 1460:is at most the length of 1432:is at most the length of 414:the edges, and does this 35: 2733:Polynomial-time problems 2400:Algorithms in a Nutshell 1951:Another improvement, by 1376:is a shortest path from 1236:if there is a path from 2617:Monte Carlo tree search 1633:It does not scale well. 1533:Applications in routing 1516:Finding negative cycles 2175:"On a routing problem" 2100:Duan, Fanding (1994). 2009: 1942: 1763:, contains all edges ( 1719: 1613:Autonomous system (AS) 1450:uv.weight + u.distance 1446:uv.weight + u.distance 1430:uv.weight + u.distance 1319:u.distance + uv.weight 1271:and the moment before 1119: 1099: 1054: 983: 953: 917: 854: 834: 791:distance, predecessor 599: 569: 536: 474: 444: 388: 266:, who published it in 232:Bellman–Ford algorithm 219: 169: 119: 31:Bellman–Ford algorithm 2675:Minimum spanning tree 2373:Leiserson, Charles E. 2010: 2008:{\displaystyle |V|/3} 1943: 1941:{\displaystyle |V|/2} 1720: 1120: 1100: 1055: 984: 954: 952:{\displaystyle |V|-1} 918: 916:{\displaystyle |V|-1} 855: 835: 600: 570: 537: 487:Bellman–Ford runs in 475: 445: 443:{\displaystyle |V|-1} 378: 242:from a single source 220: 170: 120: 2660:Shortest path faster 2568:Breadth-first search 2563:Bidirectional search 2509:traversal algorithms 2406:. pp. 160–164. 2242:Yen, Jin Y. (1970). 2161:Shimbel, A. (1955). 1981: 1914: 1908:| − 1 1674: 1668:| − 1 1565:improve this section 1161:improve this section 1129:Proof of correctness 1109: 1064: 1009: 963: 927: 891: 844: 840:, at the end of the 802: 647:predecessor := 579: 549: 491: 454: 418: 393:Dijkstra's algorithm 337:improve this section 252:Dijkstra's algorithm 250:. It is slower than 190: 140: 77: 2738:Dynamic programming 2595:Iterative deepening 2214:Network Flow Theory 2211:(August 14, 1956). 2209:Ford, Lester R. Jr. 1444:gets compared with 1277:source.distance = 0 982:{\displaystyle |V|} 880:that uses at most 598:{\displaystyle |E|} 568:{\displaystyle |V|} 473:{\displaystyle |V|} 32: 2590:Depth-first search 2443:Algorithms in Java 2277:Bannister, M. J.; 2261:10.1090/qam/253822 2192:10.1090/qam/102435 2005: 1957:random permutation 1938: 1792:, contains edges ( 1715: 1607:, for example the 1472:that uses at most 1115: 1095: 1050: 979: 949: 913: 850: 830: 595: 565: 532: 470: 440: 389: 215: 165: 115: 2715: 2714: 2612:Jump point search 2553:Best-first search 2438:Sedgewick, Robert 2413:978-0-596-51624-6 2392:978-0-262-04630-5 2377:Rivest, Ronald L. 2369:Cormen, Thomas H. 2363:. Elsevier: 1–68. 2344:978-1-84800-997-4 2324:Flows in Networks 2309:Secondary sources 1644:Count to infinity 1601: 1600: 1593: 1337:and then goes to 1197: 1196: 1189: 1118:{\displaystyle l} 853:{\displaystyle i} 749:initialized with 639:distance := 373: 372: 365: 228: 227: 16:(Redirected from 2750: 2728:Graph algorithms 2496: 2489: 2482: 2473: 2468: 2466: 2465: 2456:. Archived from 2446:(3rd ed.). 2433: 2430:Algorithm Design 2417: 2385: 2364: 2358: 2348: 2327: 2320:Fulkerson, D. R. 2304: 2294: 2273: 2263: 2238: 2223:Moore, Edward F. 2218: 2204: 2194: 2171:Bellman, Richard 2166: 2155:Original sources 2143: 2134:See Sedgewick's 2132: 2123: 2120: 2114: 2113: 2097: 2091: 2085: 2079: 2076:Sedgewick (2002) 2073: 2067: 2065:Schrijver (2005) 2062: 2056: 2050: 2041: 2036: 2014: 2012: 2011: 2006: 2001: 1996: 1988: 1947: 1945: 1944: 1939: 1934: 1929: 1921: 1909: 1907: 1878: 1840: 1724: 1722: 1721: 1716: 1711: 1703: 1695: 1687: 1669: 1667: 1638:network topology 1596: 1589: 1585: 1582: 1576: 1545: 1537: 1523:cycle-cancelling 1509: 1493: 1459: 1451: 1447: 1443: 1431: 1415: 1320: 1308: 1304: 1289: 1278: 1270: 1192: 1185: 1181: 1178: 1172: 1141: 1133: 1124: 1122: 1121: 1116: 1104: 1102: 1101: 1096: 1091: 1083: 1059: 1057: 1056: 1051: 1046: 1038: 1030: 1022: 996: 988: 986: 985: 980: 978: 970: 958: 956: 955: 950: 942: 934: 922: 920: 919: 914: 906: 898: 883: 879: 875: 871: 867: 863: 859: 857: 856: 851: 839: 837: 836: 831: 823: 815: 767:visited := 753:visited := 741:visited := 604: 602: 601: 596: 594: 586: 574: 572: 571: 566: 564: 556: 541: 539: 538: 533: 528: 520: 512: 504: 479: 477: 476: 471: 469: 461: 449: 447: 446: 441: 433: 425: 386: 368: 361: 357: 354: 348: 317: 309: 274:, respectively. 248:weighted digraph 224: 222: 221: 216: 211: 203: 183:space complexity 174: 172: 171: 166: 161: 153: 124: 122: 121: 116: 111: 103: 98: 90: 40: 33: 21: 2758: 2757: 2753: 2752: 2751: 2749: 2748: 2747: 2718: 2717: 2716: 2711: 2702: 2669: 2626: 2510: 2500: 2463: 2461: 2454: 2436: 2420: 2414: 2397: 2367: 2356: 2351: 2345: 2330: 2316:Ford, L. R. Jr. 2314: 2311: 2276: 2241: 2221: 2207: 2169: 2160: 2157: 2152: 2147: 2146: 2133: 2126: 2121: 2117: 2099: 2098: 2094: 2086: 2082: 2074: 2070: 2063: 2059: 2051: 2044: 2037: 2026: 2021: 1979: 1978: 1971: 1964: 1912: 1911: 1903: 1901: 1898: 1891: 1884: 1877: 1870: 1859: 1849: 1846: 1839: 1827: 1820: 1815: 1804: 1797: 1790: 1775: 1768: 1761: 1672: 1671: 1663: 1661: 1657: 1651: 1597: 1586: 1580: 1577: 1562: 1546: 1535: 1518: 1507: 1491: 1457: 1449: 1445: 1441: 1429: 1413: 1318: 1306: 1302: 1284: 1276: 1268: 1213:repetitions of 1193: 1182: 1176: 1173: 1158: 1142: 1131: 1107: 1106: 1062: 1061: 1007: 1006: 994: 961: 960: 925: 924: 889: 888: 881: 877: 873: 872:, and further, 869: 865: 861: 842: 841: 800: 799: 792: 577: 576: 547: 546: 489: 488: 452: 451: 416: 415: 380: 369: 358: 352: 349: 334: 318: 307: 276:Edward F. Moore 264:Lester Ford Jr. 260:Richard Bellman 188: 187: 138: 137: 75: 74: 28: 23: 22: 15: 12: 11: 5: 2756: 2754: 2746: 2745: 2743:Graph distance 2740: 2735: 2730: 2720: 2719: 2713: 2712: 2707: 2704: 2703: 2701: 2700: 2698:Reverse-delete 2695: 2690: 2685: 2679: 2677: 2671: 2670: 2668: 2667: 2662: 2657: 2652: 2650:Floyd–Warshall 2647: 2642: 2636: 2634: 2628: 2627: 2625: 2624: 2619: 2614: 2609: 2604: 2599: 2598: 2597: 2587: 2582: 2581: 2580: 2575: 2565: 2560: 2555: 2550: 2549: 2548: 2543: 2538: 2526: 2520: 2518: 2512: 2511: 2501: 2499: 2498: 2491: 2484: 2476: 2470: 2469: 2452: 2434: 2422:Kleinberg, Jon 2418: 2412: 2404:O'Reilly Media 2395: 2365: 2349: 2343: 2328: 2310: 2307: 2306: 2305: 2274: 2254:(4): 526–530. 2239: 2219: 2205: 2167: 2156: 2153: 2151: 2148: 2145: 2144: 2124: 2115: 2092: 2080: 2068: 2057: 2042: 2023: 2022: 2020: 2017: 2004: 2000: 1995: 1991: 1987: 1969: 1962: 1937: 1933: 1928: 1924: 1920: 1896: 1889: 1882: 1875: 1864: 1853: 1844: 1833: 1825: 1818: 1802: 1795: 1788: 1785:; the second, 1773: 1766: 1759: 1714: 1710: 1706: 1702: 1698: 1694: 1690: 1686: 1682: 1679: 1656: 1653: 1649: 1648: 1641: 1634: 1627: 1626: 1623: 1620: 1599: 1598: 1549: 1547: 1540: 1534: 1531: 1525:techniques in 1517: 1514: 1500:.distance and 1298:with 0 edges. 1262: 1261: 1234: 1195: 1194: 1145: 1143: 1136: 1130: 1127: 1114: 1094: 1090: 1086: 1082: 1078: 1075: 1072: 1069: 1049: 1045: 1041: 1037: 1033: 1029: 1025: 1021: 1017: 1014: 977: 973: 969: 948: 945: 941: 937: 933: 912: 909: 905: 901: 897: 849: 829: 826: 822: 818: 814: 810: 807: 607: 593: 589: 585: 563: 559: 555: 531: 527: 523: 519: 515: 511: 507: 503: 499: 496: 468: 464: 460: 439: 436: 432: 428: 424: 404:priority queue 371: 370: 321: 319: 312: 306: 303: 240:shortest paths 238:that computes 226: 225: 214: 210: 206: 202: 198: 195: 185: 176: 175: 164: 160: 156: 152: 148: 145: 135: 126: 125: 114: 110: 106: 102: 97: 93: 89: 85: 82: 72: 63: 62: 57: 56:Data structure 53: 52: 46: 42: 41: 26: 24: 14: 13: 10: 9: 6: 4: 3: 2: 2755: 2744: 2741: 2739: 2736: 2734: 2731: 2729: 2726: 2725: 2723: 2710: 2705: 2699: 2696: 2694: 2691: 2689: 2686: 2684: 2681: 2680: 2678: 2676: 2672: 2666: 2663: 2661: 2658: 2656: 2653: 2651: 2648: 2646: 2643: 2641: 2638: 2637: 2635: 2633: 2632:Shortest path 2629: 2623: 2620: 2618: 2615: 2613: 2610: 2608: 2607:Fringe search 2605: 2603: 2600: 2596: 2593: 2592: 2591: 2588: 2586: 2583: 2579: 2576: 2574: 2573:Lexicographic 2571: 2570: 2569: 2566: 2564: 2561: 2559: 2556: 2554: 2551: 2547: 2544: 2542: 2539: 2537: 2534: 2533: 2532: 2531: 2527: 2525: 2522: 2521: 2519: 2517: 2513: 2508: 2504: 2497: 2492: 2490: 2485: 2483: 2478: 2477: 2474: 2460:on 2008-05-31 2459: 2455: 2453:0-201-36121-3 2449: 2445: 2444: 2439: 2435: 2431: 2427: 2423: 2419: 2415: 2409: 2405: 2401: 2396: 2393: 2389: 2383: 2382: 2378: 2374: 2370: 2366: 2362: 2355: 2350: 2346: 2340: 2336: 2335: 2329: 2325: 2321: 2317: 2313: 2312: 2308: 2302: 2298: 2293: 2288: 2284: 2280: 2275: 2271: 2267: 2262: 2257: 2253: 2249: 2245: 2240: 2236: 2232: 2228: 2224: 2220: 2216: 2215: 2210: 2206: 2202: 2198: 2193: 2188: 2184: 2180: 2176: 2172: 2168: 2164: 2159: 2158: 2154: 2149: 2141: 2137: 2136:web exercises 2131: 2129: 2125: 2119: 2116: 2112:(2): 207–212. 2111: 2107: 2103: 2096: 2093: 2089: 2084: 2081: 2077: 2072: 2069: 2066: 2061: 2058: 2054: 2049: 2047: 2043: 2040: 2035: 2033: 2031: 2029: 2025: 2018: 2016: 2002: 1998: 1989: 1976: 1972: 1965: 1958: 1954: 1949: 1935: 1931: 1922: 1906: 1899: 1893:and one from 1892: 1885: 1874: 1868: 1863: 1857: 1852: 1847: 1837: 1832: 1828: 1821: 1813: 1809: 1805: 1798: 1791: 1784: 1780: 1776: 1769: 1762: 1754: 1750: 1748: 1743: 1739: 1735: 1731: 1726: 1704: 1696: 1688: 1677: 1666: 1654: 1652: 1645: 1642: 1639: 1635: 1632: 1631: 1630: 1624: 1621: 1618: 1617: 1616: 1614: 1610: 1606: 1595: 1592: 1584: 1574: 1570: 1566: 1560: 1559: 1555: 1550:This section 1548: 1544: 1539: 1538: 1532: 1530: 1528: 1524: 1515: 1513: 1510: 1505: 1503: 1499: 1494: 1489: 1487: 1483: 1477: 1475: 1471: 1467: 1463: 1455: 1439: 1435: 1428:. Therefore, 1427: 1423: 1419: 1411: 1407: 1403: 1399: 1396:with at most 1395: 1391: 1387: 1384:with at most 1383: 1379: 1375: 1371: 1367: 1363: 1359: 1356:with at most 1355: 1351: 1347: 1342: 1340: 1336: 1332: 1328: 1324: 1316: 1312: 1299: 1297: 1293: 1288: 1285:u.distance = 1282: 1274: 1266: 1259: 1256:with at most 1255: 1251: 1247: 1244:with at most 1243: 1239: 1235: 1232: 1228: 1224: 1220: 1219: 1218: 1216: 1212: 1208: 1204: 1202: 1191: 1188: 1180: 1170: 1166: 1162: 1156: 1155: 1151: 1146:This section 1144: 1140: 1135: 1134: 1128: 1126: 1112: 1084: 1076: 1073: 1067: 1039: 1031: 1023: 1012: 1002: 1000: 999:cycle finding 990: 971: 946: 943: 935: 910: 907: 899: 885: 847: 827: 824: 816: 808: 805: 796: 790: 786: 782: 778: 774: 770: 766: 762: 759: 756: 752: 748: 744: 740: 736: 732: 729: 725: 721: 717: 714: 710: 706: 703: 699: 695: 691: 687: 683: 680: 676: 672: 668: 664: 660: 657: 654: 650: 646: 642: 638: 635: 632: 629: 626: 622: 618: 614: 610: 606: 587: 557: 544: 521: 513: 505: 494: 485: 481: 462: 450:times, where 437: 434: 426: 413: 409: 405: 400: 398: 394: 384: 377: 367: 364: 356: 353:December 2021 346: 342: 338: 332: 331: 327: 322:This section 320: 316: 311: 310: 304: 302: 300: 296: 292: 287: 285: 281: 277: 273: 269: 265: 261: 257: 253: 249: 245: 241: 237: 233: 204: 186: 184: 181: 177: 154: 136: 134: 131: 127: 104: 91: 73: 71: 68: 64: 61: 58: 54: 50: 47: 43: 39: 34: 19: 2640:Bellman–Ford 2639: 2529: 2462:. Retrieved 2458:the original 2442: 2429: 2399: 2380: 2360: 2333: 2323: 2282: 2279:Eppstein, D. 2251: 2247: 2226: 2213: 2182: 2178: 2162: 2139: 2118: 2109: 2105: 2095: 2083: 2071: 2060: 2055:stanford.edu 1967: 1960: 1950: 1904: 1894: 1887: 1880: 1872: 1866: 1861: 1855: 1850: 1842: 1835: 1830: 1823: 1816: 1811: 1807: 1806:) such that 1800: 1793: 1786: 1782: 1778: 1777:) such that 1771: 1764: 1757: 1751: 1747:dense graphs 1741: 1737: 1733: 1730:Moore (1959) 1727: 1664: 1658: 1655:Improvements 1650: 1628: 1602: 1587: 1578: 1563:Please help 1551: 1527:network flow 1519: 1511: 1506: 1501: 1497: 1495: 1490: 1485: 1481: 1478: 1473: 1469: 1465: 1461: 1456:iterations, 1453: 1437: 1433: 1425: 1421: 1417: 1409: 1405: 1401: 1397: 1393: 1389: 1385: 1381: 1377: 1373: 1369: 1365: 1361: 1357: 1353: 1349: 1345: 1343: 1338: 1334: 1330: 1326: 1322: 1314: 1310: 1300: 1295: 1291: 1286: 1280: 1272: 1264: 1263: 1257: 1253: 1249: 1245: 1241: 1237: 1230: 1226: 1222: 1221:if Distance( 1214: 1210: 1206: 1205: 1198: 1183: 1174: 1159:Please help 1147: 1003: 991: 886: 797: 793: 788: 784: 780: 779:v != u 776: 772: 768: 764: 760: 757: 754: 750: 746: 742: 738: 734: 730: 727: 723: 719: 718:edge (u, v) 715: 712: 708: 704: 701: 697: 693: 692:edge (u, v) 689: 685: 681: 678: 674: 670: 666: 662: 658: 655: 652: 648: 644: 640: 636: 633: 630: 627: 624: 620: 616: 612: 611:BellmanFord( 608: 486: 482: 411: 401: 390: 382: 359: 350: 335:Please help 323: 294: 288: 283: 231: 229: 2558:Beam search 2524:α–β pruning 2426:Tardos, Éva 1636:Changes in 1440:iteration, 1360:edges. Let 866:predecessor 133:performance 70:performance 2722:Categories 2645:Dijkstra's 2464:2007-05-28 2150:References 2140:Algorithms 2053:Lecture 14 1753:Yen (1970) 1581:April 2024 1529:analysis. 1458:v.distance 1442:v.distance 1414:u.distance 1307:u.distance 1177:March 2019 688:: 615:vertices, 397:relaxation 180:Worst-case 67:Worst-case 2688:Kruskal's 2683:Borůvka's 2655:Johnson's 2292:1111.5414 2185:: 87–90. 1697:⋅ 1552:does not 1436:. In the 1201:induction 1148:does not 1077:⋅ 1032:⋅ 944:− 908:− 825:− 809:≤ 722:weight w 696:weight w 665:vertices 661:vertex v 514:⋅ 435:− 324:does not 305:Algorithm 236:algorithm 194:Θ 144:Θ 130:Best-case 81:Θ 2578:Parallel 2428:(2006). 2281:(2012). 2225:(1959). 2173:(1958). 1975:expected 1287:infinity 1209:. After 874:distance 870:distance 763:visited 745:of size 716:for each 690:for each 659:for each 651:of size 643:of size 623:source) 609:function 545:, where 408:greedily 385:|−1 295:cheapest 2270:0253822 2235:0114710 2201:0102435 1871:, ..., 1829:, ..., 1573:removed 1558:sources 1484:, ..., 1476:edges. 1317:. Then 1169:removed 1154:sources 995:visited 884:edges. 619:edges, 345:removed 330:sources 2693:Prim's 2516:Search 2450:  2410:  2390:  2341:  2268:  2233:  2199:  1902:| 1662:| 1647:loops. 1466:source 1422:source 1416:after 1390:source 1378:source 1370:source 1350:source 1331:source 1323:source 1311:source 1292:source 1260:edges. 1217:loop, 1105:where 789:return 726:edges 700:edges 684:|V|−1 682:repeat 621:vertex 381:| 244:vertex 234:is an 2665:Yen's 2503:Graph 2357:(PDF) 2287:arXiv 2019:Notes 1810:> 1781:< 1265:Proof 1233:; and 1207:Lemma 785:error 777:while 758:while 751:false 686:times 391:Like 291:cycle 60:Graph 45:Class 2622:SSS* 2546:SMA* 2541:LPA* 2536:IDA* 2507:tree 2505:and 2448:ISBN 2408:ISBN 2388:ISBN 2339:ISBN 2138:for 1966:and 1556:any 1554:cite 1152:any 1150:cite 769:true 755:true 743:list 735:then 720:with 709:then 694:with 675:null 649:list 641:list 617:list 613:list 575:and 543:time 328:any 326:cite 299:walk 280:1959 272:1956 270:and 268:1958 262:and 256:1955 230:The 2297:doi 2256:doi 2187:doi 1910:to 1869:|−1 1567:by 1468:to 1424:to 1398:i-1 1392:to 1386:i-1 1380:to 1372:to 1352:to 1333:to 1325:to 1313:to 1294:to 1273:for 1269:i=0 1252:to 1240:to 1229:to 1215:for 1163:by 1060:to 761:not 671:inf 412:all 406:to 339:by 2724:: 2602:D* 2585:B* 2530:A* 2424:; 2402:. 2375:; 2371:; 2359:. 2318:; 2295:. 2266:MR 2264:. 2252:27 2250:. 2246:. 2231:MR 2197:MR 2195:. 2183:16 2181:. 2177:. 2127:^ 2110:29 2108:. 2104:. 2045:^ 2027:^ 2015:. 1948:. 1860:, 1822:, 1799:, 1770:, 1488:, 1402:uv 1341:. 1283:, 1203:: 781:do 765:do 731:if 728:do 724:in 705:if 702:do 698:in 667:do 663:in 625:is 286:. 2495:e 2488:t 2481:v 2467:. 2416:. 2347:. 2303:. 2299:: 2289:: 2272:. 2258:: 2237:. 2203:. 2189:: 2090:. 2078:. 2003:3 1999:/ 1994:| 1990:V 1986:| 1970:b 1968:E 1963:f 1961:E 1936:2 1932:/ 1927:| 1923:V 1919:| 1905:V 1897:b 1895:E 1890:f 1888:E 1883:b 1881:E 1876:1 1873:v 1867:V 1865:| 1862:v 1858:| 1856:V 1854:| 1851:v 1845:f 1843:E 1838:| 1836:V 1834:| 1831:v 1826:2 1824:v 1819:1 1817:v 1812:j 1808:i 1803:j 1801:v 1796:i 1794:v 1789:b 1787:E 1783:j 1779:i 1774:j 1772:v 1767:i 1765:v 1760:f 1758:E 1742:v 1738:v 1734:v 1713:) 1709:| 1705:E 1701:| 1693:| 1689:V 1685:| 1681:( 1678:O 1665:V 1594:) 1588:( 1583:) 1579:( 1575:. 1561:. 1502:v 1498:v 1486:v 1482:v 1474:i 1470:v 1462:P 1454:i 1438:i 1434:P 1426:u 1418:i 1410:P 1406:i 1394:u 1382:u 1374:u 1366:v 1362:u 1358:i 1354:v 1346:P 1339:v 1335:u 1327:v 1315:u 1296:u 1281:u 1258:i 1254:u 1250:s 1246:i 1242:u 1238:s 1231:u 1227:s 1223:u 1211:i 1190:) 1184:( 1179:) 1175:( 1171:. 1157:. 1113:l 1093:) 1089:| 1085:E 1081:| 1074:l 1071:( 1068:O 1048:) 1044:| 1040:E 1036:| 1028:| 1024:V 1020:| 1016:( 1013:O 993:( 976:| 972:V 968:| 947:1 940:| 936:V 932:| 911:1 904:| 900:V 896:| 882:i 878:v 862:v 848:i 828:1 821:| 817:V 813:| 806:i 747:n 653:n 645:n 592:| 588:E 584:| 562:| 558:V 554:| 530:) 526:| 522:E 518:| 510:| 506:V 502:| 498:( 495:O 467:| 463:V 459:| 438:1 431:| 427:V 423:| 383:V 366:) 360:( 355:) 351:( 347:. 333:. 213:) 209:| 205:V 201:| 197:( 163:) 159:| 155:E 151:| 147:( 113:) 109:| 105:E 101:| 96:| 92:V 88:| 84:( 20:)

Index

Bellman–Ford–Moore algorithm

Single-source shortest path problem
Graph
Worst-case
performance
Best-case
performance
Worst-case
space complexity
algorithm
shortest paths
vertex
weighted digraph
Dijkstra's algorithm
1955
Richard Bellman
Lester Ford Jr.
1958
1956
Edward F. Moore
1959
cycle
walk

cite
sources
improve this section
adding citations to reliable sources
removed

Text is available under the Creative Commons Attribution-ShareAlike License. Additional terms may apply.