This article includes a list ofgeneral references, butit lacks sufficient correspondinginline citations. Please help toimprove this article byintroducing more precise citations.(June 2009) (Learn how and when to remove this message) |

Ingraph theory, theshortest path problem is the problem of finding apath between twovertices (or nodes) in agraph such that the sum of theweights of its constituent edges is minimized.[1]
The problem of finding the shortest path between two intersections on a road map may be modeled as a special case of the shortest path problem in graphs, where the vertices correspond to intersections and the edges correspond to road segments, each weighted by the length or distance of each segment.[2]
The shortest path problem can be defined forgraphs whetherundirected,directed, ormixed. The definition for undirected graphs states that every edge can be traversed in either direction. Directed graphs require that consecutive vertices be connected by an appropriate directed edge.[3]
Two vertices are adjacent when they are both incident to a common edge. Apath in an undirected graph is asequence of vertices such that is adjacent to for. Such a path is called a path of length from to. (The are variables; their numbering relates to their position in the sequence and need not relate to a canonical labeling.)
Let where is the edge incident to both and. Given areal-valued weight function, and an undirected (simple) graph, the shortest path from to is the path (where and) that over all possible minimizes the sum When each edge in the graph has unit weight or, this is equivalent to finding the path with fewest edges.
The problem is also sometimes called thesingle-pair shortest path problem, to distinguish it from the following variations:
These generalizations have significantly more efficient algorithms than the simplistic approach of running a single-pair shortest path algorithm on all relevant pairs of vertices.
Several well-known algorithms exist for solving this problem and its variants.
Additional algorithms and associated evaluations may be found inCherkassky, Goldberg & Radzik (1996).
| Weights | Time complexity | Author |
|---|---|---|
| + | O(V2) | Dijkstra 1959 |
| + | O((E + V) log V) | Johnson 1977 (binary heap) |
| + | O(E + V log V) | Fredman & Tarjan 1984 (Fibonacci heap) |
| O(E) | Thorup 1999 (requires constant-time multiplication) | |
| + | Duan et al. 2023 |
| Algorithm | Time complexity | Author |
|---|---|---|
| Breadth-first search | O(E + V) |
An algorithm usingtopological sorting can solve the single-source shortest path problem in timeΘ(E +V) in arbitrarily-weighted directed acyclic graphs.[4]
The following table is taken fromSchrijver (2004), with some corrections and additions.A green background indicates an asymptotically best bound in the table;L is the maximum length (or weight) among all edges, assuming integer edge weights.
| Weights | Algorithm | Time complexity | Author |
|---|---|---|---|
| Ford 1956 | |||
| Bellman–Ford algorithm | Shimbel 1955,Bellman 1958,Moore 1959 | ||
| Dantzig 1960 | |||
| Dijkstra's algorithm with list | Leyzorek et al. 1957,Dijkstra 1959, Minty (seePollack & Wiebenson 1960),Whiting & Hillier 1960 | ||
| Dijkstra's algorithm withbinary heap | Johnson 1977 | ||
| Dijkstra's algorithm withFibonacci heap | Fredman & Tarjan 1984,Fredman & Tarjan 1987 | ||
| QuantumDijkstra algorithm with adjacency list | Dürr et al. 2006[5] | ||
| Dijkstra's-Bellman–Ford hybrid with adivide-and-conquer frontier reduction | Duan et al. 2025[6] | ||
| Dial's algorithm[7] (Dijkstra's algorithm using abucket queue withL buckets) | Dial 1969 | ||
| Johnson 1981,Karlsson & Poblete 1983 | |||
| Gabow's algorithm | Gabow 1983,Gabow 1985 | ||
| Ahuja et al. 1990 | |||
| Thorup | Thorup 2004 |
| Weights | Algorithm | Time complexity | Author |
|---|---|---|---|
| Ford 1956 | |||
| Bellman–Ford algorithm | Shimbel 1955,Bellman 1958,Moore 1959 | ||
| Johnson-Dijkstra withbinary heap | Johnson 1977 | ||
| Johnson-Dijkstra withFibonacci heap | Fredman & Tarjan 1984,Fredman & Tarjan 1987, adapted afterJohnson 1977 | ||
| Johnson's technique applied to Dial's algorithm[7] | Dial 1969, adapted afterJohnson 1977 | ||
| Interior-point method with Laplacian solver | Cohen et al. 2017 | ||
| Interior-point method with flow solver | Axiotis, Mądry & Vladu 2020 | ||
| Robustinterior-point method with sketching | van den Brand et al. 2020 | ||
| interior-point method with dynamic min-ratio cycle data structure | Chen et al. 2022 | ||
| Based on low-diameter decomposition | Bernstein, Nanongkai & Wulff-Nilsen 2022 | ||
| Hop-limited shortest paths | Fineman 2024 |
Finds a negative cycle or calculates distances to all vertices.
| Weights | Algorithm | Time complexity | Author |
|---|---|---|---|
| Andrew V. Goldberg |
| Weights | Algorithm | Time complexity | Author |
|---|---|---|---|
| Henzinger et al. 1997 |
Network flows[8] are a fundamental concept in graph theory and operations research, often used to model problems involving the transportation of goods, liquids, or information through a network. A network flow problem typically involves a directed graph where each edge represents a pipe, wire, or road, and each edge has a capacity, which is the maximum amount that can flow through it. The goal is to find a feasible flow that maximizes the flow from a source node to a sink node.
Shortest Path Problems can be used to solve certain network flow problems, particularly when dealing with single-source, single-sink networks. In these scenarios, we can transform the network flow problem into a series of shortest path problems.
The all-pairs shortest path problem finds the shortest paths between every pair of verticesv,v' in the graph. The all-pairs shortest paths problem for unweighted directed graphs was introduced byShimbel (1953), who observed that it could be solved by a linear number of matrix multiplications that takes a total time ofO(V4).
| Weights | Time complexity | Algorithm |
|---|---|---|
| + | O(V3) | Floyd–Warshall algorithm |
| Seidel's algorithm (expected running time usingfast matrix multiplication algorithms) | ||
| Williams 2014 | ||
| + | O(EV log α(E,V)) | Pettie & Ramachandran 2002 |
| O(EV) | Thorup 1999 applied to every vertex (requires constant-time multiplication). |
| Weights | Time complexity | Algorithm |
|---|---|---|
| (no negative cycles) | Floyd–Warshall algorithm | |
| Williams 2014 | ||
| (no negative cycles) | Quantum search[10][11] | |
| (no negative cycles) | O(EV + V2 log V) | Johnson–Dijkstra |
| (no negative cycles) | O(EV + V2 log log V) | Pettie 2004 |
| O(EV + V2 log log V) | Hagerup 2000 |
Shortest path algorithms are applied to automatically find directions between physical locations, such as driving directions onweb mapping websites likeMapQuest orGoogle Maps. For this application fast specialized algorithms are available.[12]
If one represents a nondeterministicabstract machine as a graph where vertices describe states and edges describe possible transitions, shortest path algorithms can be used to find an optimal sequence of choices to reach a certain goal state, or to establish lower bounds on the time needed to reach a given state. For example, if vertices represent the states of a puzzle like aRubik's Cube and each directed edge corresponds to a single move or turn, shortest path algorithms can be used to find a solution that uses the minimum possible number of moves.
In anetworking ortelecommunications mindset, this shortest path problem is sometimes called the min-delay path problem and usually tied with awidest path problem. For example, the algorithm may seek the shortest (min-delay) widest path, or widest shortest (min-delay) path.[13]
A more lighthearted application is the games of "six degrees of separation" that try to find the shortest path in graphs like movie stars appearing in the same film.
Other applications, often studied inoperations research, include plant and facility layout,robotics,transportation, andVLSI design.[14]
A road network can be considered as a graph with positive weights. The nodes represent road junctions and each edge of the graph is associated with a road segment between two junctions. The weight of an edge may correspond to the length of the associated road segment, the time needed to traverse the segment, or the cost of traversing the segment. Using directed edges it is also possible to model one-way streets. Such graphs are special in the sense that some edges are more important than others for long-distance travel (e.g. highways). This property has been formalized using the notion of highway dimension.[15] There are a great number of algorithms that exploit this property and are therefore able to compute the shortest path a lot quicker than would be possible on general graphs.
All of these algorithms work in two phases. In the first phase, the graph is preprocessed without knowing the source or target node. The second phase is the query phase. In this phase, source and target node are known. The idea is that the road network is static, so the preprocessing phase can be done once and used for a large number of queries on the same road network.
The algorithm with the fastest known query time is called hub labeling and is able to compute shortest path on the road networks of Europe or the US in a fraction of a microsecond.[16] Other techniques that have been used are:
For shortest path problems incomputational geometry, seeEuclidean shortest path.
The shortest multiple disconnected path[17] is a representation of the primitive path network within the framework ofReptation theory. Thewidest path problem seeks a path so that the minimum label of any edge is as large as possible.
Other related problems may be classified into the following categories.
Unlike the shortest path problem, which can be solved in polynomial time in graphs without negative cycles, shortest path problems which include additional constraints on the desired solution path are calledConstrained Shortest Path First, and are harder to solve. One example is the constrained shortest path problem,[18] which attempts to minimize the total cost of the path while at the same time maintaining another metric below a given threshold. This makes the problemNP-complete (such problems are not believed to be efficiently solvable for large sets of data, seeP = NP problem). AnotherNP-complete example requires a specific set of vertices to be included in the path,[19] which makes the problem similar to theTraveling Salesman Problem (TSP). The TSP is the problem of finding the shortest path that goes through every vertex exactly once, and returns to the start. The problem offinding the longest path in a graph is also NP-complete.
TheCanadian traveller problem and the stochastic shortest path problem are generalizations where either the graph is not completely known to the mover, changes over time, or where actions (traversals) are probabilistic.[20][21]
This sectiondoes notcite anysources. Please helpimprove this section byadding citations to reliable sources. Unsourced material may be challenged andremoved.(December 2015) (Learn how and when to remove this message) |
Sometimes, the edges in a graph have personalities: each edge has its own selfish interest. An example is a communication network, in which each edge is a computer that possibly belongs to a different person. Different computers have different transmission speeds, so every edge in the network has a numeric weight equal to the number of milliseconds it takes to transmit a message. Our goal is to send a message between two points in the network in the shortest time possible. If we know the transmission-time of each computer (the weight of each edge), then we can use a standard shortest-paths algorithm. If we do not know the transmission times, then we have to ask each computer to tell us its transmission-time. But, the computers may be selfish: a computer might tell us that its transmission time is very long, so that we will not bother it with our messages. A possible solution to this problem is to usea variant of the VCG mechanism, which gives the computers an incentive to reveal their true weights.
In some cases, the main goal is not to find the shortest path, but only to detect if the graph contains a negative cycle. Some shortest-paths algorithms can be used for this purpose:
This sectionneeds expansion. You can help byadding missing information.(August 2014) |
Many problems can be framed as a form of the shortest path for some suitably substituted notions of addition along a path and taking the minimum. The general approach to these is to consider the two operations to be those of asemiring. Semiring multiplication is done along the path, and the addition is between paths. This general framework is known as thealgebraic path problem.[23][24][25]
Most of the classic shortest-path algorithms (and new ones) can be formulated as solving linear systems over such algebraic structures.[26]
More recently, an even more general framework for solving these (and much less obviously related problems) has been developed under the banner ofvaluation algebras.[27]
In real-life, a transportation network is usually stochastic and time-dependent. The travel duration on a road segment depends on many factors such as the amount of traffic (origin-destination matrix), road work, weather, accidents and vehicle breakdowns. A more realistic model of such a road network is a stochastic time-dependent (STD) network.[28][29]
There is no accepted definition of optimal path under uncertainty (that is, in stochastic road networks). It is a controversial subject, despite considerable progress during the past decade. One common definition is a path with the minimum expected travel time. The main advantage of this approach is that it can make use of efficient shortest path algorithms for deterministic networks. However, the resulting optimal path may not be reliable, because this approach fails to address travel time variability.
To tackle this issue, some researchers use travel duration distribution instead of its expected value. So, they find the probability distribution of total travel duration using different optimization methods such asdynamic programming andDijkstra's algorithm .[30] These methods usestochastic optimization, specifically stochastic dynamic programming to find the shortest path in networks with probabilistic arc length.[31] The termstravel time reliability andtravel time variability are used as opposites in the transportation research literature: the higher the variability, the lower the reliability of predictions.
To account for variability, researchers have suggested two alternative definitions for an optimal path under uncertainty. Themost reliable path is one that maximizes the probability of arriving on time given a travel time budget. Anα-reliable path is one that minimizes the travel time budget required to arrive on time with a given probability.