Knowledge

Johnson's algorithm

Source đź“ť

401: 504:. In this reweighted graph, all edge weights are non-negative, but the shortest path between any two nodes uses the same sequence of edges as the shortest path between the same two nodes in the original graph. The algorithm concludes by applying Dijkstra's algorithm to each of the four starting nodes in the reweighted graph. 841: 1151:. The non-existence of negative edges ensures the optimality of the paths found by Dijkstra's algorithm. The distances in the original graph may be calculated from the distances calculated by Dijkstra's algorithm in the reweighted graph by reversing the reweighting transformation. 578: 1078: 1259: 145: 1385: 434:
has a length-zero edge to each vertex and the shortest path can be no longer than that edge. On the right is shown the reweighted graph, formed by replacing each edge weight
1119:
path, a path is a shortest path in the original weighting if and only if it is a shortest path after reweighting. The weight of edges that belong to a shortest path from
1469: 932: 1311: 921: 882: 469: 307: 1415: 1115: 569: 1660: 1127:
to every node become zero in the reweighted graph; however, they still remain shortest paths. Therefore, there can be no negative edges: if edge
1547: 836:{\displaystyle \left(w(s,p_{1})+h(s)-h(p_{1})\right)+\left(w(p_{1},p_{2})+h(p_{1})-h(p_{2})\right)+...+\left(w(p_{n},t)+h(p_{n})-h(t)\right).} 1653: 407:
The graph on the left of the illustration has two negative edges, but no negative cycles. The center graph shows the new vertex
204:
for finding two disjoint paths of minimum total length between the same two vertices in a graph with non-negative edge weights.
1761: 1521: 264:
Next the edges of the original graph are reweighted using the values computed by the Bellman–Ford algorithm: an edge from
1646: 1739: 1633: 357:
to every other vertex in the reweighted graph. The distance in the original graph is then computed for each distance
167: 28: 1826: 1170: 56: 1744: 1816: 1422: 46: 1316: 1899: 1806: 1512: 231: 186: 1894: 1875: 1849: 1864: 201: 1904: 1811: 1783: 350: 190: 1428: 1854: 1702: 1690: 1264: 923:
in the previous bracketed expression; therefore, we are left with the following expression for
887: 848: 39: 1841: 1798: 217: 439: 277: 1734: 1729: 1707: 1541: 1499: 189:
to compute a transformation of the input graph that removes all negative weights, allowing
182: 8: 1859: 1695: 1390: 1094: 548: 224: 153: 1831: 1756: 1585: 1566: 1638: 397:
The first three stages of Johnson's algorithm are depicted in the illustration below.
1778: 1719: 1589: 1561: 1517: 194: 1612: 1575: 1495: 1073:{\displaystyle \left(w(s,p_{1})+w(p_{1},p_{2})+\cdots +w(p_{n},t)\right)+h(s)-h(t)} 1682: 1669: 1160: 573:
path. Its weight W in the reweighted graph is given by the following expression:
178: 49: 1673: 1507: 1164: 174: 171: 1888: 1773: 163: 1131:
had a negative weight after the reweighting, then the zero-length path from
1616: 1418: 1580: 1527:. Section 25.3, "Johnson's algorithm for sparse graphs", pp. 636–640. 1123:
to any node is zero, and therefore the lengths of the shortest paths from
1724: 400: 1503: 1564:(1977), "Efficient algorithms for shortest paths in sparse networks", 411:, a shortest path tree as computed by the Bellman–Ford algorithm with 261:. If this step detects a negative cycle, the algorithm is terminated. 539:
added to them. The previous statement can be proven as follows: Let
426:
computed at each other node as the length of the shortest path from
1147:, contradicting the fact that all vertices have zero distance from 430:
to that node. Note that these values are all non-positive, because
1089:
Since the reweighting adds the same amount to the weight of every
1417:
instantiations of Dijkstra's algorithm. Thus, when the graph is
1139:
together with this edge would form a negative-length path from
1788: 1712: 1494: 1603:
Suurballe, J. W. (1974), "Disjoint paths in a network",
1768: 1751: 1668: 193:
to be used on the transformed graph. It is named after
1313:
time for the Bellman–Ford stage of the algorithm, and
1431: 1393: 1319: 1267: 1173: 1097: 935: 890: 851: 581: 551: 442: 280: 212:
Johnson's algorithm consists of the following steps:
59: 152:For the scheduling algorithm of the same name, see 1463: 1409: 1379: 1305: 1253: 1167:in the implementation of Dijkstra's algorithm, is 1109: 1072: 915: 876: 835: 563: 512:In the reweighted graph, all paths between a pair 463: 353:is used to find the shortest paths from each node 301: 139: 388:to the distance returned by Dijkstra's algorithm. 1886: 223:is added to the graph, connected by zero-weight 200:A similar reweighting technique is also used in 1548:National Institute of Standards and Technology 1540:Black, Paul E. (2004), "Johnson's Algorithm", 1654: 197:, who first published the technique in 1977. 1543:Dictionary of Algorithms and Data Structures 177:. It allows some of the edge weights to be 1661: 1647: 1082:The bracketed expression is the weight of 1602: 1579: 1254:{\displaystyle O(|V|^{2}\log |V|+|V||E|)} 140:{\displaystyle O(|V|^{2}\log |V|+|V||E|)} 1425:, which solves the same problem in time 1421:, the total time can be faster than the 207: 1560: 1535: 1533: 1887: 1490: 1488: 1486: 1484: 234:is used, starting from the new vertex 1642: 1539: 1530: 1481: 415:as starting vertex, and the values 13: 1380:{\displaystyle O(|V|\log |V|+|E|)} 399: 16:Computer-based path-finding method 14: 1916: 1627: 185:may exist. It works by using the 520:of nodes have the same quantity 1876:List of graph search algorithms 1634:Boost: All Pairs Shortest Paths 29:All-pairs shortest path problem 1596: 1554: 1458: 1448: 1439: 1435: 1403: 1395: 1374: 1370: 1362: 1354: 1346: 1335: 1327: 1323: 1300: 1296: 1288: 1283: 1275: 1271: 1248: 1244: 1236: 1231: 1223: 1215: 1207: 1190: 1181: 1177: 1067: 1061: 1052: 1046: 1032: 1013: 998: 972: 963: 944: 910: 897: 871: 858: 822: 816: 807: 794: 785: 766: 735: 722: 713: 700: 691: 665: 646: 633: 624: 618: 609: 590: 507: 458: 446: 296: 284: 134: 130: 122: 117: 109: 101: 93: 76: 67: 63: 1: 1516:, MIT Press and McGraw-Hill, 1474: 7: 1154: 1086:in the original weighting. 227:to each of the other nodes. 10: 1921: 1513:Introduction to Algorithms 1464:{\displaystyle O(|V|^{3})} 392: 311:, is given the new length 238:, to find for each vertex 151: 1873: 1840: 1797: 1681: 1306:{\displaystyle O(|V||E|)} 1163:of this algorithm, using 916:{\displaystyle -h(p_{i})} 877:{\displaystyle +h(p_{i})} 181:, but no negative-weight 45: 35: 24: 1423:Floyd–Warshall algorithm 1784:Monte Carlo tree search 20:Johnson's algorithm 1617:10.1002/net.3230040204 1465: 1411: 1381: 1307: 1255: 1111: 1074: 917: 878: 837: 565: 465: 464:{\displaystyle w(u,v)} 404: 303: 302:{\displaystyle w(u,v)} 232:Bellman–Ford algorithm 187:Bellman–Ford algorithm 141: 1842:Minimum spanning tree 1581:10.1145/321992.321993 1500:Leiserson, Charles E. 1466: 1412: 1382: 1308: 1261:: the algorithm uses 1256: 1112: 1075: 918: 879: 838: 566: 466: 403: 304: 208:Algorithm description 202:Suurballe's algorithm 168:all pairs of vertices 162:is a way to find the 142: 31:(for weighted graphs) 1827:Shortest path faster 1735:Breadth-first search 1730:Bidirectional search 1676:traversal algorithms 1429: 1391: 1317: 1265: 1171: 1095: 933: 888: 849: 579: 549: 440: 351:Dijkstra's algorithm 278: 191:Dijkstra's algorithm 57: 1762:Iterative deepening 1410:{\displaystyle |V|} 1110:{\displaystyle s-t} 564:{\displaystyle s-t} 242:the minimum weight 160:Johnson's algorithm 154:Job shop scheduling 21: 1757:Depth-first search 1567:Journal of the ACM 1562:Johnson, Donald B. 1461: 1407: 1377: 1303: 1251: 1107: 1070: 913: 874: 833: 561: 461: 405: 299: 137: 19: 1900:Search algorithms 1882: 1881: 1779:Jump point search 1720:Best-first search 1523:978-0-262-03293-3 1504:Rivest, Ronald L. 1496:Cormen, Thomas H. 195:Donald B. Johnson 150: 149: 1912: 1895:Graph algorithms 1663: 1656: 1649: 1640: 1639: 1621: 1619: 1600: 1594: 1592: 1583: 1558: 1552: 1550: 1537: 1528: 1526: 1492: 1470: 1468: 1467: 1462: 1457: 1456: 1451: 1442: 1416: 1414: 1413: 1408: 1406: 1398: 1387:for each of the 1386: 1384: 1383: 1378: 1373: 1365: 1357: 1349: 1338: 1330: 1312: 1310: 1309: 1304: 1299: 1291: 1286: 1278: 1260: 1258: 1257: 1252: 1247: 1239: 1234: 1226: 1218: 1210: 1199: 1198: 1193: 1184: 1118: 1116: 1114: 1113: 1108: 1079: 1077: 1076: 1071: 1039: 1035: 1025: 1024: 997: 996: 984: 983: 962: 961: 922: 920: 919: 914: 909: 908: 884:is cancelled by 883: 881: 880: 875: 870: 869: 842: 840: 839: 834: 829: 825: 806: 805: 778: 777: 742: 738: 734: 733: 712: 711: 690: 689: 677: 676: 653: 649: 645: 644: 608: 607: 572: 570: 568: 567: 562: 542: 538: 519: 515: 503: 472: 470: 468: 467: 462: 433: 429: 425: 414: 410: 387: 368: 364: 360: 356: 349:is removed, and 348: 341: 310: 308: 306: 305: 300: 272:, having length 271: 267: 260: 256: 252: 241: 237: 222: 179:negative numbers 146: 144: 143: 138: 133: 125: 120: 112: 104: 96: 85: 84: 79: 70: 22: 18: 1920: 1919: 1915: 1914: 1913: 1911: 1910: 1909: 1885: 1884: 1883: 1878: 1869: 1836: 1793: 1677: 1667: 1630: 1625: 1624: 1601: 1597: 1559: 1555: 1538: 1531: 1524: 1508:Stein, Clifford 1493: 1482: 1477: 1452: 1447: 1446: 1438: 1430: 1427: 1426: 1402: 1394: 1392: 1389: 1388: 1369: 1361: 1353: 1345: 1334: 1326: 1318: 1315: 1314: 1295: 1287: 1282: 1274: 1266: 1263: 1262: 1243: 1235: 1230: 1222: 1214: 1206: 1194: 1189: 1188: 1180: 1172: 1169: 1168: 1165:Fibonacci heaps 1161:time complexity 1157: 1096: 1093: 1092: 1090: 1020: 1016: 992: 988: 979: 975: 957: 953: 940: 936: 934: 931: 930: 904: 900: 889: 886: 885: 865: 861: 850: 847: 846: 801: 797: 773: 769: 762: 758: 729: 725: 707: 703: 685: 681: 672: 668: 661: 657: 640: 636: 603: 599: 586: 582: 580: 577: 576: 550: 547: 546: 544: 540: 521: 517: 513: 510: 474: 441: 438: 437: 435: 431: 427: 416: 412: 408: 395: 370: 366: 362: 358: 354: 346: 312: 279: 276: 275: 273: 269: 265: 258: 254: 253:of a path from 243: 239: 235: 220: 210: 157: 129: 121: 116: 108: 100: 92: 80: 75: 74: 66: 58: 55: 54: 17: 12: 11: 5: 1918: 1908: 1907: 1905:Graph distance 1902: 1897: 1880: 1879: 1874: 1871: 1870: 1868: 1867: 1865:Reverse-delete 1862: 1857: 1852: 1846: 1844: 1838: 1837: 1835: 1834: 1829: 1824: 1819: 1817:Floyd–Warshall 1814: 1809: 1803: 1801: 1795: 1794: 1792: 1791: 1786: 1781: 1776: 1771: 1766: 1765: 1764: 1754: 1749: 1748: 1747: 1742: 1732: 1727: 1722: 1717: 1716: 1715: 1710: 1705: 1693: 1687: 1685: 1679: 1678: 1666: 1665: 1658: 1651: 1643: 1637: 1636: 1629: 1628:External links 1626: 1623: 1622: 1611:(2): 125–145, 1595: 1553: 1529: 1522: 1479: 1478: 1476: 1473: 1460: 1455: 1450: 1445: 1441: 1437: 1434: 1405: 1401: 1397: 1376: 1372: 1368: 1364: 1360: 1356: 1352: 1348: 1344: 1341: 1337: 1333: 1329: 1325: 1322: 1302: 1298: 1294: 1290: 1285: 1281: 1277: 1273: 1270: 1250: 1246: 1242: 1238: 1233: 1229: 1225: 1221: 1217: 1213: 1209: 1205: 1202: 1197: 1192: 1187: 1183: 1179: 1176: 1156: 1153: 1106: 1103: 1100: 1069: 1066: 1063: 1060: 1057: 1054: 1051: 1048: 1045: 1042: 1038: 1034: 1031: 1028: 1023: 1019: 1015: 1012: 1009: 1006: 1003: 1000: 995: 991: 987: 982: 978: 974: 971: 968: 965: 960: 956: 952: 949: 946: 943: 939: 912: 907: 903: 899: 896: 893: 873: 868: 864: 860: 857: 854: 832: 828: 824: 821: 818: 815: 812: 809: 804: 800: 796: 793: 790: 787: 784: 781: 776: 772: 768: 765: 761: 757: 754: 751: 748: 745: 741: 737: 732: 728: 724: 721: 718: 715: 710: 706: 702: 699: 696: 693: 688: 684: 680: 675: 671: 667: 664: 660: 656: 652: 648: 643: 639: 635: 632: 629: 626: 623: 620: 617: 614: 611: 606: 602: 598: 595: 592: 589: 585: 560: 557: 554: 509: 506: 460: 457: 454: 451: 448: 445: 394: 391: 390: 389: 343: 298: 295: 292: 289: 286: 283: 262: 228: 209: 206: 175:directed graph 164:shortest paths 148: 147: 136: 132: 128: 124: 119: 115: 111: 107: 103: 99: 95: 91: 88: 83: 78: 73: 69: 65: 62: 52: 43: 42: 37: 36:Data structure 33: 32: 26: 15: 9: 6: 4: 3: 2: 1917: 1906: 1903: 1901: 1898: 1896: 1893: 1892: 1890: 1877: 1872: 1866: 1863: 1861: 1858: 1856: 1853: 1851: 1848: 1847: 1845: 1843: 1839: 1833: 1830: 1828: 1825: 1823: 1820: 1818: 1815: 1813: 1810: 1808: 1805: 1804: 1802: 1800: 1799:Shortest path 1796: 1790: 1787: 1785: 1782: 1780: 1777: 1775: 1774:Fringe search 1772: 1770: 1767: 1763: 1760: 1759: 1758: 1755: 1753: 1750: 1746: 1743: 1741: 1740:Lexicographic 1738: 1737: 1736: 1733: 1731: 1728: 1726: 1723: 1721: 1718: 1714: 1711: 1709: 1706: 1704: 1701: 1700: 1699: 1698: 1694: 1692: 1689: 1688: 1686: 1684: 1680: 1675: 1671: 1664: 1659: 1657: 1652: 1650: 1645: 1644: 1641: 1635: 1632: 1631: 1618: 1614: 1610: 1606: 1599: 1591: 1587: 1582: 1577: 1573: 1569: 1568: 1563: 1557: 1549: 1545: 1544: 1536: 1534: 1525: 1519: 1515: 1514: 1509: 1505: 1501: 1497: 1491: 1489: 1487: 1485: 1480: 1472: 1453: 1443: 1432: 1424: 1420: 1399: 1366: 1358: 1350: 1342: 1339: 1331: 1320: 1292: 1279: 1268: 1240: 1227: 1219: 1211: 1203: 1200: 1195: 1185: 1174: 1166: 1162: 1152: 1150: 1146: 1142: 1138: 1134: 1130: 1126: 1122: 1104: 1101: 1098: 1087: 1085: 1080: 1064: 1058: 1055: 1049: 1043: 1040: 1036: 1029: 1026: 1021: 1017: 1010: 1007: 1004: 1001: 993: 989: 985: 980: 976: 969: 966: 958: 954: 950: 947: 941: 937: 928: 926: 905: 901: 894: 891: 866: 862: 855: 852: 843: 830: 826: 819: 813: 810: 802: 798: 791: 788: 782: 779: 774: 770: 763: 759: 755: 752: 749: 746: 743: 739: 730: 726: 719: 716: 708: 704: 697: 694: 686: 682: 678: 673: 669: 662: 658: 654: 650: 641: 637: 630: 627: 621: 615: 612: 604: 600: 596: 593: 587: 583: 574: 558: 555: 552: 536: 532: 528: 524: 505: 501: 497: 493: 489: 485: 481: 477: 455: 452: 449: 443: 423: 419: 402: 398: 385: 381: 377: 373: 369:), by adding 352: 344: 339: 335: 331: 327: 323: 319: 315: 293: 290: 287: 281: 263: 250: 246: 233: 229: 226: 219: 216:First, a new 215: 214: 213: 205: 203: 198: 196: 192: 188: 184: 180: 176: 173: 172:edge-weighted 169: 165: 161: 155: 126: 113: 105: 97: 89: 86: 81: 71: 60: 53: 51: 48: 44: 41: 38: 34: 30: 27: 23: 1821: 1807:Bellman–Ford 1696: 1608: 1604: 1598: 1571: 1565: 1556: 1542: 1511: 1158: 1148: 1144: 1140: 1136: 1132: 1128: 1124: 1120: 1088: 1083: 1081: 929: 924: 844: 575: 534: 530: 526: 522: 511: 499: 495: 491: 487: 483: 479: 475: 421: 417: 406: 396: 383: 379: 375: 371: 337: 333: 329: 325: 321: 317: 313: 248: 244: 230:Second, the 211: 199: 159: 158: 1725:Beam search 1691:α–β pruning 1574:(1): 1–13, 508:Correctness 50:performance 1889:Categories 1812:Dijkstra's 1475:References 529:) − 494:) − 378:) − 332:) − 47:Worst-case 1855:Kruskal's 1850:BorĹŻvka's 1822:Johnson's 1590:207678246 1343:⁡ 1204:⁡ 1102:− 1056:− 1005:⋯ 892:− 811:− 717:− 628:− 556:− 345:Finally, 90:⁡ 1745:Parallel 1605:Networks 1510:(2001), 1155:Analysis 166:between 1117:⁠ 1091:⁠ 571:⁠ 545:⁠ 471:⁠ 436:⁠ 393:Example 309:⁠ 274:⁠ 1860:Prim's 1683:Search 1588:  1520:  1419:sparse 845:Every 543:be an 183:cycles 170:in an 1832:Yen's 1670:Graph 1586:S2CID 225:edges 40:Graph 25:Class 1789:SSS* 1713:SMA* 1708:LPA* 1703:IDA* 1674:tree 1672:and 1518:ISBN 1159:The 516:and 486:) + 324:) + 218:node 1613:doi 1576:doi 1340:log 1201:log 1143:to 1135:to 473:by 268:to 257:to 87:log 1891:: 1769:D* 1752:B* 1697:A* 1609:14 1607:, 1584:, 1572:24 1570:, 1546:, 1532:^ 1506:; 1502:; 1498:; 1483:^ 1471:. 1129:uv 927:: 365:, 1662:e 1655:t 1648:v 1620:. 1615:: 1593:. 1578:: 1551:. 1459:) 1454:3 1449:| 1444:V 1440:| 1436:( 1433:O 1404:| 1400:V 1396:| 1375:) 1371:| 1367:E 1363:| 1359:+ 1355:| 1351:V 1347:| 1336:| 1332:V 1328:| 1324:( 1321:O 1301:) 1297:| 1293:E 1289:| 1284:| 1280:V 1276:| 1272:( 1269:O 1249:) 1245:| 1241:E 1237:| 1232:| 1228:V 1224:| 1220:+ 1216:| 1212:V 1208:| 1196:2 1191:| 1186:V 1182:| 1178:( 1175:O 1149:q 1145:v 1141:q 1137:u 1133:q 1125:q 1121:q 1105:t 1099:s 1084:p 1068:) 1065:t 1062:( 1059:h 1053:) 1050:s 1047:( 1044:h 1041:+ 1037:) 1033:) 1030:t 1027:, 1022:n 1018:p 1014:( 1011:w 1008:+ 1002:+ 999:) 994:2 990:p 986:, 981:1 977:p 973:( 970:w 967:+ 964:) 959:1 955:p 951:, 948:s 945:( 942:w 938:( 925:W 911:) 906:i 902:p 898:( 895:h 872:) 867:i 863:p 859:( 856:h 853:+ 831:. 827:) 823:) 820:t 817:( 814:h 808:) 803:n 799:p 795:( 792:h 789:+ 786:) 783:t 780:, 775:n 771:p 767:( 764:w 760:( 756:+ 753:. 750:. 747:. 744:+ 740:) 736:) 731:2 727:p 723:( 720:h 714:) 709:1 705:p 701:( 698:h 695:+ 692:) 687:2 683:p 679:, 674:1 670:p 666:( 663:w 659:( 655:+ 651:) 647:) 642:1 638:p 634:( 631:h 625:) 622:s 619:( 616:h 613:+ 610:) 605:1 601:p 597:, 594:s 591:( 588:w 584:( 559:t 553:s 541:p 537:) 535:t 533:( 531:h 527:s 525:( 523:h 518:t 514:s 502:) 500:v 498:( 496:h 492:u 490:( 488:h 484:v 482:, 480:u 478:( 476:w 459:) 456:v 453:, 450:u 447:( 444:w 432:q 428:q 424:) 422:v 420:( 418:h 413:q 409:q 386:) 384:u 382:( 380:h 376:v 374:( 372:h 367:v 363:u 361:( 359:D 355:s 347:q 342:. 340:) 338:v 336:( 334:h 330:u 328:( 326:h 322:v 320:, 318:u 316:( 314:w 297:) 294:v 291:, 288:u 285:( 282:w 270:v 266:u 259:v 255:q 251:) 249:v 247:( 245:h 240:v 236:q 221:q 156:. 135:) 131:| 127:E 123:| 118:| 114:V 110:| 106:+ 102:| 98:V 94:| 82:2 77:| 72:V 68:| 64:( 61:O

Index

All-pairs shortest path problem
Graph
Worst-case
performance
Job shop scheduling
shortest paths
all pairs of vertices
edge-weighted
directed graph
negative numbers
cycles
Bellman–Ford algorithm
Dijkstra's algorithm
Donald B. Johnson
Suurballe's algorithm
node
edges
Bellman–Ford algorithm
Dijkstra's algorithm

time complexity
Fibonacci heaps
sparse
Floyd–Warshall algorithm




Cormen, Thomas H.
Leiserson, Charles E.

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

↑